Skip to content

Commit 9df0b7d

Browse files
authored
Rollup merge of #148465 - Jarcho:for_span, r=davidtwco,Zalathar
Adjust spans into the `for` loops context before creating the new desugaring spans. When lowering `for` loops, the spans for the `into_iter` call and the `Some` pattern used the span of the provided pattern and head expression. If either of those came from a different `SyntaxContext` this would result in some very strange contexts. e.g.: ```rust macro_rules! m { ($e:expr) => { { $e } } } for _ in m!(expr) {} ``` This would result in the `into_iter` call have a context chain of `desugar => m!() => root` which is completely nonsensical; `m!()` does not have a `for` loop. The `into_iter` call also ends up located at `{ $e }` rather than inside the `for _ in _` part. This fixes that by walking the spans up to the `for` loop's context first. This will not handle adjusting the location of macro variable expansions (e.g. `for _ in $e`), but this does adjust the context to match the `for` loops. --- This ended up causing rust-lang/rust-clippy#16008. Clippy should be using a `debug_assert` rather than `unreachable`, but it still results in a bug either way.
2 parents cbfd44c + 27bcfc3 commit 9df0b7d

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)