## Rust 2021 Edition
nikomatsakis, m-ou-se
---
### [Rust 2021 is coming!](https://blog.rust-lang.org/2021/05/11/edition-2021.html)

---
### Rust 2021 is different
* Focused on a few discrete changes
* Not meant as an overview of the last 3 years
---
### Prelude additions
```rust
let rust = Vec::from_iter(...);
let is = really.try_from();
let great = huzzah.try_into();
```
---
### Cargo resolver
The new feature resolver no longer merges all requested features for crates that are depended on in multiple ways.
---
### IntoIterator for arrays
```rust
// *All* editions (Rust 1.53):
for x in [1, 2, 3] {
..
}
// Only in Rust 2021:
let mut it = [1, 2, 3].into_iter();
it.next().unwrap() // this is an i32, not &i32!
```
---
### Disjoint capture
This compiles:
```rust
self.vector.retain(|elem| value > self.threshold)
// --------------
//
// Closure captures `self.threshold`, not `self`.
```
---
### Panic macro consistency
Panic is the same on std/core, and formatting works.
```rust
panic!("{}", foo); // works
panic!("{}"); // error
panic!("")
panic_any!("{}"); // panics w/ the string `{}`
```
Enables upcoming `{foo}` notation:
```rust
println!("{foo}"); // Any edition
panic!("{foo}"); // Only Rust 2021
```
---
### Reserved syntax
Unknown prefixes now error in the lexer:
* on identifiers, e.g. `foo#bar`
* on strings, e.g. `f#"..."`
* on numbers, e.g. `k33`
---
### How can I help?
Our [project board](https://github.com/orgs/rust-lang/projects/7) contains remaining blockers
---
### Thanks!
Too many people to thank! Some major contributors:
* rylev
* ehuss
* cuviper
* arora-aman and RFC 2229 project group
* simulacrum
* bstrie
* mark-i-m
* hi-rustin
* djc
{"metaMigratedAt":"2023-06-16T00:23:05.000Z","metaMigratedFrom":"YAML","title":"1: Rust 2021 Update","breaks":true,"contributors":"[{\"id\":\"27d8f2ac-a5dc-4ebe-8c31-cc45bcd8447e\",\"add\":2394,\"del\":664},{\"id\":\"9109409b-0740-4b0a-845c-1f09b0892fcb\",\"add\":197,\"del\":49}]"}