From 5486857448ad37a90ed1d75c87fac8adb9884894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Wed, 11 Dec 2024 13:57:34 +0000 Subject: [PATCH] use let else more consistently in fact generation also remove a useless trace --- .../src/polonius/legacy/accesses.rs | 40 ++++++-------- .../rustc_borrowck/src/polonius/legacy/mod.rs | 52 +++++++++---------- 2 files changed, 43 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_borrowck/src/polonius/legacy/accesses.rs b/compiler/rustc_borrowck/src/polonius/legacy/accesses.rs index 406fdba0f83d..4266aba9cc55 100644 --- a/compiler/rustc_borrowck/src/polonius/legacy/accesses.rs +++ b/compiler/rustc_borrowck/src/polonius/legacy/accesses.rs @@ -21,30 +21,24 @@ pub(crate) fn emit_access_facts<'tcx>( location_table: &LocationTable, all_facts: &mut Option, ) { - if let Some(facts) = all_facts.as_mut() { - debug!("emit_access_facts()"); + let Some(facts) = all_facts.as_mut() else { return }; + let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation"); + let mut extractor = AccessFactsExtractor { + var_defined_at: &mut facts.var_defined_at, + var_used_at: &mut facts.var_used_at, + var_dropped_at: &mut facts.var_dropped_at, + path_accessed_at_base: &mut facts.path_accessed_at_base, + location_table, + move_data, + }; + extractor.visit_body(body); - let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation"); - let mut extractor = AccessFactsExtractor { - var_defined_at: &mut facts.var_defined_at, - var_used_at: &mut facts.var_used_at, - var_dropped_at: &mut facts.var_dropped_at, - path_accessed_at_base: &mut facts.path_accessed_at_base, - location_table, - move_data, - }; - extractor.visit_body(body); - - for (local, local_decl) in body.local_decls.iter_enumerated() { - debug!( - "add use_of_var_derefs_origin facts - local={:?}, type={:?}", - local, local_decl.ty - ); - tcx.for_each_free_region(&local_decl.ty, |region| { - let region_vid = universal_regions.to_region_vid(region); - facts.use_of_var_derefs_origin.push((local, region_vid.into())); - }); - } + for (local, local_decl) in body.local_decls.iter_enumerated() { + debug!("add use_of_var_derefs_origin facts - local={:?}, type={:?}", local, local_decl.ty); + tcx.for_each_free_region(&local_decl.ty, |region| { + let region_vid = universal_regions.to_region_vid(region); + facts.use_of_var_derefs_origin.push((local, region_vid.into())); + }); } } diff --git a/compiler/rustc_borrowck/src/polonius/legacy/mod.rs b/compiler/rustc_borrowck/src/polonius/legacy/mod.rs index 4c98dfa7e3e3..15988fad57f6 100644 --- a/compiler/rustc_borrowck/src/polonius/legacy/mod.rs +++ b/compiler/rustc_borrowck/src/polonius/legacy/mod.rs @@ -39,8 +39,8 @@ pub(crate) fn emit_facts<'tcx>( location_table: &LocationTable, body: &Body<'tcx>, borrow_set: &BorrowSet<'tcx>, - move_data: &MoveData<'_>, - universal_region_relations: &UniversalRegionRelations<'_>, + move_data: &MoveData<'tcx>, + universal_region_relations: &UniversalRegionRelations<'tcx>, ) { let Some(all_facts) = all_facts else { // We don't do anything if there are no facts to fill. @@ -202,13 +202,12 @@ pub(crate) fn emit_drop_facts<'tcx>( all_facts: &mut Option, ) { debug!("emit_drop_facts(local={:?}, kind={:?}", local, kind); - if let Some(facts) = all_facts.as_mut() { - let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation"); - tcx.for_each_free_region(kind, |drop_live_region| { - let region_vid = universal_regions.to_region_vid(drop_live_region); - facts.drop_of_var_derefs_origin.push((local, region_vid.into())); - }); - } + let Some(facts) = all_facts.as_mut() else { return }; + let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation"); + tcx.for_each_free_region(kind, |drop_live_region| { + let region_vid = universal_regions.to_region_vid(drop_live_region); + facts.drop_of_var_derefs_origin.push((local, region_vid.into())); + }); } /// Emit facts about the outlives constraints: the `subset` base relation, i.e. not a transitive @@ -219,22 +218,23 @@ pub(crate) fn emit_outlives_facts<'tcx>( location_table: &LocationTable, all_facts: &mut Option, ) { - if let Some(facts) = all_facts { - let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation"); - facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map( - |constraint: &OutlivesConstraint<'_>| { - if let Some(from_location) = constraint.locations.from_location() { - Either::Left(iter::once(( - constraint.sup.into(), - constraint.sub.into(), - location_table.mid_index(from_location), - ))) - } else { - Either::Right(location_table.all_points().map(move |location| { + let Some(facts) = all_facts else { return }; + let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation"); + facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map( + |constraint: &OutlivesConstraint<'_>| { + if let Some(from_location) = constraint.locations.from_location() { + Either::Left(iter::once(( + constraint.sup.into(), + constraint.sub.into(), + location_table.mid_index(from_location), + ))) + } else { + Either::Right( + location_table.all_points().map(move |location| { (constraint.sup.into(), constraint.sub.into(), location) - })) - } - }, - )); - } + }), + ) + } + }, + )); }