From 3b039f89d289b3bdd0a4b6bee95c7b8e114b96c7 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 14 Jun 2021 15:46:31 +0200 Subject: [PATCH] Add short summaries to all 2021 edition changes. --- src/rust-2021/IntoIterator-for-arrays.md | 7 ++++++- src/rust-2021/default-cargo-resolver.md | 4 +++- src/rust-2021/disjoint-capture-in-closures.md | 3 +++ src/rust-2021/or-patterns-macro-rules.md | 4 ++++ src/rust-2021/panic-macro-consistency.md | 8 ++++++-- src/rust-2021/prelude.md | 3 +++ src/rust-2021/reserving-syntax.md | 6 +++++- src/rust-2021/warnings-promoted-to-error.md | 4 +++- 8 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/rust-2021/IntoIterator-for-arrays.md b/src/rust-2021/IntoIterator-for-arrays.md index e26e7fbf..bfd2fabc 100644 --- a/src/rust-2021/IntoIterator-for-arrays.md +++ b/src/rust-2021/IntoIterator-for-arrays.md @@ -2,6 +2,11 @@ ## Summary +- Arrays implement `IntoIterator` in *all* editions. +- The new `.into_iter()` is *hidden* in Rust 2015 and Rust 2018 in method call syntax. + So, `array.into_iter()` still resolves to `(&array).into_iter()` as before. +- `array.into_iter()` changes meaning when switching to Rust 2021. + ## Details Until Rust 1.53, only *references* to arrays implement `IntoIterator`. @@ -46,4 +51,4 @@ there is no added complexity in the new edition. [25]: https://github.com/rust-lang/rust/issues/25725 [20]: https://github.com/rust-lang/rust/pull/65819 -[22]: https://doc.rust-lang.org/book/ch05-03-method-syntax.html#wheres-the---operator \ No newline at end of file +[22]: https://doc.rust-lang.org/book/ch05-03-method-syntax.html#wheres-the---operator diff --git a/src/rust-2021/default-cargo-resolver.md b/src/rust-2021/default-cargo-resolver.md index a798b873..6eb949ad 100644 --- a/src/rust-2021/default-cargo-resolver.md +++ b/src/rust-2021/default-cargo-resolver.md @@ -2,6 +2,8 @@ ## Summary +- `edition = "2021"` implies `resolver = "2"` in `Cargo.toml`. + ## Details 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. See [the announcement of Rust 1.51][5] for details. [4]: https://doc.rust-lang.org/cargo/reference/resolver.html#feature-resolver-version-2 -[5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver \ No newline at end of file +[5]: https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#cargos-new-feature-resolver diff --git a/src/rust-2021/disjoint-capture-in-closures.md b/src/rust-2021/disjoint-capture-in-closures.md index 4e47fd45..46458c50 100644 --- a/src/rust-2021/disjoint-capture-in-closures.md +++ b/src/rust-2021/disjoint-capture-in-closures.md @@ -2,6 +2,9 @@ ## Summary +- `|| a.x + 1` now captures only `a.x` instead of `a`. +- This can subtly change the drop order of things. + ## Details [Closures](https://doc.rust-lang.org/book/ch13-01-closures.html) diff --git a/src/rust-2021/or-patterns-macro-rules.md b/src/rust-2021/or-patterns-macro-rules.md index 451b0e5f..66f64ab5 100644 --- a/src/rust-2021/or-patterns-macro-rules.md +++ b/src/rust-2021/or-patterns-macro-rules.md @@ -2,6 +2,10 @@ ## Summary +- `$_:pat` in `macro_rules` now matches `|` too: e.g. `A | B`. +- `$_:pat_param` behaves like `$_:pat` did before; it does not match (top level) `|`. +- `$_:pat_param` is available in all editions. + ## Details Starting in Rust 1.53.0, [patterns](https://doc.rust-lang.org/stable/reference/patterns.html) diff --git a/src/rust-2021/panic-macro-consistency.md b/src/rust-2021/panic-macro-consistency.md index cf4265bc..10ad2248 100644 --- a/src/rust-2021/panic-macro-consistency.md +++ b/src/rust-2021/panic-macro-consistency.md @@ -2,8 +2,12 @@ ## Summary -## Details +- `panic!(..)` now always use `format_args!(..)`, just like `println!()`. +- `panic!("{")` is no longer accepted, without escaping the `{` as `{{`. +- `panic!(x)` is no longer accepted if `x` is not a string literal. +- Use `std::panic::panic_any(x)` to panic with a non-string payload. +## Details The `panic!()` macro is one of Rust's most well known macros. 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. In addition, `core::panic!()` and `std::panic!()` will be identical in Rust 2021. Currently, there are some historical differences between those two, -which can be noticable when switching `#![no_std]` on or off. \ No newline at end of file +which can be noticable when switching `#![no_std]` on or off. diff --git a/src/rust-2021/prelude.md b/src/rust-2021/prelude.md index 2d182066..a62993b6 100644 --- a/src/rust-2021/prelude.md +++ b/src/rust-2021/prelude.md @@ -2,6 +2,9 @@ ## Summary +- `TryInto`, `TryFrom` and `FromIterator` are now part of the prelude. +- This might change the meaning of e.g. `x.try_into()` depending on types and imports. + ## Details The [prelude of the standard library](https://doc.rust-lang.org/stable/std/prelude/index.html) diff --git a/src/rust-2021/reserving-syntax.md b/src/rust-2021/reserving-syntax.md index 315954be..b69fd3b5 100644 --- a/src/rust-2021/reserving-syntax.md +++ b/src/rust-2021/reserving-syntax.md @@ -2,6 +2,10 @@ ## Summary +- `any_prefix#..`, `any_prefix".."`, and `any_prefix'..'` are reserved syntax, and no longer tokenize. +- These did not parse as valid Rust in any edition, except in arguments to macros. +- Insert whitespace to avoid errors. + ## Details 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: this prefix would've allowed us to accept `k#async` in edition 2015 without having to wait for edition 2018 to reserve `async` as a keyword. -[10]: https://github.com/rust-lang/rfcs/pull/3101 \ No newline at end of file +[10]: https://github.com/rust-lang/rfcs/pull/3101 diff --git a/src/rust-2021/warnings-promoted-to-error.md b/src/rust-2021/warnings-promoted-to-error.md index 5c20246d..117b0d59 100644 --- a/src/rust-2021/warnings-promoted-to-error.md +++ b/src/rust-2021/warnings-promoted-to-error.md @@ -2,6 +2,8 @@ ## Summary +- `bare-trait-objects` and `ellipsis-inclusive-range-patters` are now hard errors. + ## Details Two existing lints are becoming hard errors in Rust 2021. @@ -14,4 +16,4 @@ These lints will remain warnings in older editions. * `ellipsis-inclusive-range-patterns`: The [deprecated `...` syntax](https://doc.rust-lang.org/stable/reference/patterns.html#range-patterns) for inclusive range patterns is no longer accepted in Rust 2021. - It has been superseded by `..=`, which is consistent with expressions. \ No newline at end of file + It has been superseded by `..=`, which is consistent with expressions.