Skip to content

Fix #73948 #74292

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

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 9 additions & 1 deletion src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::owning_ref::OwningRef;
use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::MetadataRef;
use rustc_errors::struct_span_err;
use rustc_errors::{struct_span_err, Applicability};
use rustc_middle::middle::cstore::{CrateSource, MetadataLoader};
use rustc_session::config::{self, CrateType};
use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch};
Expand Down Expand Up @@ -1068,6 +1068,14 @@ impl CrateError {
err.note(&format!("the `{}` target may not be installed", locator.triple));
} else if crate_name == sym::profiler_builtins {
err.note(&"the compiler may have been built without the profiler runtime");
} else if crate_name == sym::meta {
err.note(&"meta is a reserved crate name");
err.span_suggestion(
span,
"you can use `crate::` or `self::` if you intended to refer to a local module and not a crate",
"crate::meta".to_string(),
Applicability::MaybeIncorrect,
);
}
err.span_label(span, "can't find crate");
err
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/rfc-2126-extern-absolute-paths/meta.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ error[E0463]: can't find crate for `meta`
|
LL | use meta;
| ^^^^ can't find crate
|
= note: meta is a reserved crate name
help: you can use `crate::` or `self::` if you intended to refer to a local module and not a crate
|
LL | use crate::meta;
| ^^^^^^^^^^^

error: aborting due to previous error

Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/suggestions/issue-73948-meta-as-module-name.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-only
// run-rustfix
// edition:2018

// https://github.com/rust-lang/rust/issues/73948
// Tests that when `meta` is used as a module name and imported uniformly a
// suggestion is made to make the import unambiguous with `crate::meta`

mod meta {
pub const FOO: bool = true;
}

use crate::meta::FOO; //~ ERROR can't find crate for `meta`

fn main() {
assert!(FOO);
}
17 changes: 17 additions & 0 deletions src/test/ui/suggestions/issue-73948-meta-as-module-name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-only
// run-rustfix
// edition:2018

// https://github.com/rust-lang/rust/issues/73948
// Tests that when `meta` is used as a module name and imported uniformly a
// suggestion is made to make the import unambiguous with `crate::meta`

mod meta {
pub const FOO: bool = true;
}

use meta::FOO; //~ ERROR can't find crate for `meta`

fn main() {
assert!(FOO);
}
15 changes: 15 additions & 0 deletions src/test/ui/suggestions/issue-73948-meta-as-module-name.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0463]: can't find crate for `meta`
--> $DIR/issue-73948-meta-as-module-name.rs:13:5
|
LL | use meta::FOO;
| ^^^^ can't find crate
|
= note: meta is a reserved crate name
help: you can use `crate::` or `self::` if you intended to refer to a local module and not a crate
|
LL | use crate::meta::FOO;
| ^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.