Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggest importing the right kind of macro. #88229

Merged
merged 1 commit into from
Aug 22, 2021
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
4 changes: 1 addition & 3 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,7 @@ impl<'a> Resolver<'a> {
self.add_typo_suggestion(err, suggestion, ident.span);

let import_suggestions =
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, |res| {
matches!(res, Res::Def(DefKind::Macro(MacroKind::Bang), _))
});
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
Comment on lines 952 to +953
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gonna have a merge conflict with the other PR, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That other PR includes this one as the first commit (with identical hash even), so should be fine. ^^

show_candidates(err, None, &import_suggestions, false, true);

if macro_kind == MacroKind::Derive && (ident.name == sym::Send || ident.name == sym::Sync) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/ui/macros/issue-88228.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 26 additions & 0 deletions src/test/ui/macros/issue-88228.stderr
Original file line number Diff line number Diff line change
@@ -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

4 changes: 4 additions & 0 deletions src/test/ui/proc-macro/derive-helper-shadowing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ error: cannot find attribute `empty_helper` in this scope
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)

error: cannot find attribute `empty_helper` in this scope
Expand All @@ -27,6 +29,8 @@ LL | #[empty_helper]
LL | gen_helper_use!();
| ------------------ 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)

error[E0659]: `empty_helper` is ambiguous (name vs any other name during import resolution)
Expand Down