Point out macro expansion ident in resolver errors too

This commit is contained in:
Michael Goulet 2025-02-24 20:20:54 +00:00
parent ab31129956
commit e4dfca8ac2
6 changed files with 26 additions and 1 deletions

View File

@ -194,7 +194,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
node => unreachable!("{node:?}"),
};
// Try to get the span of the identifier within the expression's syntax context (if that's different).
// Try to get the span of the identifier within the expression's syntax context
// (if that's different).
let within_macro_span = span.within_macro(expr_span);
// Avoid suggestions when we don't know what's going on.

View File

@ -429,6 +429,12 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
let mut err = self.r.dcx().struct_span_err(base_error.span, base_error.msg.clone());
err.code(code);
// Try to get the span of the identifier within the path's syntax context
// (if that's different).
if let Some(within_macro_span) = base_error.span.within_macro(span) {
err.span_label(within_macro_span, "within this macro");
}
self.detect_missing_binding_available_from_pattern(&mut err, path, following_seg);
self.suggest_at_operator_in_slice_pat_with_range(&mut err, path);
self.suggest_swapping_misplaced_self_ty_and_trait(&mut err, source, res, base_error.span);

View File

@ -1,12 +1,18 @@
error[E0412]: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:35:13
|
LL | type A = $FromOutside;
| ------------ due to this macro variable
...
LL | genmod!(FromOutside, Outer);
| ^^^^^^^^^^^ not found in this scope
error[E0412]: cannot find type `Outer` in this scope
--> $DIR/generate-mod.rs:35:26
|
LL | struct $Outer;
| ------ due to this macro variable
...
LL | genmod!(FromOutside, Outer);
| ^^^^^ not found in this scope

View File

@ -50,6 +50,9 @@ error[E0425]: cannot find function `f` in this scope
LL | n!(f);
| ----- in this macro invocation
...
LL | $j();
| -- due to this macro variable
...
LL | n!(f);
| ^ not found in this scope
|
@ -63,6 +66,9 @@ error[E0425]: cannot find function `f` in this scope
LL | n!(f);
| ----- in this macro invocation
...
LL | $j();
| -- due to this macro variable
...
LL | f
| ^ not found in this scope
|

View File

@ -1,6 +1,9 @@
error[E0425]: cannot find value `x` in this scope
--> $DIR/macro-parameter-span.rs:11:9
|
LL | $id
| --- due to this macro variable
...
LL | x
| ^ not found in this scope

View File

@ -338,6 +338,9 @@ LL | no_curly__no_rhs_dollar__no_round!(a);
error[E0425]: cannot find value `a` in this scope
--> $DIR/syntax-errors.rs:152:37
|
LL | ( $i:ident ) => { count($i) };
| -- due to this macro variable
...
LL | no_curly__rhs_dollar__no_round!(a);
| ^ not found in this scope