Skip to content

Commit f219ab5

Browse files
committed
Tweak E0412 label for proc-macros
1 parent 00a2616 commit f219ab5

File tree

7 files changed

+36
-19
lines changed

7 files changed

+36
-19
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,29 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
214214
let item_span = path.last().unwrap().ident.span;
215215
let sp = item_span.peel_ctxt();
216216
let ctxt_kind = sp.ctxt().outer_expn_data().kind;
217-
let (mod_prefix, mod_str, suggestion) =
217+
let (mod_prefix, mod_str, name, mod_label, suggestion) =
218218
if let ExpnKind::Macro(MacroKind::Attr | MacroKind::Bang, name) = ctxt_kind
219219
&& sp.parent_callsite().map(|p| (p.lo(), p.hi())) == Some((sp.lo(), sp.hi()))
220220
{
221221
// This span comes from a proc macro and it doesn't point at user code.
222-
(String::new(), format!("the expanded code of procedural macro `{name}`"), None)
222+
(
223+
String::new(),
224+
format!("the expanded code of procedural macro `{name}`"),
225+
format!("`{path_str}` "),
226+
format!("expanded code of this procedural macro"),
227+
None,
228+
)
223229
} else if let ExpnKind::Macro(MacroKind::Derive, name) = ctxt_kind
224230
&& sp.parent_callsite().map(|p| (p.lo(), p.hi())) == Some((sp.lo(), sp.hi()))
225231
{
226232
// This span comes from a `derive` macro and it doesn't point at user code.
227-
(String::new(), format!("the expanded code of `derive` macro `{name}`"), None)
233+
(
234+
String::new(),
235+
format!("the expanded code of `derive` macro `{name}`"),
236+
format!("`{path_str}` "),
237+
format!("expanded code of this `derive` macro"),
238+
None,
239+
)
228240
} else if path.len() == 1 {
229241
debug!(?self.diagnostic_metadata.current_impl_items);
230242
debug!(?self.diagnostic_metadata.current_function);
@@ -259,26 +271,31 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
259271
} else {
260272
None
261273
};
262-
(String::new(), "this scope".to_string(), suggestion)
274+
let s = "this scope".to_string();
275+
(String::new(), s.clone(), String::new(), s, suggestion)
263276
} else if path.len() == 2 && path[0].ident.name == kw::PathRoot {
264277
if self.r.tcx.sess.edition() > Edition::Edition2015 {
265278
// In edition 2018 onwards, the `::foo` syntax may only pull from the extern prelude
266279
// which overrides all other expectations of item type
267280
expected = "crate";
268-
(String::new(), "the list of imported crates".to_string(), None)
281+
let s = "the list of imported crates".to_string();
282+
(String::new(), s.clone(), String::new(), s, None)
269283
} else {
270-
(String::new(), "the crate root".to_string(), None)
284+
let s = "the crate root".to_string();
285+
(String::new(), s.clone(), String::new(), s, None)
271286
}
272287
} else if path.len() == 2 && path[0].ident.name == kw::Crate {
273-
(String::new(), "the crate root".to_string(), None)
288+
let s = "the crate root".to_string();
289+
(String::new(), s.clone(), String::new(), s, None)
274290
} else {
275291
let mod_path = &path[..path.len() - 1];
276292
let mod_prefix = match self.resolve_path(mod_path, Some(TypeNS), None) {
277293
PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(),
278294
_ => None,
279295
}
280296
.map_or_else(String::new, |res| format!("{} ", res.descr()));
281-
(mod_prefix, format!("`{}`", Segment::names_to_string(mod_path)), None)
297+
let s = format!("`{}`", Segment::names_to_string(mod_path));
298+
(mod_prefix, s.clone(), String::new(), s, None)
282299
};
283300

284301
let (fallback_label, suggestion) = if path_str == "async"
@@ -302,7 +319,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
302319
} else {
303320
suggestion
304321
};
305-
(format!("not found in {mod_str}"), override_suggestion)
322+
(format!("{name}not found in {mod_label}"), override_suggestion)
306323
};
307324

308325
BaseError {

tests/ui/feature-gates/feature-gate-concat_idents2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ error[E0425]: cannot find value `ab` in the expanded code of procedural macro `c
1111
--> $DIR/feature-gate-concat_idents2.rs:2:5
1212
|
1313
LL | concat_idents!(a, b);
14-
| ^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `concat_idents`
14+
| ^^^^^^^^^^^^^^^^^^^^ `ab` not found in expanded code of this procedural macro
1515
|
1616
= note: this error originates in the macro `concat_idents` (in Nightly builds, run with -Z macro-backtrace for more info)
1717

tests/ui/issues/issue-32950.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0412]: cannot find type `FooBar` in the expanded code of procedural macro
88
--> $DIR/issue-32950.rs:5:5
99
|
1010
LL | concat_idents!(Foo, Bar)
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `concat_idents`
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^ `FooBar` not found in expanded code of this procedural macro
1212
|
1313
= note: this error originates in the macro `concat_idents` (in Nightly builds, run with -Z macro-backtrace for more info)
1414

tests/ui/macros/issue-100199.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0405]: cannot find trait `MyTrait` in the expanded code of procedural mac
22
--> $DIR/issue-100199.rs:1:1
33
|
44
LL | #[issue_100199::struct_with_bound]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `issue_100199::struct_with_bound`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `crate::MyTrait` not found in expanded code of this procedural macro
66
|
77
= note: this error originates in the attribute macro `issue_100199::struct_with_bound` (in Nightly builds, run with -Z macro-backtrace for more info)
88

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0412]: cannot find type `FromOutside` in the expanded code of procedural
22
--> $DIR/generate-mod.rs:9:1
33
|
44
LL | generate_mod::check!();
5-
| ^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `generate_mod::check`
5+
| ^^^^^^^^^^^^^^^^^^^^^^ `FromOutside` not found in expanded code of this procedural macro
66
|
77
= help: consider importing this struct:
88
FromOutside
@@ -12,7 +12,7 @@ error[E0412]: cannot find type `Outer` in the expanded code of procedural macro
1212
--> $DIR/generate-mod.rs:9:1
1313
|
1414
LL | generate_mod::check!();
15-
| ^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `generate_mod::check`
15+
| ^^^^^^^^^^^^^^^^^^^^^^ `Outer` not found in expanded code of this procedural macro
1616
|
1717
= help: consider importing this struct:
1818
Outer
@@ -22,15 +22,15 @@ error[E0412]: cannot find type `FromOutside` in the expanded code of procedural
2222
--> $DIR/generate-mod.rs:12:1
2323
|
2424
LL | #[generate_mod::check_attr]
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `generate_mod::check_attr`
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `FromOutside` not found in expanded code of this procedural macro
2626
|
2727
= note: this error originates in the attribute macro `generate_mod::check_attr` (in Nightly builds, run with -Z macro-backtrace for more info)
2828

2929
error[E0412]: cannot find type `OuterAttr` in the expanded code of procedural macro `generate_mod::check_attr`
3030
--> $DIR/generate-mod.rs:12:1
3131
|
3232
LL | #[generate_mod::check_attr]
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `generate_mod::check_attr`
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `OuterAttr` not found in expanded code of this procedural macro
3434
|
3535
= note: this error originates in the attribute macro `generate_mod::check_attr` (in Nightly builds, run with -Z macro-backtrace for more info)
3636

tests/ui/proc-macro/issue-38586.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0425]: cannot find value `foo` in the expanded code of `derive` macro `A`
22
--> $DIR/issue-38586.rs:6:10
33
|
44
LL | #[derive(A)]
5-
| ^ not found in the expanded code of `derive` macro `A`
5+
| ^ `foo` not found in expanded code of this `derive` macro
66
|
77
= note: this error originates in the derive macro `A` (in Nightly builds, run with -Z macro-backtrace for more info)
88

tests/ui/proc-macro/issue-83510.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0412]: cannot find type `Foo` in the expanded code of procedural macro `i
22
--> $DIR/issue-83510.rs:5:1
33
|
44
LL | issue_83510::dance_like_you_want_to_ice!();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `issue_83510::dance_like_you_want_to_ice`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Foo` not found in expanded code of this procedural macro
66
|
77
= note: this error originates in the macro `issue_83510::dance_like_you_want_to_ice` (in Nightly builds, run with -Z macro-backtrace for more info)
88

@@ -18,7 +18,7 @@ error[E0405]: cannot find trait `Baz` in the expanded code of procedural macro `
1818
--> $DIR/issue-83510.rs:5:1
1919
|
2020
LL | issue_83510::dance_like_you_want_to_ice!();
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in the expanded code of procedural macro `issue_83510::dance_like_you_want_to_ice`
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Baz` not found in expanded code of this procedural macro
2222
|
2323
= note: this error originates in the macro `issue_83510::dance_like_you_want_to_ice` (in Nightly builds, run with -Z macro-backtrace for more info)
2424

0 commit comments

Comments
 (0)