Skip to content

make help text for cannot find macro actionable #112091

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

Closed
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
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,7 @@ fn show_candidates(

for candidate in accessible_path_strings {
msg.push('\n');
msg.push_str(&candidate.0);
msg.push_str(&format!("use {};", &candidate.0));
}

err.help(msg);
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/empty/empty-macro-use.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ error: cannot find macro `macro_two` in this scope
LL | macro_two!();
| ^^^^^^^^^
|
help: consider importing this macro
= help: consider importing this macro:
use two_macros::macro_two;
|
LL + use two_macros::macro_two;
|
Comment on lines +7 to 11
Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite sure how this happened given the logic change, but I would like us to avoid changing the message for the structured suggestion case.

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/hygiene/globs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ LL | n!(f);
| ^ not found in this scope
|
= help: consider importing this function:
foo::f
use foo::f;
= note: this error originates in the macro `n` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find function `f` in this scope
Expand All @@ -65,7 +65,7 @@ LL | f
| ^ not found in this scope
|
= help: consider importing this function:
foo::f
use foo::f;
= note: this error originates in the macro `n` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/hygiene/no_implicit_prelude-2018.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ error: cannot find macro `print` in this scope
LL | print!();
| ^^^^^
|
help: consider importing this macro
= help: consider importing this macro:
use std::print;
|
LL + use std::print;
|
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/imports/bad-import-in-nested.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | use super::{super::C::D::AA, AA as _};
| ^^^^^^^^^^^^^^^ no `AA` in `C::D`
|
= help: consider importing this type alias instead:
crate::A::AA
use crate::A::AA;

error[E0432]: unresolved import `crate::C::AA`
--> $DIR/bad-import-in-nested.rs:20:26
Expand All @@ -14,7 +14,7 @@ LL | use crate::C::{self, AA};
| ^^ no `AA` in `C`
|
= help: consider importing this type alias instead:
crate::A::AA
use crate::A::AA;

error[E0432]: unresolved import `crate::C::BB`
--> $DIR/bad-import-in-nested.rs:23:20
Expand All @@ -23,7 +23,7 @@ LL | use crate::{A, C::BB};
| ^^^^^ no `BB` in `C`
|
= help: consider importing this type alias instead:
crate::A::BB
use crate::A::BB;

error: aborting due to 3 previous errors

Expand Down
6 changes: 4 additions & 2 deletions tests/ui/macros/issue-88228.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ error: cannot find macro `bla` in this scope
LL | bla!();
| ^^^
|
help: consider importing this macro
= help: consider importing this macro:
use crate::hey::bla;
|
LL + use crate::hey::bla;
|
Expand All @@ -23,7 +24,8 @@ error: cannot find derive macro `Bla` in this scope
LL | #[derive(Bla)]
| ^^^
|
help: consider importing this derive macro
= help: consider importing this derive macro:
use crate::hey::Bla;
|
LL + use crate::hey::Bla;
|
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/macros/macro-use-wrong-name.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ LL | macro_two!();
LL | macro_rules! macro_one { () => ("one") }
| ---------------------- similarly named macro `macro_one` defined here
|
help: a macro with a similar name exists
= help: consider importing this macro:
use two_macros::macro_two;
|
LL | macro_one!();
| ~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/missing/missing-macro-use.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ error: cannot find macro `macro_two` in this scope
LL | macro_two!();
| ^^^^^^^^^
|
help: consider importing this macro
= help: consider importing this macro:
use two_macros::macro_two;
|
LL + use two_macros::macro_two;
|
Expand Down
6 changes: 4 additions & 2 deletions tests/ui/proc-macro/derive-helper-shadowing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ error: cannot find attribute `empty_helper` in this scope
LL | #[derive(GenHelperUse)]
| ^^^^^^^^^^^^
|
= help: consider importing this attribute macro:
use empty_helper;
= note: this error originates in the derive macro `GenHelperUse` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this attribute macro
|
LL + use empty_helper;
|
Expand All @@ -31,8 +32,9 @@ LL | #[empty_helper]
LL | gen_helper_use!();
| ----------------- in this macro invocation
|
= help: consider importing this attribute macro:
use crate::empty_helper;
= note: this error originates in the macro `gen_helper_use` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this attribute macro
|
LL + use crate::empty_helper;
|
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/proc-macro/generate-mod.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | generate_mod::check!();
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
= help: consider importing this struct:
FromOutside
use FromOutside;
= note: this error originates in the macro `generate_mod::check` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `Outer` in this scope
Expand All @@ -15,7 +15,7 @@ LL | generate_mod::check!();
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
= help: consider importing this struct:
Outer
use Outer;
= note: this error originates in the macro `generate_mod::check` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `FromOutside` in this scope
Expand All @@ -25,7 +25,7 @@ LL | #[generate_mod::check_attr]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
= help: consider importing this struct:
FromOutside
use FromOutside;
= note: this error originates in the attribute macro `generate_mod::check_attr` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0412]: cannot find type `OuterAttr` in this scope
Expand All @@ -35,7 +35,7 @@ LL | #[generate_mod::check_attr]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
|
= help: consider importing this struct:
OuterAttr
use OuterAttr;
= note: this error originates in the attribute macro `generate_mod::check_attr` (in Nightly builds, run with -Z macro-backtrace for more info)

error: cannot find type `FromOutside` in this scope
Expand Down