Fix bug in `referent_used_exactly_once`

This commit is contained in:
Samuel Moelius 2022-10-11 19:41:44 -04:00
parent b8a9a507bf
commit 524ec2e125
2 changed files with 5 additions and 6 deletions

View File

@ -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);

View File

@ -121,8 +121,7 @@ pub fn expr_local(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> Option<Local> {
})
}
/// 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<Location> {
let mut locations = Vec::new();
for (block, data) in mir.basic_blocks.iter_enumerated() {