use let chains in hir, lint, mir

This commit is contained in:
Kivooeo
2025-07-26 06:21:54 +05:00
parent 43725ed819
commit bae38bad78
24 changed files with 278 additions and 307 deletions

View File

@@ -124,10 +124,9 @@ pub fn drop_flag_effects_for_location<'tcx, F>(
// Drop does not count as a move but we should still consider the variable uninitialized.
if let Some(Terminator { kind: TerminatorKind::Drop { place, .. }, .. }) =
body.stmt_at(loc).right()
&& let LookupResult::Exact(mpi) = move_data.rev_lookup.find(place.as_ref())
{
if let LookupResult::Exact(mpi) = move_data.rev_lookup.find(place.as_ref()) {
on_all_children_bits(move_data, mpi, |mpi| callback(mpi, DropFlagState::Absent))
}
on_all_children_bits(move_data, mpi, |mpi| callback(mpi, DropFlagState::Absent))
}
debug!("drop_flag_effects: assignment for location({:?})", loc);

View File

@@ -637,16 +637,13 @@ impl<'tcx> Analysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
debug!("initializes move_indexes {:?}", init_loc_map[location]);
state.gen_all(init_loc_map[location].iter().copied());
if let mir::StatementKind::StorageDead(local) = stmt.kind {
if let mir::StatementKind::StorageDead(local) = stmt.kind
// End inits for StorageDead, so that an immutable variable can
// be reinitialized on the next iteration of the loop.
if let Some(move_path_index) = rev_lookup.find_local(local) {
debug!(
"clears the ever initialized status of {:?}",
init_path_map[move_path_index]
);
state.kill_all(init_path_map[move_path_index].iter().copied());
}
&& let Some(move_path_index) = rev_lookup.find_local(local)
{
debug!("clears the ever initialized status of {:?}", init_path_map[move_path_index]);
state.kill_all(init_path_map[move_path_index].iter().copied());
}
}

View File

@@ -135,12 +135,11 @@ fn value_assigned_to_local<'a, 'tcx>(
stmt: &'a mir::Statement<'tcx>,
local: Local,
) -> Option<&'a mir::Rvalue<'tcx>> {
if let mir::StatementKind::Assign(box (place, rvalue)) = &stmt.kind {
if let Some(l) = place.as_local() {
if local == l {
return Some(&*rvalue);
}
}
if let mir::StatementKind::Assign(box (place, rvalue)) = &stmt.kind
&& let Some(l) = place.as_local()
&& local == l
{
return Some(&*rvalue);
}
None
@@ -178,31 +177,30 @@ impl PeekCall {
let span = terminator.source_info.span;
if let mir::TerminatorKind::Call { func: Operand::Constant(func), args, .. } =
&terminator.kind
&& let ty::FnDef(def_id, fn_args) = *func.const_.ty().kind()
{
if let ty::FnDef(def_id, fn_args) = *func.const_.ty().kind() {
if tcx.intrinsic(def_id)?.name != sym::rustc_peek {
return None;
}
if tcx.intrinsic(def_id)?.name != sym::rustc_peek {
return None;
}
assert_eq!(fn_args.len(), 1);
let kind = PeekCallKind::from_arg_ty(fn_args.type_at(0));
let arg = match &args[0].node {
Operand::Copy(place) | Operand::Move(place) => {
if let Some(local) = place.as_local() {
local
} else {
tcx.dcx().emit_err(PeekMustBeNotTemporary { span });
return None;
}
}
_ => {
assert_eq!(fn_args.len(), 1);
let kind = PeekCallKind::from_arg_ty(fn_args.type_at(0));
let arg = match &args[0].node {
Operand::Copy(place) | Operand::Move(place) => {
if let Some(local) = place.as_local() {
local
} else {
tcx.dcx().emit_err(PeekMustBeNotTemporary { span });
return None;
}
};
}
_ => {
tcx.dcx().emit_err(PeekMustBeNotTemporary { span });
return None;
}
};
return Some(PeekCall { arg, kind, span });
}
return Some(PeekCall { arg, kind, span });
}
None

View File

@@ -215,10 +215,10 @@ impl<V: Clone + HasBottom> State<V> {
// If both places are tracked, we copy the value to the target.
// If the target is tracked, but the source is not, we do nothing, as invalidation has
// already been performed.
if let Some(target_value) = map.places[target].value_index {
if let Some(source_value) = map.places[source].value_index {
values.insert(target_value, values.get(source_value).clone());
}
if let Some(target_value) = map.places[target].value_index
&& let Some(source_value) = map.places[source].value_index
{
values.insert(target_value, values.get(source_value).clone());
}
for target_child in map.children(target) {
// Try to find corresponding child and recurse. Reasoning is similar as above.