From 524ec2e12577d652875c68c3f205e8530451ba48 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Tue, 11 Oct 2022 19:41:44 -0400 Subject: [PATCH] Fix bug in `referent_used_exactly_once` --- clippy_lints/src/dereference.rs | 8 ++++---- clippy_utils/src/mir/mod.rs | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs index 45ee2fce4e4..82fc41d3a82 100644 --- a/clippy_lints/src/dereference.rs +++ b/clippy_lints/src/dereference.rs @@ -1194,16 +1194,16 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool { }) } -fn referent_used_exactly_once<'a, 'tcx>( - cx: &'a LateContext<'tcx>, +fn referent_used_exactly_once<'tcx>( + cx: &LateContext<'tcx>, possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>, reference: &Expr<'tcx>, ) -> bool { let mir = enclosing_mir(cx.tcx, reference.hir_id); if let Some(local) = expr_local(cx.tcx, reference) && let [location] = *local_assignments(mir, local).as_slice() - && let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = - mir.basic_blocks[location.block].statements[location.statement_index].kind + && let Some(statement) = mir.basic_blocks[location.block].statements.get(location.statement_index) + && let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind && !place.has_deref() { let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id); diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs index c8aa6f3e595..818e603f665 100644 --- a/clippy_utils/src/mir/mod.rs +++ b/clippy_utils/src/mir/mod.rs @@ -121,8 +121,7 @@ pub fn expr_local(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> Option { }) } -/// Returns a vector of `mir::Location` where `local` is assigned. Each statement referred to has -/// kind `StatementKind::Assign`. +/// Returns a vector of `mir::Location` where `local` is assigned. pub fn local_assignments(mir: &Body<'_>, local: Local) -> Vec { let mut locations = Vec::new(); for (block, data) in mir.basic_blocks.iter_enumerated() {