Fix MutVisitor's default implementations to visit Stmt's and BinOp's spans by dtolnay · Pull Request #133784 · rust-lang/rust (original) (raw)
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request
Rollup merge of rust-lang#133784 - dtolnay:visitspans, r=compiler-errors
Fix MutVisitor's default implementations to visit Stmt's and BinOp's spans
The Stmt
case is a bug introduced almost certainly unintentionally by rust-lang#126993. The code used to visit and mutate span
correctly, but got changed as follows by that PR. Notice how span
is copied into the output by |kind| Stmt { id, kind, span }
which happens after the mutation in the correct code (red) and before the mutation in the incorrect code (green).
pub fn noop_flat_map_stmt<T: MutVisitor>(
Stmt { kind, mut span, mut id }: Stmt,
vis: &mut T,
) -> SmallVec<[Stmt; 1]> {
vis.visit_id(&mut id);
- vis.visit_span(&mut span);
let stmts: SmallVec<_> = noop_flat_map_stmt_kind(kind, vis)
.into_iter()
.map(|kind| Stmt { id, kind, span })
.collect();
if stmts.len() > 1 {
panic!(...);
}
+ vis.visit_span(&mut span);
stmts
}