Account for macros when trying to point at inference cause

Do not point at macro invocation which expands to an inference error. Avoid the following:

```
error[E0308]: mismatched types
  --> $DIR/does-not-have-iter-interpolated.rs:12:5
   |
LL |     quote!($($nonrep)*);
   |     ^^^^^^^^^^^^^^^^^^^
   |     |
   |     expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
   |     expected due to this
   |     here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
```
This commit is contained in:
Esteban Küber 2025-08-10 21:47:52 +00:00
parent 18eeac04fc
commit e9609abda4
5 changed files with 3 additions and 11 deletions

View file

@ -698,7 +698,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
match (self.tcx.parent_hir_node(expr.hir_id), error) {
(hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), init: Some(init), .. }), _)
if init.hir_id == expr.hir_id =>
if init.hir_id == expr.hir_id && !ty.span.source_equal(init.span) =>
{
// Point at `let` assignment type.
err.span_label(ty.span, "expected due to this");

View file

@ -5,7 +5,6 @@ LL | quote!($($nonrep $nonrep)*);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
| expected due to this
| here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
error: aborting due to 1 previous error

View file

@ -5,7 +5,6 @@ LL | quote!($($nonrep)*);
| ^^^^^^^^^^^^^^^^^^^
| |
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
| expected due to this
| here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition`
error: aborting due to 1 previous error

View file

@ -2,10 +2,7 @@ error[E0308]: mismatched types
--> $DIR/does-not-have-iter-separated.rs:8:5
|
LL | quote!($(a b),*);
| ^^^^^^^^^^^^^^^^
| |
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
| expected due to this
| ^^^^^^^^^^^^^^^^ expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
error: aborting due to 1 previous error

View file

@ -2,10 +2,7 @@ error[E0308]: mismatched types
--> $DIR/does-not-have-iter.rs:8:5
|
LL | quote!($(a b)*);
| ^^^^^^^^^^^^^^^
| |
| expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
| expected due to this
| ^^^^^^^^^^^^^^^ expected `HasIterator`, found `ThereIsNoIteratorInRepetition`
error: aborting due to 1 previous error