Files
rust/compiler/rustc_mir_dataflow
bors 874e6f2a53 Auto merge of #160889 - nnethercote:simplify-MaybeBorrowedLocals, r=cjgillot
Simplify `MaybeBorrowedLocals`

It is implemented as a `Visitor`, but it only uses `visit_statement`, `visit_terminator`, and `visit_rvalue`. Visiting statements and terminators is trivial without a `Visitor`, and visiting rvalues is almost as easy because they can only appear at the top-level of a `StatementKind::Assign`. So a `Visitor` is overkill, because we don't have to worry about nesting (like we would with expressions, for example).

So this commit restructures `MaybeBorrowedLocals` to not use a `Visitor`, which makes the analysis shorter and simpler. `gen_statement` and `gen_terminator` are added to do most of the work, and are called from several places. They are similar to the equivalent `visit_*` methods but `gen_statement` doesn't do any kills. So how are kills for statements handled?

- In `Self::apply_primary_statement_effect` we now explicitly kill (on a `StorageDead` stmt) after calling `gen_statement`.

- `borrowed_locals` doesn't do kills; in fact it currently has its own custom `GenKill` to avoid killing anything. So `gen_{statement,terminator}` are enough for it.

- `MaybeRequiresStorage::apply_early_statement_effect` already has an explicit kill. (I.e. it killed each local a second time, after calling the transfer function.)

r? @cjgillot
2026-08-16 10:34:57 +00:00
..