Skip to content

Commit

Permalink
Fix bug in referent_used_exactly_once
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Oct 12, 2022
1 parent b8a9a50 commit 524ec2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions clippy_utils/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 524ec2e

Please sign in to comment.