Skip to content

Commit

Permalink
Suggest importing std:: types always before core::
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Jun 12, 2024
1 parent 7f923f3 commit fa382d6
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2788,7 +2788,6 @@ fn show_candidates(
path_strings.extend(core_path_strings);
path_strings.dedup_by(|a, b| a.0 == b.0);
}
accessible_path_strings.sort();

if !accessible_path_strings.is_empty() {
let (determiner, kind, name, through) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | static FOO: Sync = AtomicUsize::new(0);
|
help: consider importing one of these items
|
LL + use core::sync::atomic::AtomicUsize;
|
LL + use std::sync::atomic::AtomicUsize;
|
LL + use core::sync::atomic::AtomicUsize;
|

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/const_refs_to_static-ice-121413.rs:12:17
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/hygiene/extern-prelude-from-opaque-fail-2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ LL | a!();
| ---- in this macro invocation
|
= help: consider importing one of these items:
core::mem
std::mem
core::mem
= note: this error originates in the macro `a` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: use of undeclared crate or module `my_core`
Expand All @@ -37,10 +37,10 @@ LL | fn f() { my_core::mem::drop(0); }
|
help: consider importing one of these items
|
LL + use core::mem;
|
LL + use std::mem;
|
LL + use core::mem;
|
help: if you import `mem`, refer to it directly
|
LL - fn f() { my_core::mem::drop(0); }
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/imports/cycle-import-in-std-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | use ops::{self as std};
| ^^^^^^^^^^^ no external crate `ops`
|
= help: consider importing one of these items instead:
core::ops
std::ops
core::ops

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/imports/cycle-import-in-std-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ LL | use ops::{self as std};
| ^^^^^^^^^^^ no external crate `ops`
|
= help: consider importing one of these items instead:
core::ops
std::ops
core::ops

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | use alloc;
|
help: consider importing one of these items instead
|
LL | use core::alloc;
| ~~~~~~~~~~~
LL | use std::alloc;
| ~~~~~~~~~~
LL | use core::alloc;
| ~~~~~~~~~~~

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suggestions/core-std-import-order-issue-83564.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ LL | let _x = NonZero::new(5u32).unwrap();
|
help: consider importing one of these items
|
LL + use core::num::NonZero;
|
LL + use std::num::NonZero;
|
LL + use core::num::NonZero;
|

error: aborting due to 1 previous error

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/suggestions/crate-or-module-typo.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ LL | bar: std::cell::Cell<bool>
| ~~~
help: consider importing one of these items
|
LL + use core::cell;
|
LL + use std::cell;
|
LL + use core::cell;
|
help: if you import `cell`, refer to it directly
|
LL - bar: st::cell::Cell<bool>
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/suggestions/suggest-tryinto-edition-change.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@ error[E0433]: failed to resolve: use of undeclared type `TryFrom`
LL | let _i: i16 = TryFrom::try_from(0_i32).unwrap();
| ^^^^^^^ use of undeclared type `TryFrom`
|
= note: 'core::convert::TryFrom' is included in the prelude starting in Edition 2021
= 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 core::convert::TryFrom;
|
LL + use std::convert::TryFrom;
|
LL + use core::convert::TryFrom;
|

error[E0433]: failed to resolve: use of undeclared type `TryInto`
--> $DIR/suggest-tryinto-edition-change.rs:16:19
|
LL | let _i: i16 = TryInto::try_into(0_i32).unwrap();
| ^^^^^^^ use of undeclared type `TryInto`
|
= note: 'core::convert::TryInto' is included in the prelude starting in Edition 2021
= 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 core::convert::TryInto;
|
LL + use std::convert::TryInto;
|
LL + use core::convert::TryInto;
|

error[E0433]: failed to resolve: use of undeclared type `FromIterator`
--> $DIR/suggest-tryinto-edition-change.rs:22:22
|
LL | let _v: Vec<_> = FromIterator::from_iter(&[1]);
| ^^^^^^^^^^^^ use of undeclared type `FromIterator`
|
= note: 'core::iter::FromIterator' is included in the prelude starting in Edition 2021
= 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 core::iter::FromIterator;
|
LL + use std::iter::FromIterator;
|
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
Expand Down

0 comments on commit fa382d6

Please sign in to comment.