Skip to content

Commit e237690

Browse files
committed
diagnostics: add }; only if { was added too
1 parent e9d8d23 commit e237690

File tree

4 files changed

+60
-5
lines changed

4 files changed

+60
-5
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2161,18 +2161,18 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
21612161
format!("{{{}, {}", import_snippet, start_snippet)
21622162
},
21632163
));
2164+
2165+
// Add a `};` to the end if nested, matching the `{` added at the start.
2166+
if !has_nested {
2167+
corrections.push((source_map.end_point(after_crate_name), "};".to_string()));
2168+
}
21642169
} else {
21652170
// If the root import is module-relative, add the import separately
21662171
corrections.push((
21672172
source_map.start_point(import.use_span).shrink_to_lo(),
21682173
format!("use {module_name}::{import_snippet};\n"),
21692174
));
21702175
}
2171-
2172-
// Add a `};` to the end if nested, matching the `{` added at the start.
2173-
if !has_nested {
2174-
corrections.push((source_map.end_point(after_crate_name), "};".to_string()));
2175-
}
21762176
}
21772177

21782178
let suggestion = Some((

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

+20
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() {}

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

+19
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() {}

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

+16
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)