Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When failing to import core, suggest std #118065

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading