Skip to content

Commit 98091c0

Browse files
committed
diagnostics: add }; only if { was added too
1 parent cf2d0ce commit 98091c0

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,18 +2321,18 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
23212321
format!("{{{}, {}", import_snippet, start_snippet)
23222322
},
23232323
));
2324+
2325+
// Add a `};` to the end if nested, matching the `{` added at the start.
2326+
if !has_nested {
2327+
corrections.push((source_map.end_point(after_crate_name), "};".to_string()));
2328+
}
23242329
} else {
23252330
// If the root import is module-relative, add the import separately
23262331
corrections.push((
23272332
source_map.start_point(import.use_span).shrink_to_lo(),
23282333
format!("use {module_name}::{import_snippet};\n"),
23292334
));
23302335
}
2331-
2332-
// Add a `};` to the end if nested, matching the `{` added at the start.
2333-
if !has_nested {
2334-
corrections.push((source_map.end_point(after_crate_name), "};".to_string()));
2335-
}
23362336
}
23372337

23382338
let suggestion = Some((
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-rustfix
2+
#![allow(unused, nonstandard_style)]
3+
mod m {
4+
5+
mod p {
6+
#[macro_export]
7+
macro_rules! nu {
8+
{} => {};
9+
}
10+
11+
pub struct other_item;
12+
}
13+
14+
use ::nu;
15+
pub use self::p::{other_item as _};
16+
//~^ ERROR unresolved import `self::p::nu` [E0432]
17+
//~| HELP a macro with this name exists at the root of the crate
18+
}
19+
20+
fn main() {}

src/test/ui/imports/issue-99695-b.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// run-rustfix
2+
#![allow(unused, nonstandard_style)]
3+
mod m {
4+
5+
mod p {
6+
#[macro_export]
7+
macro_rules! nu {
8+
{} => {};
9+
}
10+
11+
pub struct other_item;
12+
}
13+
14+
pub use self::p::{nu, other_item as _};
15+
//~^ ERROR unresolved import `self::p::nu` [E0432]
16+
//~| HELP a macro with this name exists at the root of the crate
17+
}
18+
19+
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:14: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 ::nu;
11+
LL ~ pub use self::p::{other_item as _};
12+
|
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)