Skip to content

Commit b89118a

Browse files
authored
Rollup merge of #141132 - bvanjoi:issue-141082, r=fmease
Use `crate::` prefix for root macro suggestions Fixes #141082 I've changed the prefix to `crate` directly, since it's compatible across all editions.
2 parents 2aff1d6 + 1adfdb4 commit b89118a

8 files changed

+51
-6
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24932493
let Res::Def(DefKind::Macro(MacroKind::Bang), _) = binding.res() else {
24942494
return None;
24952495
};
2496-
let module_name = crate_module.kind.name().unwrap_or(kw::Empty);
2496+
let module_name = crate_module.kind.name().unwrap_or(kw::Crate);
24972497
let import_snippet = match import.kind {
24982498
ImportKind::Single { source, target, .. } if source != target => {
24992499
format!("{source} as {target}")

tests/ui/imports/issue-99695-b.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod m {
1111
pub struct other_item;
1212
}
1313

14-
use ::nu;
14+
use crate::nu;
1515
pub use self::p::{other_item as _};
1616
//~^ ERROR unresolved import `self::p::nu` [E0432]
1717
//~| HELP a macro with this name exists at the root of the crate

tests/ui/imports/issue-99695-b.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub use self::p::{nu, other_item as _};
77
= note: this could be because a macro annotated with `#[macro_export]` will be exported at the root of the crate instead of the module where it is defined
88
help: a macro with this name exists at the root of the crate
99
|
10-
LL ~ use ::nu;
10+
LL ~ use crate::nu;
1111
LL ~ pub use self::p::{other_item as _};
1212
|
1313

tests/ui/imports/issue-99695.fixed renamed to tests/ui/imports/issue-99695.edition_2015.fixed

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ run-rustfix
2+
//@ revisions: edition_2015 edition_2018
3+
//@ [edition_2015] edition: 2015
4+
//@ [edition_2018] edition: 2018
5+
26
#![allow(unused, nonstandard_style)]
37
mod m {
48
#[macro_export]
@@ -8,7 +12,7 @@ mod m {
812

913
pub struct other_item;
1014

11-
use ::nu;
15+
use crate::nu;
1216
pub use self::{other_item as _};
1317
//~^ ERROR unresolved import `self::nu` [E0432]
1418
//~| HELP a macro with this name exists at the root of the crate

tests/ui/imports/issue-99695.stderr renamed to tests/ui/imports/issue-99695.edition_2015.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0432]: unresolved import `self::nu`
2-
--> $DIR/issue-99695.rs:11:20
2+
--> $DIR/issue-99695.rs:15:20
33
|
44
LL | pub use self::{nu, other_item as _};
55
| ^^ no `nu` in `m`
66
|
77
= note: this could be because a macro annotated with `#[macro_export]` will be exported at the root of the crate instead of the module where it is defined
88
help: a macro with this name exists at the root of the crate
99
|
10-
LL ~ use ::nu;
10+
LL ~ use crate::nu;
1111
LL ~ pub use self::{other_item as _};
1212
|
1313

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ run-rustfix
2+
//@ revisions: edition_2015 edition_2018
3+
//@ [edition_2015] edition: 2015
4+
//@ [edition_2018] edition: 2018
5+
6+
#![allow(unused, nonstandard_style)]
7+
mod m {
8+
#[macro_export]
9+
macro_rules! nu {
10+
{} => {};
11+
}
12+
13+
pub struct other_item;
14+
15+
use crate::nu;
16+
pub use self::{other_item as _};
17+
//~^ ERROR unresolved import `self::nu` [E0432]
18+
//~| HELP a macro with this name exists at the root of the crate
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0432]: unresolved import `self::nu`
2+
--> $DIR/issue-99695.rs:15:20
3+
|
4+
LL | pub use self::{nu, other_item as _};
5+
| ^^ no `nu` in `m`
6+
|
7+
= note: this could be because a macro annotated with `#[macro_export]` will be exported at the root of the crate instead of the module where it is defined
8+
help: a macro with this name exists at the root of the crate
9+
|
10+
LL ~ use crate::nu;
11+
LL ~ pub use self::{other_item as _};
12+
|
13+
14+
error: aborting due to 1 previous error
15+
16+
For more information about this error, try `rustc --explain E0432`.

tests/ui/imports/issue-99695.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
//@ run-rustfix
2+
//@ revisions: edition_2015 edition_2018
3+
//@ [edition_2015] edition: 2015
4+
//@ [edition_2018] edition: 2018
5+
26
#![allow(unused, nonstandard_style)]
37
mod m {
48
#[macro_export]

0 commit comments

Comments
 (0)