Add test checking that Edition 2021 is suggested for .try_into() and fix other test

This commit is contained in:
Jakob Degen 2021-10-24 21:09:52 -04:00
parent 3876753668
commit e91d5ca197
3 changed files with 33 additions and 0 deletions

View File

@ -15,6 +15,7 @@ LL | fn try_into(self) -> Result<T, Self::Error>;
| the method is available for `Rc<u8>` 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();

View File

@ -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() {}

View File

@ -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<T, Self::Error>;
| -------- 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`.