Skip to content

Commit b692518

Browse files
olwangclaude
andcommitted
refactor(checks): extract field move-use helper in local.rs (behavior-preserving)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1a7292c commit b692518

1 file changed

Lines changed: 25 additions & 13 deletions

File tree

crates/rsscript/src/checks/local.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -854,19 +854,7 @@ fn collect_ordered_moved_uses_from_expr(
854854
collect_ordered_moved_uses_from_expr(right, state, moved_uses);
855855
}
856856
HirExpr::Field { base, .. } => {
857-
if let Some((path, span)) = hir_expr_path(expr) {
858-
if let Some(root) = path_root(&path)
859-
&& let Some(move_span) = state.move_span(root)
860-
{
861-
push_moved_use(moved_uses, root.to_string(), span, move_span.clone());
862-
return;
863-
}
864-
if let Some((moved_path, move_span)) = state.moved_path_span(&path) {
865-
push_moved_use(moved_uses, moved_path, span, move_span.clone());
866-
}
867-
} else {
868-
collect_ordered_moved_uses_from_expr(base, state, moved_uses);
869-
}
857+
collect_field_move_use(expr, base, state, moved_uses);
870858
}
871859
HirExpr::Index { base, index, .. } => {
872860
collect_ordered_moved_uses_from_expr(base, state, moved_uses);
@@ -925,6 +913,30 @@ fn collect_ordered_moved_uses_from_expr(
925913
}
926914
}
927915

916+
/// Handle the `HirExpr::Field` branch of move-use collection: resolve the field
917+
/// access to a path, recording a moved-use against the moved root or the moved
918+
/// path, falling back to recursing into the base when no path resolves.
919+
fn collect_field_move_use(
920+
expr: &HirExpr,
921+
base: &HirExpr,
922+
state: &mut BodyState,
923+
moved_uses: &mut Vec<MovedUse>,
924+
) {
925+
if let Some((path, span)) = hir_expr_path(expr) {
926+
if let Some(root) = path_root(&path)
927+
&& let Some(move_span) = state.move_span(root)
928+
{
929+
push_moved_use(moved_uses, root.to_string(), span, move_span.clone());
930+
return;
931+
}
932+
if let Some((moved_path, move_span)) = state.moved_path_span(&path) {
933+
push_moved_use(moved_uses, moved_path, span, move_span.clone());
934+
}
935+
} else {
936+
collect_ordered_moved_uses_from_expr(base, state, moved_uses);
937+
}
938+
}
939+
928940
/// Walk a block with a *threaded* move state (rather than the precomputed
929941
/// per-statement flow map). Used for match-*expression* arm bodies, which the CFG
930942
/// flow analysis does not weave in. It catches straight-line use-after-move within

0 commit comments

Comments
 (0)