Suggest importing the right kind of macro.
This commit is contained in:
parent
e7f7fe462a
commit
bcc5ecb969
4 changed files with 53 additions and 3 deletions
|
@ -950,9 +950,7 @@ impl<'a> Resolver<'a> {
|
||||||
self.add_typo_suggestion(err, suggestion, ident.span);
|
self.add_typo_suggestion(err, suggestion, ident.span);
|
||||||
|
|
||||||
let import_suggestions =
|
let import_suggestions =
|
||||||
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, |res| {
|
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
||||||
matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _))
|
|
||||||
});
|
|
||||||
show_candidates(err, None, &import_suggestions, false, true);
|
show_candidates(err, None, &import_suggestions, false, true);
|
||||||
|
|
||||||
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
|
if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
|
||||||
|
|
22
src/test/ui/macros/issue-88228.rs
Normal file
22
src/test/ui/macros/issue-88228.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// compile-flags: -Z deduplicate-diagnostics=yes
|
||||||
|
// edition:2018
|
||||||
|
|
||||||
|
mod hey {
|
||||||
|
pub use Copy as Bla;
|
||||||
|
pub use std::println as bla;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Bla)]
|
||||||
|
//~^ ERROR cannot find derive macro `Bla`
|
||||||
|
//~| NOTE consider importing this derive macro
|
||||||
|
struct A;
|
||||||
|
|
||||||
|
#[derive(println)]
|
||||||
|
//~^ ERROR cannot find derive macro `println`
|
||||||
|
struct B;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
bla!();
|
||||||
|
//~^ ERROR cannot find macro `bla`
|
||||||
|
//~| NOTE consider importing this macro
|
||||||
|
}
|
26
src/test/ui/macros/issue-88228.stderr
Normal file
26
src/test/ui/macros/issue-88228.stderr
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
error: cannot find macro `bla` in this scope
|
||||||
|
--> $DIR/issue-88228.rs:19:5
|
||||||
|
|
|
||||||
|
LL | bla!();
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
= note: consider importing this macro:
|
||||||
|
crate::hey::bla
|
||||||
|
|
||||||
|
error: cannot find derive macro `println` in this scope
|
||||||
|
--> $DIR/issue-88228.rs:14:10
|
||||||
|
|
|
||||||
|
LL | #[derive(println)]
|
||||||
|
| ^^^^^^^
|
||||||
|
|
||||||
|
error: cannot find derive macro `Bla` in this scope
|
||||||
|
--> $DIR/issue-88228.rs:9:10
|
||||||
|
|
|
||||||
|
LL | #[derive(Bla)]
|
||||||
|
| ^^^
|
||||||
|
|
|
||||||
|
= note: consider importing this derive macro:
|
||||||
|
crate::hey::Bla
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
|
@ -16,6 +16,8 @@ error: cannot find attribute `empty_helper` in this scope
|
||||||
LL | #[derive(GenHelperUse)]
|
LL | #[derive(GenHelperUse)]
|
||||||
| ^^^^^^^^^^^^
|
| ^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
|
= note: consider importing this attribute macro:
|
||||||
|
empty_helper
|
||||||
= note: this error originates in the derive macro `GenHelperUse` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the derive macro `GenHelperUse` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error: cannot find attribute `empty_helper` in this scope
|
error: cannot find attribute `empty_helper` in this scope
|
||||||
|
@ -27,6 +29,8 @@ LL | #[empty_helper]
|
||||||
LL | gen_helper_use!();
|
LL | gen_helper_use!();
|
||||||
| ------------------ in this macro invocation
|
| ------------------ in this macro invocation
|
||||||
|
|
|
|
||||||
|
= note: consider importing this attribute macro:
|
||||||
|
crate::empty_helper
|
||||||
= note: this error originates in the macro `gen_helper_use` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `gen_helper_use` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution)
|
error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue