Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_resolve/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,3 +1774,14 @@ pub(crate) enum UnusedImportsSugg {
num_to_remove: usize,
},
}

#[derive(Diagnostic)]
#[diag("attribute macro `{$attr_path}` is ambiguous")]
#[note("ambiguous because of a name conflict with a tool namespace")]
#[note("`{$tool}` could refer to a tool namespace")]
pub(crate) struct ToolAttrAmbiguity {
#[primary_span]
pub path_span: Span,
pub attr_path: String,
pub tool: Symbol,
}
10 changes: 10 additions & 0 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
});
}
}
if kind == MacroKind::Attr
&& let [tool, _second, ..] = path.segments.as_slice()
&& self.registered_attr_tool_decls.contains_key(&IdentKey::new(tool.ident))
{
self.dcx().emit_err(diagnostics::ToolAttrAmbiguity {
path_span: path.span,
attr_path: pprust::path_to_string(path),
tool: tool.ident.name,
});
}
}
Res::NonMacroAttr(..) | Res::Err => {}
_ => panic!("expected `DefKind::Macro` or `Res::NonMacroAttr`"),
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/diagnostic_namespace/existing_proc_macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ check-pass
//@ proc-macro: proc-macro-helper.rs

extern crate proc_macro_helper;
Expand All @@ -17,6 +16,7 @@ mod test2 {
}

#[diagnostic::on_unimplemented]
//~^ ERROR attribute macro `diagnostic::on_unimplemented` is ambiguous
trait Foo {}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/diagnostic_namespace/existing_proc_macros.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: attribute macro `diagnostic::on_unimplemented` is ambiguous
--> $DIR/existing_proc_macros.rs:18:7
|
LL | #[diagnostic::on_unimplemented]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: ambiguous because of a name conflict with a tool namespace
= note: `diagnostic` could refer to a tool namespace

error: aborting due to 1 previous error

27 changes: 27 additions & 0 deletions tests/ui/tool-attributes/no_implicit_prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#![no_implicit_prelude]
#![feature(register_tool)]
#![register_tool(my_tool)]

mod test1 {
mod my_tool {
pub use ::std::derive as attr;
}

#[my_tool::attr(Debug)]
//~^ ERROR attribute macro `my_tool::attr` is ambiguous
struct Foo;
}

mod test2 {
mod clippy {
pub use ::std::derive as format_args;
}

#[rustfmt::skip]
//~^ ERROR cannot find module or crate `rustfmt` in this scope
#[clippy::format_args(Debug)]
//~^ ERROR attribute macro `clippy::format_args` is ambiguous
struct Foo;
}

fn main() {}
27 changes: 27 additions & 0 deletions tests/ui/tool-attributes/no_implicit_prelude.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error: attribute macro `my_tool::attr` is ambiguous
--> $DIR/no_implicit_prelude.rs:10:7
|
LL | #[my_tool::attr(Debug)]
| ^^^^^^^^^^^^^
|
= note: ambiguous because of a name conflict with a tool namespace
= note: `my_tool` could refer to a tool namespace

error: attribute macro `clippy::format_args` is ambiguous
--> $DIR/no_implicit_prelude.rs:22:7
|
LL | #[clippy::format_args(Debug)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: ambiguous because of a name conflict with a tool namespace
= note: `clippy` could refer to a tool namespace

error[E0433]: cannot find module or crate `rustfmt` in this scope
--> $DIR/no_implicit_prelude.rs:20:7
|
LL | #[rustfmt::skip]
| ^^^^^^^ use of unresolved module or unlinked crate `rustfmt`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0433`.
Loading