From e91d5ca197b966b841c4e49c921215a69f9d9c19 Mon Sep 17 00:00:00 2001 From: Jakob Degen Date: Sun, 24 Oct 2021 21:09:52 -0400 Subject: [PATCH] Add test checking that Edition 2021 is suggested for .try_into() and fix other test --- .../future-prelude-collision-shadow.stderr | 1 + .../suggest-tryinto-edition-change.rs | 11 ++++++++++ .../suggest-tryinto-edition-change.stderr | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/test/ui/suggestions/suggest-tryinto-edition-change.rs create mode 100644 src/test/ui/suggestions/suggest-tryinto-edition-change.stderr diff --git a/src/test/ui/rust-2021/future-prelude-collision-shadow.stderr b/src/test/ui/rust-2021/future-prelude-collision-shadow.stderr index e4662b430dcc..d945b4c94ca2 100644 --- a/src/test/ui/rust-2021/future-prelude-collision-shadow.stderr +++ b/src/test/ui/rust-2021/future-prelude-collision-shadow.stderr @@ -15,6 +15,7 @@ LL | fn try_into(self) -> Result; | the method is available for `Rc` here | = help: items from traits can only be used if the trait is in scope + = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 help: consider wrapping the receiver expression with the appropriate type | LL | let _: u32 = Box::new(3u8).try_into().unwrap(); diff --git a/src/test/ui/suggestions/suggest-tryinto-edition-change.rs b/src/test/ui/suggestions/suggest-tryinto-edition-change.rs new file mode 100644 index 000000000000..f60ef587cfaa --- /dev/null +++ b/src/test/ui/suggestions/suggest-tryinto-edition-change.rs @@ -0,0 +1,11 @@ +// Make sure that calling `.try_into()` in pre-2021 mentions Edition 2021 change +// edition:2018 + +fn test() { + let i: i16 = 0_i32.try_into().unwrap(); + //~^ ERROR no method named `try_into` found for type `i32` in the current scope + //~| NOTE method not found in `i32` + //~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021 +} + +fn main() {} diff --git a/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr b/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr new file mode 100644 index 000000000000..7915937023c0 --- /dev/null +++ b/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr @@ -0,0 +1,21 @@ +error[E0599]: no method named `try_into` found for type `i32` in the current scope + --> $DIR/suggest-tryinto-edition-change.rs:5:24 + | +LL | let i: i16 = 0_i32.try_into().unwrap(); + | ^^^^^^^^ method not found in `i32` + | + ::: $SRC_DIR/core/src/convert/mod.rs:LL:COL + | +LL | fn try_into(self) -> Result; + | -------- the method is available for `i32` here + | + = help: items from traits can only be used if the trait is in scope + = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 +help: the following trait is implemented but not in scope; perhaps add a `use` for it: + | +LL | use std::convert::TryInto; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0599`.