Skip to content

Commit c811f8f

Browse files
Point out macro expansion ident in resolver errors too
1 parent bc272f1 commit c811f8f

File tree

6 files changed

+26
-1
lines changed

6 files changed

+26
-1
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
194194
node => unreachable!("{node:?}"),
195195
};
196196

197-
// Try to get the span of the identifier within the expression's syntax context (if that's different).
197+
// Try to get the span of the identifier within the expression's syntax context
198+
// (if that's different).
198199
let within_macro_span = span.within_macro(expr_span);
199200

200201
// Avoid suggestions when we don't know what's going on.

compiler/rustc_resolve/src/late/diagnostics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
429429
let mut err = self.r.dcx().struct_span_err(base_error.span, base_error.msg.clone());
430430
err.code(code);
431431

432+
// Try to get the span of the identifier within the path's syntax context
433+
// (if that's different).
434+
if let Some(within_macro_span) = base_error.span.within_macro(span) {
435+
err.span_label(within_macro_span, "within this macro");
436+
}
437+
432438
self.detect_missing_binding_available_from_pattern(&mut err, path, following_seg);
433439
self.suggest_at_operator_in_slice_pat_with_range(&mut err, path);
434440
self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span);

tests/ui/hygiene/generate-mod.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
error[E0412]: cannot find type `FromOutside` in this scope
22
--> $DIR/generate-mod.rs:35:13
33
|
4+
LL | type A = $FromOutside;
5+
| ------------ within this macro
6+
...
47
LL | genmod!(FromOutside, Outer);
58
| ^^^^^^^^^^^ not found in this scope
69

710
error[E0412]: cannot find type `Outer` in this scope
811
--> $DIR/generate-mod.rs:35:26
912
|
13+
LL | struct $Outer;
14+
| ------ within this macro
15+
...
1016
LL | genmod!(FromOutside, Outer);
1117
| ^^^^^ not found in this scope
1218

tests/ui/hygiene/globs.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ error[E0425]: cannot find function `f` in this scope
5050
LL | n!(f);
5151
| ----- in this macro invocation
5252
...
53+
LL | $j();
54+
| -- within this macro
55+
...
5356
LL | n!(f);
5457
| ^ not found in this scope
5558
|
@@ -63,6 +66,9 @@ error[E0425]: cannot find function `f` in this scope
6366
LL | n!(f);
6467
| ----- in this macro invocation
6568
...
69+
LL | $j();
70+
| -- within this macro
71+
...
6672
LL | f
6773
| ^ not found in this scope
6874
|

tests/ui/macros/macro-parameter-span.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
error[E0425]: cannot find value `x` in this scope
22
--> $DIR/macro-parameter-span.rs:11:9
33
|
4+
LL | $id
5+
| --- within this macro
6+
...
47
LL | x
58
| ^ not found in this scope
69

tests/ui/macros/rfc-3086-metavar-expr/syntax-errors.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ LL | no_curly__no_rhs_dollar__no_round!(a);
338338
error[E0425]: cannot find value `a` in this scope
339339
--> $DIR/syntax-errors.rs:152:37
340340
|
341+
LL | ( $i:ident ) => { count($i) };
342+
| -- within this macro
343+
...
341344
LL | no_curly__rhs_dollar__no_round!(a);
342345
| ^ not found in this scope
343346

0 commit comments

Comments
 (0)