Skip to content

Commit

Permalink
Auto merge of #118065 - estebank:core-not-found-404, r=TaKO8Ki
Browse files Browse the repository at this point in the history
When failing to import `core`, suggest `std`
  • Loading branch information
bors committed Nov 23, 2023
2 parents c387f01 + ec50f1c commit 360bafa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
Applicability::MaybeIncorrect,
)),
)
} else if ident.name == sym::core {
(
format!("maybe a missing crate `{ident}`?"),
Some((
vec![(ident.span, "std".to_string())],
"try using `std` instead of `core`".to_string(),
Applicability::MaybeIncorrect,
)),
)
} else if self.tcx.sess.is_rust_2015() {
(
format!("maybe a missing crate `{ident}`?"),
Expand Down
12 changes: 8 additions & 4 deletions tests/ui/feature-gates/feature-gate-extern_absolute_paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ error[E0432]: unresolved import `core`
--> $DIR/feature-gate-extern_absolute_paths.rs:1:5
|
LL | use core::default;
| ^^^^ maybe a missing crate `core`?
|
= help: consider adding `extern crate core` to use the `core` crate
| ^^^^
| |
| maybe a missing crate `core`?
| help: try using `std` instead of `core`: `std`

error[E0433]: failed to resolve: maybe a missing crate `core`?
--> $DIR/feature-gate-extern_absolute_paths.rs:4:19
|
LL | let _: u8 = ::core::default::Default();
| ^^^^ maybe a missing crate `core`?
|
= help: consider adding `extern crate core` to use the `core` crate
help: try using `std` instead of `core`
|
LL | let _: u8 = ::std::default::Default();
| ~~~
help: consider importing this module
|
LL + use std::default;
Expand Down
13 changes: 8 additions & 5 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/issue-102156.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ error[E0433]: failed to resolve: maybe a missing crate `core`?
--> $DIR/issue-102156.rs:4:5
|
LL | use core::convert::{From, TryFrom};
| ^^^^ maybe a missing crate `core`?
|
= help: consider adding `extern crate core` to use the `core` crate
| ^^^^
| |
| maybe a missing crate `core`?
| help: try using `std` instead of `core`: `std`

error[E0433]: failed to resolve: maybe a missing crate `core`?
--> $DIR/issue-102156.rs:4:5
|
LL | use core::convert::{From, TryFrom};
| ^^^^ maybe a missing crate `core`?
| ^^^^
| |
| maybe a missing crate `core`?
| help: try using `std` instead of `core`: `std`
|
= help: consider adding `extern crate core` to use the `core` crate
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors
Expand Down
7 changes: 4 additions & 3 deletions tests/ui/simd/portable-intrinsics-arent-exposed.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ error[E0433]: failed to resolve: maybe a missing crate `core`?
--> $DIR/portable-intrinsics-arent-exposed.rs:4:5
|
LL | use core::simd::intrinsics;
| ^^^^ maybe a missing crate `core`?
|
= help: consider adding `extern crate core` to use the `core` crate
| ^^^^
| |
| maybe a missing crate `core`?
| help: try using `std` instead of `core`: `std`

error[E0432]: unresolved import `std::simd::intrinsics`
--> $DIR/portable-intrinsics-arent-exposed.rs:5:5
Expand Down

0 comments on commit 360bafa

Please sign in to comment.