Skip to content

Commit fa382d6

Browse files
committed
Suggest importing std:: types always before core::
1 parent 7f923f3 commit fa382d6

9 files changed

+22
-23
lines changed

compiler/rustc_resolve/src/diagnostics.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,6 @@ fn show_candidates(
27882788
path_strings.extend(core_path_strings);
27892789
path_strings.dedup_by(|a, b| a.0 == b.0);
27902790
}
2791-
accessible_path_strings.sort();
27922791

27932792
if !accessible_path_strings.is_empty() {
27942793
let (determiner, kind, name, through) =

tests/ui/consts/const_refs_to_static-ice-121413.edition2021.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | static FOO: Sync = AtomicUsize::new(0);
66
|
77
help: consider importing one of these items
88
|
9-
LL + use core::sync::atomic::AtomicUsize;
10-
|
119
LL + use std::sync::atomic::AtomicUsize;
1210
|
11+
LL + use core::sync::atomic::AtomicUsize;
12+
|
1313

1414
error[E0782]: trait objects must include the `dyn` keyword
1515
--> $DIR/const_refs_to_static-ice-121413.rs:12:17

tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ LL | a!();
2525
| ---- in this macro invocation
2626
|
2727
= help: consider importing one of these items:
28-
core::mem
2928
std::mem
29+
core::mem
3030
= note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)
3131

3232
error[E0433]: failed to resolve: use of undeclared crate or module `my_core`
@@ -37,10 +37,10 @@ LL | fn f() { my_core::mem::drop(0); }
3737
|
3838
help: consider importing one of these items
3939
|
40-
LL + use core::mem;
41-
|
4240
LL + use std::mem;
4341
|
42+
LL + use core::mem;
43+
|
4444
help: if you import `mem`, refer to it directly
4545
|
4646
LL - fn f() { my_core::mem::drop(0); }

tests/ui/imports/cycle-import-in-std-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | use ops::{self as std};
55
| ^^^^^^^^^^^ no external crate `ops`
66
|
77
= help: consider importing one of these items instead:
8-
core::ops
98
std::ops
9+
core::ops
1010

1111
error: aborting due to 1 previous error
1212

tests/ui/imports/cycle-import-in-std-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ LL | use ops::{self as std};
55
| ^^^^^^^^^^^ no external crate `ops`
66
|
77
= help: consider importing one of these items instead:
8-
core::ops
98
std::ops
9+
core::ops
1010

1111
error: aborting due to 1 previous error
1212

tests/ui/rfcs/rfc-2126-extern-absolute-paths/not-allowed.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | use alloc;
66
|
77
help: consider importing one of these items instead
88
|
9-
LL | use core::alloc;
10-
| ~~~~~~~~~~~
119
LL | use std::alloc;
1210
| ~~~~~~~~~~
11+
LL | use core::alloc;
12+
| ~~~~~~~~~~~
1313

1414
error: aborting due to 1 previous error
1515

tests/ui/suggestions/core-std-import-order-issue-83564.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ LL | let _x = NonZero::new(5u32).unwrap();
66
|
77
help: consider importing one of these items
88
|
9-
LL + use core::num::NonZero;
10-
|
119
LL + use std::num::NonZero;
1210
|
11+
LL + use core::num::NonZero;
12+
|
1313

1414
error: aborting due to 1 previous error
1515

tests/ui/suggestions/crate-or-module-typo.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ LL | bar: std::cell::Cell<bool>
3232
| ~~~
3333
help: consider importing one of these items
3434
|
35-
LL + use core::cell;
36-
|
3735
LL + use std::cell;
3836
|
37+
LL + use core::cell;
38+
|
3939
help: if you import `cell`, refer to it directly
4040
|
4141
LL - bar: st::cell::Cell<bool>

tests/ui/suggestions/suggest-tryinto-edition-change.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,48 @@ error[E0433]: failed to resolve: use of undeclared type `TryFrom`
44
LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap();
55
| ^^^^^^^ use of undeclared type `TryFrom`
66
|
7-
= note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
87
= note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
8+
= note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
99
help: consider importing one of these items
1010
|
11-
LL + use core::convert::TryFrom;
12-
|
1311
LL + use std::convert::TryFrom;
1412
|
13+
LL + use core::convert::TryFrom;
14+
|
1515

1616
error[E0433]: failed to resolve: use of undeclared type `TryInto`
1717
--> $DIR/suggest-tryinto-edition-change.rs:16:19
1818
|
1919
LL | let _i: i16 = TryInto::try_into(0_i32).unwrap();
2020
| ^^^^^^^ use of undeclared type `TryInto`
2121
|
22-
= note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
2322
= note: 'std::convert::TryInto' is included in the prelude starting in Edition 2021
23+
= note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
2424
help: consider importing one of these items
2525
|
26-
LL + use core::convert::TryInto;
27-
|
2826
LL + use std::convert::TryInto;
2927
|
28+
LL + use core::convert::TryInto;
29+
|
3030

3131
error[E0433]: failed to resolve: use of undeclared type `FromIterator`
3232
--> $DIR/suggest-tryinto-edition-change.rs:22:22
3333
|
3434
LL | let _v: Vec<_> = FromIterator::from_iter(&[1]);
3535
| ^^^^^^^^^^^^ use of undeclared type `FromIterator`
3636
|
37-
= note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
3837
= note: 'std::iter::FromIterator' is included in the prelude starting in Edition 2021
38+
= note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
3939
help: a trait with a similar name exists
4040
|
4141
LL | let _v: Vec<_> = IntoIterator::from_iter(&[1]);
4242
| ~~~~~~~~~~~~
4343
help: consider importing one of these items
4444
|
45-
LL + use core::iter::FromIterator;
46-
|
4745
LL + use std::iter::FromIterator;
4846
|
47+
LL + use core::iter::FromIterator;
48+
|
4949

5050
error[E0599]: no method named `try_into` found for type `i32` in the current scope
5151
--> $DIR/suggest-tryinto-edition-change.rs:6:25

0 commit comments

Comments
 (0)