|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "Announcing Rust 1.53.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.53.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.53.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] |
| 20 | +from the appropriate page on our website, and check out the |
| 21 | +[detailed release notes for 1.53.0][notes] on GitHub. |
| 22 | + |
| 23 | +[install]: https://www.rust-lang.org/install.html |
| 24 | +[notes]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1530-2021-06-17 |
| 25 | + |
| 26 | +## What's in 1.53.0 stable |
| 27 | + |
| 28 | +This release contains several new language features and many new library features, |
| 29 | +including the long-awaited `IntoIterator` implementation for arrays. |
| 30 | +See the [detailed release notes](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1530-2021-06-17) |
| 31 | +to learn about other changes not covered by this post. |
| 32 | + |
| 33 | +### IntoIterator for arrays |
| 34 | + |
| 35 | +This is the first Rust release in which arrays implement the `IntoIterator` trait. |
| 36 | +This means you can now iterate over arrays by value: |
| 37 | + |
| 38 | +```rust |
| 39 | +for i in [1, 2, 3] { |
| 40 | + .. |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +Previously, this was only possible by reference, using `&[1, 2, 3]` or `[1, 2, 3].iter()`. |
| 45 | + |
| 46 | +Similarly, you can now pass arrays to methods expecting a `T: IntoIterator`: |
| 47 | + |
| 48 | +```rust |
| 49 | +let set = BTreeSet::from_iter([1, 2, 3]); |
| 50 | +``` |
| 51 | + |
| 52 | +```rust |
| 53 | +for (a, b) in some_iterator.chain([1]).zip([1, 2, 3]) { |
| 54 | + .. |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +This was not implemented before, due to backwards compatibility problems. |
| 59 | +Because `IntoIterator` was already implemented for references to arrays, |
| 60 | +`array.into_iter()` already compiled in earlier versions, |
| 61 | +resolving to `(&array).into_iter()`. |
| 62 | + |
| 63 | +As of this release, arrays implement `IntoIterator` with a small workaround to avoid breaking code. |
| 64 | +The compiler will continue to resolve `array.into_iter()` to `(&array).into_iter()`, |
| 65 | +as if the trait implementation does not exist. |
| 66 | +This only applies to the `.into_iter()` method call syntax, and does not |
| 67 | +affect any other syntax such as `for e in [1, 2, 3]`, `iter.zip([1, 2, 3])` or |
| 68 | +`IntoIterator::into_iter([1, 2, 3])`, which all compile fine. |
| 69 | + |
| 70 | +Since this special case for `.into_iter()` is only required to avoid breaking existing code, |
| 71 | +it is removed in the new edition, Rust 2021, which will be released later this year. |
| 72 | +See [the edition announcement](https://blog.rust-lang.org/2021/05/11/edition-2021.html#intoiterator-for-arrays) |
| 73 | +for more information. |
| 74 | + |
| 75 | +### Or patterns |
| 76 | + |
| 77 | +Pattern syntax has been extended to support `|` nested anywhere in the pattern. |
| 78 | +This enables you to write `Some(1 | 2)` instead of `Some(1) | Some(2)`. |
| 79 | + |
| 80 | +```rust |
| 81 | +match result { |
| 82 | + Ok(Some(1 | 2)) => { .. } |
| 83 | + Err(MyError { kind: FileNotFound | PermissionDenied, .. }) => { .. } |
| 84 | + _ => { .. } |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +### Unicode identifiers |
| 89 | + |
| 90 | +Identifiers can now contain non-ascii characters. |
| 91 | +All valid identifier characters in Unicode as defined in [UAX #31](https://unicode.org/reports/tr31/) can now be used. |
| 92 | +That includes characters from many different scripts and languages, but does not include emoji. |
| 93 | + |
| 94 | +For example: |
| 95 | + |
| 96 | +```rust |
| 97 | +const BLÅHAJ: &str = "🦈"; |
| 98 | + |
| 99 | +struct 人 { |
| 100 | + 名字: String, |
| 101 | +} |
| 102 | + |
| 103 | +let α = 1; |
| 104 | +``` |
| 105 | + |
| 106 | +The compiler will warn about about potentially confusing situations involving different scripts. |
| 107 | +For example, using identifiers that look very similar will result in a warning. |
| 108 | + |
| 109 | +``` |
| 110 | +warning: identifier pair considered confusable between `s` and `s` |
| 111 | +``` |
| 112 | + |
| 113 | +### HEAD branch name support in Cargo |
| 114 | + |
| 115 | +Cargo no longer assumes the default `HEAD` of git repositories is named `master`. |
| 116 | +This means you no longer need to specify `branch = "main"` for git dependencies |
| 117 | +from a repository where the default branch is called `main`. |
| 118 | + |
| 119 | +### Stabilized APIs |
| 120 | + |
| 121 | +The following methods and trait implementations were stabilized. |
| 122 | + |
| 123 | +- [`array::from_ref`](https://doc.rust-lang.org/stable/std/array/fn.from_ref.html) |
| 124 | +- [`array::from_mut`](https://doc.rust-lang.org/stable/std/array/fn.from_mut.html) |
| 125 | +- [`AtomicBool::fetch_update`](https://doc.rust-lang.org/stable/std/sync/atomic/struct.AtomicBool.html#method.fetch_update) |
| 126 | +- [`AtomicPtr::fetch_update`](https://doc.rust-lang.org/stable/std/sync/atomic/struct.AtomicPtr.html#method.fetch_update) |
| 127 | +- [`BTreeSet::retain`](https://doc.rust-lang.org/stable/std/collections/struct.BTreeSet.html#method.retain) |
| 128 | +- [`BTreeMap::retain`](https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html#method.retain) |
| 129 | +- [`BufReader::seek_relative`](https://doc.rust-lang.org/stable/std/io/struct.BufReader.html#method.seek_relative) |
| 130 | +- [`cmp::min_by`](https://doc.rust-lang.org/stable/std/cmp/fn.min_by.html) |
| 131 | +- [`cmp::min_by_key`](https://doc.rust-lang.org/stable/std/cmp/fn.min_by_key.html) |
| 132 | +- [`cmp::max_by`](https://doc.rust-lang.org/stable/std/cmp/fn.max_by.html) |
| 133 | +- [`cmp::max_by_key`](https://doc.rust-lang.org/stable/std/cmp/fn.max_by_key.html) |
| 134 | +- [`DebugStruct::finish_non_exhaustive`](https://doc.rust-lang.org/stable/std/fmt/struct.DebugStruct.html#method.finish_non_exhaustive) |
| 135 | +- [`Duration::ZERO`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#associatedconstant.ZERO) |
| 136 | +- [`Duration::MAX`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#associatedconstant.MAX) |
| 137 | +- [`Duration::is_zero`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.is_zero) |
| 138 | +- [`Duration::saturating_add`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.saturating_add) |
| 139 | +- [`Duration::saturating_sub`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.saturating_sub) |
| 140 | +- [`Duration::saturating_mul`](https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.saturating_mul) |
| 141 | +- [`f32::is_subnormal`](https://doc.rust-lang.org/stable/std/primitive.f32.html#method.is_subnormal) |
| 142 | +- [`f64::is_subnormal`](https://doc.rust-lang.org/stable/std/primitive.f64.html#method.is_subnormal) |
| 143 | +- [`IntoIterator for array`](https://doc.rust-lang.org/stable/std/primitive.array.html#impl-IntoIterator) |
| 144 | +- [`{integer}::BITS`](https://doc.rust-lang.org/stable/std/primitive.usize.html#associatedconstant.BITS) |
| 145 | +- [`io::Error::Unsupported`](https://doc.rust-lang.org/stable/std/io/enum.ErrorKind.html#variant.Unsupported) |
| 146 | +- [`NonZero*::leading_zeros`](https://doc.rust-lang.org/stable/std/num/struct.NonZeroU32.html#method.leading_zeros) |
| 147 | +- [`NonZero*::trailing_zeros`](https://doc.rust-lang.org/stable/std/num/struct.NonZeroU32.html#method.trailing_zeros) |
| 148 | +- [`Option::insert`](https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.insert) |
| 149 | +- [`Ordering::is_eq`](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html#method.is_eq) |
| 150 | +- [`Ordering::is_ne`](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html#method.is_ne) |
| 151 | +- [`Ordering::is_lt`](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html#method.is_lt) |
| 152 | +- [`Ordering::is_gt`](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html#method.is_gt) |
| 153 | +- [`Ordering::is_le`](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html#method.is_le) |
| 154 | +- [`Ordering::is_ge`](https://doc.rust-lang.org/stable/std/cmp/enum.Ordering.html#method.is_ge) |
| 155 | +- [`OsStr::make_ascii_lowercase`](https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.make_ascii_lowercase) |
| 156 | +- [`OsStr::make_ascii_uppercase`](https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.make_ascii_uppercase) |
| 157 | +- [`OsStr::to_ascii_lowercase`](https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.to_ascii_lowercase) |
| 158 | +- [`OsStr::to_ascii_uppercase`](https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.to_ascii_uppercase) |
| 159 | +- [`OsStr::is_ascii`](https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.is_ascii) |
| 160 | +- [`OsStr::eq_ignore_ascii_case`](https://doc.rust-lang.org/stable/std/ffi/struct.OsStr.html#method.eq_ignore_ascii_case) |
| 161 | +- [`Peekable::peek_mut`](https://doc.rust-lang.org/stable/std/iter/struct.Peekable.html#method.peek_mut) |
| 162 | +- [`Rc::increment_strong_count`](https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.increment_strong_count) |
| 163 | +- [`Rc::decrement_strong_count`](https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.decrement_strong_count) |
| 164 | +- [`slice::IterMut::as_slice`](https://doc.rust-lang.org/stable/std/slice/struct.IterMut.html#method.as_slice) |
| 165 | +- [`AsRef<[T]> for slice::IterMut`](https://doc.rust-lang.org/stable/std/slice/struct.IterMut.html#impl-AsRef%3C%5BT%5D%3E) |
| 166 | +- [`impl SliceIndex for (Bound<usize>, Bound<usize>)`](https://doc.rust-lang.org/stable/std/primitive.tuple.html#impl-SliceIndex%3C%5BT%5D%3E) |
| 167 | +- [`Vec::extend_from_within`](https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.extend_from_within) |
| 168 | + |
| 169 | +### Other changes |
| 170 | + |
| 171 | +There are other changes in the Rust 1.53.0 release: |
| 172 | +check out what changed in |
| 173 | +[Rust](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1530-2021-06-17), |
| 174 | +[Cargo](https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-153-2021-06-17), |
| 175 | +and [Clippy](https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-153). |
| 176 | + |
| 177 | +### Contributors to 1.53.0 |
| 178 | + |
| 179 | +Many people came together to create Rust 1.53.0. |
| 180 | +We couldn't have done it without all of you. |
| 181 | +[Thanks!](https://thanks.rust-lang.org/rust/1.53.0/) |
0 commit comments