Skip to content

Commit 6ce3ae4

Browse files
committed
Make ui/suggestions/suggest-tryinto-edition-change.rs no_std to avoid getting inconsistent output between local and CI.
1 parent 958e645 commit 6ce3ae4

File tree

2 files changed

+30
-41
lines changed

2 files changed

+30
-41
lines changed

src/test/ui/suggestions/suggest-tryinto-edition-change.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,28 @@
22
// Edition 2021 change
33
// edition:2018
44

5-
fn test() {
6-
let _i: i16 = 0_i32.try_into().unwrap();
5+
// We mark this no_std to avoid emitting suggestions for both `std` and `core` traits. These were
6+
// inconsistently ordered between CI and at least one local build, causing test failures.
7+
#![no_std]
8+
#![crate_type = "lib"]
9+
10+
pub fn test() {
11+
let _i: Result<i16, _> = 0_i32.try_into();
712
//~^ ERROR no method named `try_into` found for type `i32` in the current scope
813
//~| NOTE method not found in `i32`
9-
//~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021
14+
//~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021
1015

11-
let _i: i16 = TryFrom::try_from(0_i32).unwrap();
16+
let _i: Result<i16, _> = TryFrom::try_from(0_i32);
1217
//~^ ERROR failed to resolve: use of undeclared type
1318
//~| NOTE not found in this scope
14-
//~| NOTE 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
1519
//~| NOTE 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
1620

17-
let _i: i16 = TryInto::try_into(0_i32).unwrap();
21+
let _i: Result<i16, _> = TryInto::try_into(0_i32);
1822
//~^ ERROR failed to resolve: use of undeclared type
1923
//~| NOTE not found in this scope
20-
//~| NOTE 'std::convert::TryInto' is included in the prelude starting in Edition 2021
2124
//~| NOTE 'core::convert::TryInto' is included in the prelude starting in Edition 2021
2225

23-
let _v: Vec<_> = FromIterator::from_iter(&[1]);
26+
let _i: () = FromIterator::from_iter(core::iter::empty());
2427
//~^ ERROR failed to resolve: use of undeclared type
25-
//~| NOTE 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
2628
//~| NOTE 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
2729
}
28-
29-
fn main() {
30-
test();
31-
}

src/test/ui/suggestions/suggest-tryinto-edition-change.stderr

+19-28
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,64 @@
11
error[E0433]: failed to resolve: use of undeclared type `TryFrom`
2-
--> $DIR/suggest-tryinto-edition-change.rs:11:19
2+
--> $DIR/suggest-tryinto-edition-change.rs:14:30
33
|
4-
LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap();
5-
| ^^^^^^^ not found in this scope
4+
LL | let _i: Result<i16, _> = TryFrom::try_from(0_i32);
5+
| ^^^^^^^ not found in this scope
66
|
7-
= note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
87
= note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
9-
help: consider importing one of these items
10-
|
11-
LL | use std::convert::TryFrom;
8+
help: consider importing this trait
129
|
1310
LL | use core::convert::TryFrom;
1411
|
1512

1613
error[E0433]: failed to resolve: use of undeclared type `TryInto`
17-
--> $DIR/suggest-tryinto-edition-change.rs:17:19
14+
--> $DIR/suggest-tryinto-edition-change.rs:19:30
1815
|
19-
LL | let _i: i16 = TryInto::try_into(0_i32).unwrap();
20-
| ^^^^^^^ not found in this scope
16+
LL | let _i: Result<i16, _> = TryInto::try_into(0_i32);
17+
| ^^^^^^^ not found in this scope
2118
|
22-
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
2319
= note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
24-
help: consider importing one of these items
25-
|
26-
LL | use std::convert::TryInto;
20+
help: consider importing this trait
2721
|
2822
LL | use core::convert::TryInto;
2923
|
3024

3125
error[E0433]: failed to resolve: use of undeclared type `FromIterator`
32-
--> $DIR/suggest-tryinto-edition-change.rs:23:22
26+
--> $DIR/suggest-tryinto-edition-change.rs:24:18
3327
|
34-
LL | let _v: Vec<_> = FromIterator::from_iter(&[1]);
35-
| ^^^^^^^^^^^^
28+
LL | let _i: () = FromIterator::from_iter(core::iter::empty());
29+
| ^^^^^^^^^^^^
3630
|
3731
::: $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
3832
|
3933
LL | pub trait IntoIterator {
4034
| ---------------------- similarly named trait `IntoIterator` defined here
4135
|
42-
= note: 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
4336
= note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
4437
help: a trait with a similar name exists
4538
|
46-
LL | let _v: Vec<_> = IntoIterator::from_iter(&[1]);
47-
| ~~~~~~~~~~~~
48-
help: consider importing one of these items
49-
|
50-
LL | use std::iter::FromIterator;
39+
LL | let _i: () = IntoIterator::from_iter(core::iter::empty());
40+
| ~~~~~~~~~~~~
41+
help: consider importing this trait
5142
|
5243
LL | use core::iter::FromIterator;
5344
|
5445

5546
error[E0599]: no method named `try_into` found for type `i32` in the current scope
56-
--> $DIR/suggest-tryinto-edition-change.rs:6:25
47+
--> $DIR/suggest-tryinto-edition-change.rs:9:36
5748
|
58-
LL | let _i: i16 = 0_i32.try_into().unwrap();
59-
| ^^^^^^^^ method not found in `i32`
49+
LL | let _i: Result<i16, _> = 0_i32.try_into();
50+
| ^^^^^^^^ method not found in `i32`
6051
|
6152
::: $SRC_DIR/core/src/convert/mod.rs:LL:COL
6253
|
6354
LL | fn try_into(self) -> Result<T, Self::Error>;
6455
| -------- the method is available for `i32` here
6556
|
6657
= help: items from traits can only be used if the trait is in scope
67-
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
58+
= note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
6859
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
6960
|
70-
LL | use std::convert::TryInto;
61+
LL | use core::convert::TryInto;
7162
|
7263

7364
error: aborting due to 4 previous errors

0 commit comments

Comments
 (0)