Skip to content

Commit c9d48e0

Browse files
committed
make help text for cannot find macro actionable
1 parent c55d1ee commit c9d48e0

10 files changed

+26
-18
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ fn show_candidates(
25582558

25592559
for candidate in accessible_path_strings {
25602560
msg.push('\n');
2561-
msg.push_str(&candidate.0);
2561+
msg.push_str(&format!("use {};", &candidate.0));
25622562
}
25632563

25642564
err.help(msg);

tests/ui/empty/empty-macro-use.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error: cannot find macro `macro_two` in this scope
44
LL | macro_two!();
55
| ^^^^^^^^^
66
|
7-
help: consider importing this macro
7+
= help: consider importing this macro:
8+
use two_macros::macro_two;
89
|
910
LL + use two_macros::macro_two;
1011
|

tests/ui/hygiene/globs.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LL | n!(f);
5252
| ^ not found in this scope
5353
|
5454
= help: consider importing this function:
55-
foo::f
55+
use foo::f;
5656
= note: this error originates in the macro `n` (in Nightly builds, run with -Z macro-backtrace for more info)
5757

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

7171
error: aborting due to 4 previous errors

tests/ui/hygiene/no_implicit_prelude-2018.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error: cannot find macro `print` in this scope
44
LL | print!();
55
| ^^^^^
66
|
7-
help: consider importing this macro
7+
= help: consider importing this macro:
8+
use std::print;
89
|
910
LL + use std::print;
1011
|

tests/ui/imports/bad-import-in-nested.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | use super::{super::C::D::AA, AA as _};
55
| ^^^^^^^^^^^^^^^ no `AA` in `C::D`
66
|
77
= help: consider importing this type alias instead:
8-
crate::A::AA
8+
use crate::A::AA;
99

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

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

2828
error: aborting due to 3 previous errors
2929

tests/ui/macros/issue-88228.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error: cannot find macro `bla` in this scope
44
LL | bla!();
55
| ^^^
66
|
7-
help: consider importing this macro
7+
= help: consider importing this macro:
8+
use crate::hey::bla;
89
|
910
LL + use crate::hey::bla;
1011
|
@@ -23,7 +24,8 @@ error: cannot find derive macro `Bla` in this scope
2324
LL | #[derive(Bla)]
2425
| ^^^
2526
|
26-
help: consider importing this derive macro
27+
= help: consider importing this derive macro:
28+
use crate::hey::Bla;
2729
|
2830
LL + use crate::hey::Bla;
2931
|

tests/ui/macros/macro-use-wrong-name.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ LL | macro_two!();
99
LL | macro_rules! macro_one { () => ("one") }
1010
| ---------------------- similarly named macro `macro_one` defined here
1111
|
12-
help: a macro with a similar name exists
12+
= help: consider importing this macro:
13+
use two_macros::macro_two;
1314
|
1415
LL | macro_one!();
1516
| ~~~~~~~~~

tests/ui/missing/missing-macro-use.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ error: cannot find macro `macro_two` in this scope
44
LL | macro_two!();
55
| ^^^^^^^^^
66
|
7-
help: consider importing this macro
7+
= help: consider importing this macro:
8+
use two_macros::macro_two;
89
|
910
LL + use two_macros::macro_two;
1011
|

tests/ui/proc-macro/derive-helper-shadowing.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ error: cannot find attribute `empty_helper` in this scope
1616
LL | #[derive(GenHelperUse)]
1717
| ^^^^^^^^^^^^
1818
|
19+
= help: consider importing this attribute macro:
20+
use empty_helper;
1921
= note: this error originates in the derive macro `GenHelperUse` (in Nightly builds, run with -Z macro-backtrace for more info)
20-
help: consider importing this attribute macro
2122
|
2223
LL + use empty_helper;
2324
|
@@ -31,8 +32,9 @@ LL | #[empty_helper]
3132
LL | gen_helper_use!();
3233
| ----------------- in this macro invocation
3334
|
35+
= help: consider importing this attribute macro:
36+
use crate::empty_helper;
3437
= note: this error originates in the macro `gen_helper_use` (in Nightly builds, run with -Z macro-backtrace for more info)
35-
help: consider importing this attribute macro
3638
|
3739
LL + use crate::empty_helper;
3840
|

tests/ui/proc-macro/generate-mod.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | generate_mod::check!();
55
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
66
|
77
= help: consider importing this struct:
8-
FromOutside
8+
use FromOutside;
99
= note: this error originates in the macro `generate_mod::check` (in Nightly builds, run with -Z macro-backtrace for more info)
1010

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

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

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

4141
error: cannot find type `FromOutside` in this scope

0 commit comments

Comments
 (0)