Skip to content

Commit 8a1b7da

Browse files
mockersfpietroalbini
authored andcommitted
rust-lang#56411 do not suggest a fix for a import conflict in a macro
1 parent 04d6d7b commit 8a1b7da

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/librustc_resolve/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -5103,11 +5103,13 @@ impl<'a> Resolver<'a> {
51035103
if let (
51045104
Ok(snippet),
51055105
NameBindingKind::Import { directive, ..},
5106-
_dummy @ false,
5106+
false,
5107+
false,
51075108
) = (
51085109
cm.span_to_snippet(binding.span),
51095110
binding.kind.clone(),
51105111
binding.span.is_dummy(),
5112+
binding.span.ctxt().outer().expn_info().is_some(),
51115113
) {
51125114
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
51135115
format!("Other{}", name)

src/test/ui/issues/issue-56411.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
macro_rules! import {
2+
( $($name:ident),* ) => {
3+
$(
4+
mod $name;
5+
pub use self::$name;
6+
//~^ ERROR the name `issue_56411` is defined multiple times
7+
//~| ERROR `issue_56411` is private, and cannot be re-exported
8+
9+
)*
10+
}
11+
}
12+
13+
import!(issue_56411);
14+
15+
fn main() {
16+
println!("Hello, world!");
17+
}

src/test/ui/issues/issue-56411.stderr

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0255]: the name `issue_56411` is defined multiple times
2+
--> $DIR/issue-56411.rs:5:21
3+
|
4+
LL | mod $name;
5+
| ---------- previous definition of the module `issue_56411` here
6+
LL | pub use self::$name;
7+
| ^^^^^^^^^^^
8+
| |
9+
| `issue_56411` reimported here
10+
| you can use `as` to change the binding name of the import
11+
...
12+
LL | import!(issue_56411);
13+
| --------------------- in this macro invocation
14+
|
15+
= note: `issue_56411` must be defined only once in the type namespace of this module
16+
17+
error[E0365]: `issue_56411` is private, and cannot be re-exported
18+
--> $DIR/issue-56411.rs:5:21
19+
|
20+
LL | pub use self::$name;
21+
| ^^^^^^^^^^^ re-export of private `issue_56411`
22+
...
23+
LL | import!(issue_56411);
24+
| --------------------- in this macro invocation
25+
|
26+
= note: consider declaring type or module `issue_56411` with `pub`
27+
28+
error: aborting due to 2 previous errors
29+
30+
Some errors occurred: E0255, E0365.
31+
For more information about an error, try `rustc --explain E0255`.

src/test/ui/issues/issue_56411.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-pass
2+
3+
struct T {}
4+
5+
fn main() {}

0 commit comments

Comments
 (0)