Skip to content

Commit 524021c

Browse files
committed
Use crate:: prefix for root macro suggestions
1 parent a43b8d1 commit 524021c

8 files changed

+54
-6
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
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 renamed to tests/ui/imports/issue-99695-b.edition_2015.fixed

Lines changed: 5 additions & 1 deletion
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

@@ -11,7 +15,7 @@ mod m {
1115
pub struct other_item;
1216
}
1317

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0432]: unresolved import `self::p::nu`
2-
--> $DIR/issue-99695-b.rs:14:23
2+
--> $DIR/issue-99695-b.rs:18:23
33
|
44
LL | pub use self::p::{nu, other_item as _};
55
| ^^ no `nu` in `m::p`
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::p::{other_item as _};
1212
|
1313

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
9+
mod p {
10+
#[macro_export]
11+
macro_rules! nu {
12+
{} => {};
13+
}
14+
15+
pub struct other_item;
16+
}
17+
18+
use crate::nu;
19+
pub use self::p::{other_item as _};
20+
//~^ ERROR unresolved import `self::p::nu` [E0432]
21+
//~| HELP a macro with this name exists at the root of the crate
22+
}
23+
24+
fn main() {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0432]: unresolved import `self::p::nu`
2+
--> $DIR/issue-99695-b.rs:18:23
3+
|
4+
LL | pub use self::p::{nu, other_item as _};
5+
| ^^ no `nu` in `m::p`
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::p::{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-b.rs

Lines changed: 4 additions & 0 deletions
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

tests/ui/imports/issue-99695.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mod m {
88

99
pub struct other_item;
1010

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

tests/ui/imports/issue-99695.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | pub use self::{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::{other_item as _};
1212
|
1313

0 commit comments

Comments
 (0)