@@ -25,23 +25,54 @@ appropriate page on our website, and check out the [detailed release notes for
2525
2626## What's in 1.46.0 stable
2727
28- This release is on the smaller side, with a number of improvements to `const
29- fn`, two new standard library APIs, and one feature useful for library
30- authors. See the [ detailed release notes] [ notes ] to learn about other changes
31- not covered by this post.
28+ This release enables quite a lot of new things to appear in ` const fn ` , two
29+ new standard library APIs, and one feature useful for library authors. See
30+ the [ detailed release notes] [ notes ] to learn about other changes not covered
31+ by this post.
32+
33+ ### ` const fn ` improvements
34+
35+ There are [ several core language features] you can now use in a ` const fn ` :
36+
37+ * ` if ` , ` if let ` , and ` match `
38+ * ` while ` , ` while let ` , and ` loop `
39+ * the ` && ` and ` || ` operators
40+
41+ You can also [ cast to a slice] [ cast-to-slice ] :
42+
43+ ``` rust
44+ const fn foo () {
45+ let x = [1 , 2 , 3 , 4 , 5 ];
46+
47+ // cast the array to a slice
48+ let y : & [_ ] = & x ;
49+ }
50+ ```
51+
52+ While these features may not feel * new* , given that you could use them all
53+ outside of ` const fn ` , they add a lot of compile-time computation power! As
54+ an example, the [ ` const-sha1 ` crate] [ sha1 ] can let you compute SHA-1 hashes
55+ at compile time. This led to a [ 40x performance improvement] [ const-perf ] in
56+ Microsoft's WinRT bindings for Rust.
57+
58+ [ several core language features ] : https://github.com/rust-lang/rust/pull/72437/
59+ [ cast-to-slice ] : https://github.com/rust-lang/rust/pull/73862/
60+ [ sha1 ] : https://github.com/rylev/const-sha1
61+ [ const-perf ] : https://github.com/microsoft/winrt-rs/pull/279#issuecomment-668436700
62+
3263
3364### ` #[track_caller] `
3465
35- Back in March, the release of Rust 1.42 introduced [ better error messages when ` unwrap() ` and related functions would panic] [ better-errors ] . At the time, we mentioned that the way
66+ Back in March, the release of Rust 1.42 introduced [ better error messages when ` unwrap ` and related functions would panic] [ better-errors ] . At the time, we mentioned that the way
3667this was implemented was not yet stable. Rust 1.46 stabilizes this feature.
3768
3869[ better-errors ] : https://blog.rust-lang.org/2020/03/12/Rust-1.42.html#useful-line-numbers-in-option-and-result-panic-messages
3970
40- This attribute is called ` #[track_caller] ` , which was originally proposed
41- in [ RFC 2091] [ rfc-2091 ] way back in July of 2017! If you're writing a function
42- like ` unwrap() ` that may panic but should not itself appear in the panic stacktrace , you can put this
43- annotation on your functions, and the default panic formatter will use it to
44- print its error message. For example, here is ` unwrap ` previously:
71+ This attribute is called ` #[track_caller] ` , which was originally proposed in
72+ [ RFC 2091] [ rfc-2091 ] way back in July of 2017! If you're writing a function
73+ like ` unwrap ` that may panic, you can put this annotation on your functions,
74+ and the default panic formatter will use its caller as the location in its
75+ error message. For example, here is ` unwrap ` previously:
4576
4677``` rust
4778pub fn unwrap (self ) -> T {
@@ -72,28 +103,6 @@ on `std::panic::Location` to get access to this information.
72103[ rfc-2091 ] : https://github.com/rust-lang/rfcs/pull/2091
73104[ caller ] : https://doc.rust-lang.org/stable/std/panic/struct.Location.html#method.caller
74105
75- ### ` const fn ` improvements
76-
77- There are [ several core language features] you can now use in a ` const fn ` :
78-
79- * ` if ` , ` if let ` , and ` match `
80- * ` while ` , ` while let ` , and ` loop `
81- * the ` && ` and ` || ` operators
82-
83- You can also [ cast to a slice] [ cast-to-slice ] :
84-
85- ``` rust
86- const fn foo () {
87- let x = [1 , 2 , 3 , 4 , 5 ];
88-
89- // cast the array to a slice
90- let y : & [_ ] = & x ;
91- }
92- ```
93-
94- [ several core language features ] : https://github.com/rust-lang/rust/pull/72437/
95- [ cast-to-slice ] : https://github.com/rust-lang/rust/pull/73862/
96-
97106### Library changes
98107
99108Keeping with the theme of ` const fn ` improvements, [ ` std::mem::forget ` is now
0 commit comments