Skip to content

Commit 6a294d3

Browse files
authored
Merge pull request #243 from m-ou-se/2021-summaries
Add short summaries to all 2021 edition changes.
2 parents 302a115 + 3b039f8 commit 6a294d3

8 files changed

+33
-6
lines changed

src/rust-2021/IntoIterator-for-arrays.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Summary
44

5+
- Arrays implement `IntoIterator` in *all* editions.
6+
- The new `.into_iter()` is *hidden* in Rust 2015 and Rust 2018 in method call syntax.
7+
So, `array.into_iter()` still resolves to `(&array).into_iter()` as before.
8+
- `array.into_iter()` changes meaning when switching to Rust 2021.
9+
510
## Details
611

712
Until Rust 1.53, only *references* to arrays implement `IntoIterator`.
@@ -46,4 +51,4 @@ there is no added complexity in the new edition.
4651

4752
[25]: https://github.com/rust-lang/rust/issues/25725
4853
[20]: https://github.com/rust-lang/rust/pull/65819
49-
[22]: https://doc.rust-lang.org/book/ch05-03-method-syntax.html#wheres-the---operator
54+
[22]: https://doc.rust-lang.org/book/ch05-03-method-syntax.html#wheres-the---operator

src/rust-2021/default-cargo-resolver.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Summary
44

5+
- `edition = "2021"` implies `resolver = "2"` in `Cargo.toml`.
6+
57
## Details
68

79
Since Rust 1.51.0, Cargo has opt-in support for a [new feature resolver][4]
@@ -15,4 +17,4 @@ crates that are depended on in multiple ways.
1517
See [the announcement of Rust 1.51][5] for details.
1618

1719
[4]: https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2
18-
[5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver
20+
[5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver

src/rust-2021/disjoint-capture-in-closures.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Summary
44

5+
- `|| a.x + 1` now captures only `a.x` instead of `a`.
6+
- This can subtly change the drop order of things.
7+
58
## Details
69

710
[Closures](https://doc.rust-lang.org/book/ch13-01-closures.html)

src/rust-2021/or-patterns-macro-rules.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Summary
44

5+
- `$_:pat` in `macro_rules` now matches `|` too: e.g. `A | B`.
6+
- `$_:pat_param` behaves like `$_:pat` did before; it does not match (top level) `|`.
7+
- `$_:pat_param` is available in all editions.
8+
59
## Details
610

711
Starting in Rust 1.53.0, [patterns](https://doc.rust-lang.org/stable/reference/patterns.html)

src/rust-2021/panic-macro-consistency.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
## Summary
44

5-
## Details
5+
- `panic!(..)` now always use `format_args!(..)`, just like `println!()`.
6+
- `panic!("{")` is no longer accepted, without escaping the `{` as `{{`.
7+
- `panic!(x)` is no longer accepted if `x` is not a string literal.
8+
- Use `std::panic::panic_any(x)` to panic with a non-string payload.
69

10+
## Details
711

812
The `panic!()` macro is one of Rust's most well known macros.
913
However, it has [some subtle surprises](https://github.com/rust-lang/rfcs/blob/master/text/3007-panic-plan.md)
@@ -41,4 +45,4 @@ will be the only way to panic with something other than a formatted string.
4145

4246
In addition, `core::panic!()` and `std::panic!()` will be identical in Rust 2021.
4347
Currently, there are some historical differences between those two,
44-
which can be noticable when switching `#![no_std]` on or off.
48+
which can be noticable when switching `#![no_std]` on or off.

src/rust-2021/prelude.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Summary
44

5+
- `TryInto`, `TryFrom` and `FromIterator` are now part of the prelude.
6+
- This might change the meaning of e.g. `x.try_into()` depending on types and imports.
7+
58
## Details
69

710
The [prelude of the standard library](https://doc.rust-lang.org/stable/std/prelude/index.html)

src/rust-2021/reserving-syntax.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Summary
44

5+
- `any_prefix#..`, `any_prefix".."`, and `any_prefix'..'` are reserved syntax, and no longer tokenize.
6+
- These did not parse as valid Rust in any edition, except in arguments to macros.
7+
- Insert whitespace to avoid errors.
8+
59
## Details
610

711
To make space for some new syntax in the future,
@@ -37,4 +41,4 @@ These are some new prefixes you might see in the future:
3741
this prefix would've allowed us to accept `k#async` in edition 2015
3842
without having to wait for edition 2018 to reserve `async` as a keyword.
3943

40-
[10]: https://github.com/rust-lang/rfcs/pull/3101
44+
[10]: https://github.com/rust-lang/rfcs/pull/3101

src/rust-2021/warnings-promoted-to-error.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Summary
44

5+
- `bare-trait-objects` and `ellipsis-inclusive-range-patters` are now hard errors.
6+
57
## Details
68

79
Two existing lints are becoming hard errors in Rust 2021.
@@ -14,4 +16,4 @@ These lints will remain warnings in older editions.
1416
* `ellipsis-inclusive-range-patterns`:
1517
The [deprecated `...` syntax](https://doc.rust-lang.org/stable/reference/patterns.html#range-patterns)
1618
for inclusive range patterns is no longer accepted in Rust 2021.
17-
It has been superseded by `..=`, which is consistent with expressions.
19+
It has been superseded by `..=`, which is consistent with expressions.

0 commit comments

Comments
 (0)