Rust 1.46.0: track_caller and const fn improvements

The Rust team is pleased to announce the new version of Rust 1.46.0. Rust is a programming language that allows anyone to create reliable and efficient software.



If you have a previous version of Rust installed via rustup, getting Rust 1.46.0 is as easy as:



rustup update stable


If you don't already have it rustup, you can install it from the appropriate page on our website and check out the detailed 1.46.0 release notes on GitHub.



What's included in stable version 1.46.0



This release is fairly small, with improvements const fn, stabilization of two new APIs in the standard library and one option for library authors. See the detailed release notes for other changes not covered in this announcement.



#[track_caller]



Back in March, when Rust 1.42 was released, , unwrapfeatures like this were causing panic . We mentioned then that the implementation is not stable yet. In Rust 1.46, we stabilized it.



#[track_caller] RFC 2091 2017! , unwrap, , , . , unwrap:



pub fn unwrap(self) -> T {
    match self {
        Some(val) => val,
        None => panic!(" `Option::unwrap()`   `None`"),
    }
}


:



#[track_caller]
pub fn unwrap(self) -> T {
    match self {
        Some(val) => val,
        None => panic!(" `Option::unwrap()`   `None`"),
    }
}


!



, std::panic::Location, .



const fn



const fn , :



  • if, if let match
  • while, while let loop
  • && ||


:



const fn foo() {
  let x = [1, 2, 3, 4, 5];

  //    
  let y: &[_] = &x;
}


, , const fn, ! , , const-sha1 SHA1 . 40- Microsoft WinRT Rust.





const fn, std::mem::forget const fn. API:





, .





, Cargo Clippy .



1.46.0



, Rust 1.46.0. . !





Rust - . , .

opencollective: https://opencollective.com/rust-lang-ru.



funkill, Hirrolot andreevlex.




All Articles