diff --git a/src/test/ui/suggestions/suggest-tryinto-edition-change.rs b/src/test/ui/suggestions/suggest-tryinto-edition-change.rs index f03b42bbe475..e62990144c4c 100644 --- a/src/test/ui/suggestions/suggest-tryinto-edition-change.rs +++ b/src/test/ui/suggestions/suggest-tryinto-edition-change.rs @@ -2,30 +2,28 @@ // Edition 2021 change // edition:2018 -fn test() { - let _i: i16 = 0_i32.try_into().unwrap(); +// We mark this no_std to avoid emitting suggestions for both `std` and `core` traits. These were +// inconsistently ordered between CI and at least one local build, causing test failures. +#![no_std] +#![crate_type = "lib"] + +pub fn test() { + let _i: Result = 0_i32.try_into(); //~^ 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 - - let _i: i16 = TryFrom::try_from(0_i32).unwrap(); - //~^ ERROR failed to resolve: use of undeclared type - //~| NOTE not found in this scope - //~| NOTE 'std::convert::TryFrom' is included in the prelude starting in Edition 2021 - //~| NOTE 'core::convert::TryFrom' is included in the prelude starting in Edition 2021 - - let _i: i16 = TryInto::try_into(0_i32).unwrap(); - //~^ ERROR failed to resolve: use of undeclared type - //~| NOTE not found in this scope - //~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021 //~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021 - let _v: Vec<_> = FromIterator::from_iter(&[1]); + let _i: Result = TryFrom::try_from(0_i32); + //~^ ERROR failed to resolve: use of undeclared type + //~| NOTE not found in this scope + //~| NOTE 'core::convert::TryFrom' is included in the prelude starting in Edition 2021 + + let _i: Result = TryInto::try_into(0_i32); + //~^ ERROR failed to resolve: use of undeclared type + //~| NOTE not found in this scope + //~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021 + + let _i: () = FromIterator::from_iter(core::iter::empty()); //~^ ERROR failed to resolve: use of undeclared type - //~| NOTE 'std::iter::FromIterator' is included in the prelude starting in Edition 2021 //~| NOTE 'core::iter::FromIterator' is included in the prelude starting in Edition 2021 } - -fn main() { - test(); -} diff --git a/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr b/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr index 80191ec4fd7b..e7013063d452 100644 --- a/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr +++ b/src/test/ui/suggestions/suggest-tryinto-edition-change.stderr @@ -1,62 +1,53 @@ error[E0433]: failed to resolve: use of undeclared type `TryFrom` - --> $DIR/suggest-tryinto-edition-change.rs:11:19 + --> $DIR/suggest-tryinto-edition-change.rs:14:30 | -LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap(); - | ^^^^^^^ not found in this scope +LL | let _i: Result = TryFrom::try_from(0_i32); + | ^^^^^^^ not found in this scope | - = note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021 = note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021 -help: consider importing one of these items - | -LL | use std::convert::TryFrom; +help: consider importing this trait | LL | use core::convert::TryFrom; | error[E0433]: failed to resolve: use of undeclared type `TryInto` - --> $DIR/suggest-tryinto-edition-change.rs:17:19 + --> $DIR/suggest-tryinto-edition-change.rs:19:30 | -LL | let _i: i16 = TryInto::try_into(0_i32).unwrap(); - | ^^^^^^^ not found in this scope +LL | let _i: Result = TryInto::try_into(0_i32); + | ^^^^^^^ not found in this scope | - = note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021 = note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021 -help: consider importing one of these items - | -LL | use std::convert::TryInto; +help: consider importing this trait | LL | use core::convert::TryInto; | error[E0433]: failed to resolve: use of undeclared type `FromIterator` - --> $DIR/suggest-tryinto-edition-change.rs:23:22 + --> $DIR/suggest-tryinto-edition-change.rs:24:18 | -LL | let _v: Vec<_> = FromIterator::from_iter(&[1]); - | ^^^^^^^^^^^^ +LL | let _i: () = FromIterator::from_iter(core::iter::empty()); + | ^^^^^^^^^^^^ | ::: $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL | LL | pub trait IntoIterator { | ---------------------- similarly named trait `IntoIterator` defined here | - = note: 'std::iter::FromIterator' is included in the prelude starting in Edition 2021 = note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021 help: a trait with a similar name exists | -LL | let _v: Vec<_> = IntoIterator::from_iter(&[1]); - | ~~~~~~~~~~~~ -help: consider importing one of these items - | -LL | use std::iter::FromIterator; +LL | let _i: () = IntoIterator::from_iter(core::iter::empty()); + | ~~~~~~~~~~~~ +help: consider importing this trait | LL | use core::iter::FromIterator; | error[E0599]: no method named `try_into` found for type `i32` in the current scope - --> $DIR/suggest-tryinto-edition-change.rs:6:25 + --> $DIR/suggest-tryinto-edition-change.rs:9:36 | -LL | let _i: i16 = 0_i32.try_into().unwrap(); - | ^^^^^^^^ method not found in `i32` +LL | let _i: Result = 0_i32.try_into(); + | ^^^^^^^^ method not found in `i32` | ::: $SRC_DIR/core/src/convert/mod.rs:LL:COL | @@ -64,10 +55,10 @@ 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 + = note: 'core::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; +LL | use core::convert::TryInto; | error: aborting due to 4 previous errors