Skip to content

Commit 524ec2e

Browse files
committed
Fix bug in referent_used_exactly_once
1 parent b8a9a50 commit 524ec2e

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

clippy_lints/src/dereference.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1194,16 +1194,16 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
11941194
})
11951195
}
11961196

1197-
fn referent_used_exactly_once<'a, 'tcx>(
1198-
cx: &'a LateContext<'tcx>,
1197+
fn referent_used_exactly_once<'tcx>(
1198+
cx: &LateContext<'tcx>,
11991199
possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
12001200
reference: &Expr<'tcx>,
12011201
) -> bool {
12021202
let mir = enclosing_mir(cx.tcx, reference.hir_id);
12031203
if let Some(local) = expr_local(cx.tcx, reference)
12041204
&& let [location] = *local_assignments(mir, local).as_slice()
1205-
&& let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) =
1206-
mir.basic_blocks[location.block].statements[location.statement_index].kind
1205+
&& let Some(statement) = mir.basic_blocks[location.block].statements.get(location.statement_index)
1206+
&& let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind
12071207
&& !place.has_deref()
12081208
{
12091209
let body_owner_local_def_id = cx.tcx.hir().enclosing_body_owner(reference.hir_id);

clippy_utils/src/mir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ pub fn expr_local(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> Option<Local> {
121121
})
122122
}
123123

124-
/// Returns a vector of `mir::Location` where `local` is assigned. Each statement referred to has
125-
/// kind `StatementKind::Assign`.
124+
/// Returns a vector of `mir::Location` where `local` is assigned.
126125
pub fn local_assignments(mir: &Body<'_>, local: Local) -> Vec<Location> {
127126
let mut locations = Vec::new();
128127
for (block, data) in mir.basic_blocks.iter_enumerated() {

0 commit comments

Comments
 (0)