|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.47.0" |
| 4 | +author: The Rust Release Team |
| 5 | +release: true |
| 6 | +--- |
| 7 | + |
| 8 | +The Rust team is happy to announce a new version of Rust, 1.47.0. Rust is a |
| 9 | +programming language that is empowering everyone to build reliable and |
| 10 | +efficient software. |
| 11 | + |
| 12 | +If you have a previous version of Rust installed via rustup, getting Rust |
| 13 | +1.47.0 is as easy as: |
| 14 | + |
| 15 | +```console |
| 16 | +rustup update stable |
| 17 | +``` |
| 18 | + |
| 19 | +If you don't have it already, you can [get `rustup`][install] from the |
| 20 | +appropriate page on our website, and check out the [detailed release notes for |
| 21 | +1.47.0][notes] on GitHub. |
| 22 | + |
| 23 | +[install]: https://www.rust-lang.org/tools/install |
| 24 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1470-2020-10-08 |
| 25 | + |
| 26 | +## What's in 1.47.0 stable |
| 27 | + |
| 28 | +This release contains no new language features, though it does add one |
| 29 | +long-awaited standard library feature. It is mostly quality of life |
| 30 | +improvements, library stabilizations and const-ifications, and toolchain |
| 31 | +improvements. See the [detailed release notes][notes] to learn about other |
| 32 | +changes not covered by this post. |
| 33 | + |
| 34 | +#### Traits on larger arrays |
| 35 | + |
| 36 | +Rust does not currently have a way to be generic over integer values. This |
| 37 | +has long caused problems with arrays, because arrays have an integer as part |
| 38 | +of their type; `[T; N]` is the type of an array of type `T` of `N` length. |
| 39 | +Because there is no way to be generic over `N`, you have to manually implement |
| 40 | +traits for arrays for every `N` you want to support. For the standard library, |
| 41 | +it was decided to support up to `N` of 32. |
| 42 | + |
| 43 | +We have been working on a feature called "const generics" that would allow |
| 44 | +you to be generic over `N`. Fully explaining this feature is out of the scope |
| 45 | +of this post, because we are not stabilizing const generics just yet. |
| 46 | +However, the core of this feature has been implemented in the compiler, and |
| 47 | +it has been decided that the feature is far enough along that we are okay |
| 48 | +with [the standard library using it to implement traits on arrays of any |
| 49 | +length](https://github.com/rust-lang/rust/pull/74060/). What this means in |
| 50 | +practice is that if you try to do something like this on Rust 1.46: |
| 51 | + |
| 52 | +```rust |
| 53 | +fn main() { |
| 54 | + let xs = [0; 34]; |
| 55 | + |
| 56 | + println!("{:?}", xs); |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +you'd get this error: |
| 61 | + |
| 62 | +```text |
| 63 | +error[E0277]: arrays only have std trait implementations for lengths 0..=32 |
| 64 | + --> src/main.rs:4:22 |
| 65 | + | |
| 66 | +4 | println!("{:?}", xs); |
| 67 | + | ^^ the trait `std::array::LengthAtMost32` is not implemented for `[{integer}; 34]` |
| 68 | + | |
| 69 | + = note: required because of the requirements on the impl of `std::fmt::Debug` for `[{integer}; 34]` |
| 70 | + = note: required by `std::fmt::Debug::fmt` |
| 71 | + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) |
| 72 | +``` |
| 73 | + |
| 74 | +But with Rust 1.47, it will properly print out the array. |
| 75 | + |
| 76 | +This should make arrays significantly more useful to folks, though it will |
| 77 | +take until the const generics feature stabilizes for libraries to be able to do |
| 78 | +this kind of implementation for their own traits. We do not have a current |
| 79 | +estimated date for the stabilization of const generics. |
| 80 | + |
| 81 | +#### Shorter backtraces |
| 82 | + |
| 83 | +Back in Rust 1.18, we [made some changes to the backtraces `rustc` would |
| 84 | +print on panic](https://github.com/rust-lang/rust/pull/38165). There are a |
| 85 | +number of things in a backtrace that aren't useful the majority of the time. |
| 86 | +However, at some point, [these |
| 87 | +regressed](https://github.com/rust-lang/rust/issues/47429). In Rust 1.47.0, |
| 88 | +the culprit was found, and [this has now been |
| 89 | +fixed](https://github.com/rust-lang/rust/pull/75048). Since the regression, |
| 90 | +this program: |
| 91 | + |
| 92 | +```rust |
| 93 | +fn main() { |
| 94 | + panic!(); |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +would give you a backtrace that looks like this: |
| 99 | + |
| 100 | +```text |
| 101 | +thread 'main' panicked at 'explicit panic', src/main.rs:2:5 |
| 102 | +stack backtrace: |
| 103 | + 0: backtrace::backtrace::libunwind::trace |
| 104 | + at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86 |
| 105 | + 1: backtrace::backtrace::trace_unsynchronized |
| 106 | + at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66 |
| 107 | + 2: std::sys_common::backtrace::_print_fmt |
| 108 | + at src/libstd/sys_common/backtrace.rs:78 |
| 109 | + 3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt |
| 110 | + at src/libstd/sys_common/backtrace.rs:59 |
| 111 | + 4: core::fmt::write |
| 112 | + at src/libcore/fmt/mod.rs:1076 |
| 113 | + 5: std::io::Write::write_fmt |
| 114 | + at src/libstd/io/mod.rs:1537 |
| 115 | + 6: std::sys_common::backtrace::_print |
| 116 | + at src/libstd/sys_common/backtrace.rs:62 |
| 117 | + 7: std::sys_common::backtrace::print |
| 118 | + at src/libstd/sys_common/backtrace.rs:49 |
| 119 | + 8: std::panicking::default_hook::{{closure}} |
| 120 | + at src/libstd/panicking.rs:198 |
| 121 | + 9: std::panicking::default_hook |
| 122 | + at src/libstd/panicking.rs:217 |
| 123 | + 10: std::panicking::rust_panic_with_hook |
| 124 | + at src/libstd/panicking.rs:526 |
| 125 | + 11: std::panicking::begin_panic |
| 126 | + at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/panicking.rs:456 |
| 127 | + 12: playground::main |
| 128 | + at src/main.rs:2 |
| 129 | + 13: std::rt::lang_start::{{closure}} |
| 130 | + at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/rt.rs:67 |
| 131 | + 14: std::rt::lang_start_internal::{{closure}} |
| 132 | + at src/libstd/rt.rs:52 |
| 133 | + 15: std::panicking::try::do_call |
| 134 | + at src/libstd/panicking.rs:348 |
| 135 | + 16: std::panicking::try |
| 136 | + at src/libstd/panicking.rs:325 |
| 137 | + 17: std::panic::catch_unwind |
| 138 | + at src/libstd/panic.rs:394 |
| 139 | + 18: std::rt::lang_start_internal |
| 140 | + at src/libstd/rt.rs:51 |
| 141 | + 19: std::rt::lang_start |
| 142 | + at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/rt.rs:67 |
| 143 | + 20: main |
| 144 | + 21: __libc_start_main |
| 145 | + 22: _start |
| 146 | +``` |
| 147 | + |
| 148 | +Now, in Rust 1.47.0, you'll see this instead: |
| 149 | + |
| 150 | +```text |
| 151 | +thread 'main' panicked at 'explicit panic', src/main.rs:2:5 |
| 152 | +stack backtrace: |
| 153 | + 0: std::panicking::begin_panic |
| 154 | + at /rustc/d6646f64790018719caebeafd352a92adfa1d75a/library/std/src/panicking.rs:497 |
| 155 | + 1: playground::main |
| 156 | + at ./src/main.rs:2 |
| 157 | + 2: core::ops::function::FnOnce::call_once |
| 158 | + at /rustc/d6646f64790018719caebeafd352a92adfa1d75a/library/core/src/ops/function.rs:227 |
| 159 | +``` |
| 160 | + |
| 161 | +This makes it much easier to see where the panic actually originated, and |
| 162 | +you can still set `RUST_BACKTRACE=full` if you want to see everything. |
| 163 | + |
| 164 | +#### LLVM 11 |
| 165 | + |
| 166 | +We have [upgraded to LLVM 11](https://github.com/rust-lang/rust/pull/73526/). |
| 167 | +The compiler still supports being compiled with LLVM versions as old as 8, |
| 168 | +but by default, 11 is what you'll be getting. |
| 169 | + |
| 170 | +#### Control Flow Guard on Windows |
| 171 | + |
| 172 | +`rustc` [now supports](https://github.com/rust-lang/rust/pull/73893/) `-C |
| 173 | +control-flow-guard`, an option that will turn on [Control Flow |
| 174 | +Guard](https://docs.microsoft.com/en-us/windows/win32/secbp/control-flow-guard) |
| 175 | +on Windows. Other platforms ignore this flag. |
| 176 | + |
| 177 | +### Library changes |
| 178 | + |
| 179 | +Additionally, nine new APIs were stabilized this release: |
| 180 | + |
| 181 | +- [`Ident::new_raw`] |
| 182 | +- [`Range::is_empty`] |
| 183 | +- [`RangeInclusive::is_empty`] |
| 184 | +- [`Result::as_deref`] |
| 185 | +- [`Result::as_deref_mut`] |
| 186 | +- [`Vec::leak`] |
| 187 | +- [`pointer::offset_from`] |
| 188 | +- [`f32::TAU`] |
| 189 | +- [`f64::TAU`] |
| 190 | + |
| 191 | +The following previously stable APIs have now been made `const`: |
| 192 | + |
| 193 | +- [The `new` method for all `NonZero` integers.][73858] |
| 194 | +- [The `checked_add`,`checked_sub`,`checked_mul`,`checked_neg`, `checked_shl`, |
| 195 | + `checked_shr`, `saturating_add`, `saturating_sub`, and `saturating_mul` |
| 196 | + methods for all integers.][73858] |
| 197 | +- [The `checked_abs`, `saturating_abs`, `saturating_neg`, and `signum` for all |
| 198 | + signed integers.][73858] |
| 199 | +- [The `is_ascii_alphabetic`, `is_ascii_uppercase`, `is_ascii_lowercase`, |
| 200 | + `is_ascii_alphanumeric`, `is_ascii_digit`, `is_ascii_hexdigit`, |
| 201 | + `is_ascii_punctuation`, `is_ascii_graphic`, `is_ascii_whitespace`, and |
| 202 | + `is_ascii_control` methods for `char` and `u8`.][73858] |
| 203 | + |
| 204 | +[`Ident::new_raw`]: https://doc.rust-lang.org/stable/proc_macro/struct.Ident.html#method.new_raw |
| 205 | +[`Range::is_empty`]: https://doc.rust-lang.org/stable/std/ops/struct.Range.html#method.is_empty |
| 206 | +[`RangeInclusive::is_empty`]: https://doc.rust-lang.org/stable/std/ops/struct.RangeInclusive.html#method.is_empty |
| 207 | +[`Result::as_deref_mut`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.as_deref_mut |
| 208 | +[`Result::as_deref`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.as_deref |
| 209 | +[`TypeId::of`]: https://doc.rust-lang.org/stable/std/any/struct.TypeId.html#method.of |
| 210 | +[`Vec::leak`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.leak |
| 211 | +[`f32::TAU`]: https://doc.rust-lang.org/stable/std/f32/consts/constant.TAU.html |
| 212 | +[`f64::TAU`]: https://doc.rust-lang.org/stable/std/f64/consts/constant.TAU.html |
| 213 | +[`pointer::offset_from`]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.offset_from |
| 214 | +[73858]: https://github.com/rust-lang/rust/pull/73858/ |
| 215 | + |
| 216 | +See the [detailed release notes][notes] for more. |
| 217 | + |
| 218 | +### Other changes |
| 219 | + |
| 220 | +[Rustdoc has gained support for the Ayu theme](https://github.com/rust-lang/rust/pull/71237/). |
| 221 | + |
| 222 | +[relnotes-cargo]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-147-2020-10-08 |
| 223 | +[relnotes-clippy]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-147 |
| 224 | + |
| 225 | +There are other changes in the Rust 1.47.0 release: check out what changed in |
| 226 | +[Rust][notes], [Cargo][relnotes-cargo], and [Clippy][relnotes-clippy]. |
| 227 | + |
| 228 | +## Contributors to 1.47.0 |
| 229 | + |
| 230 | +Many people came together to create Rust 1.47.0. We couldn't have done it |
| 231 | +without all of you. [Thanks!](https://thanks.rust-lang.org/rust/1.47.0/) |
0 commit comments