Skip to content

Commit 5486857

Browse files
committed
use let else more consistently in fact generation
also remove a useless trace
1 parent afbe101 commit 5486857

File tree

2 files changed

+43
-49
lines changed

2 files changed

+43
-49
lines changed

compiler/rustc_borrowck/src/polonius/legacy/accesses.rs

+17-23
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,24 @@ pub(crate) fn emit_access_facts<'tcx>(
2121
location_table: &LocationTable,
2222
all_facts: &mut Option<AllFacts>,
2323
) {
24-
if let Some(facts) = all_facts.as_mut() {
25-
debug!("emit_access_facts()");
24+
let Some(facts) = all_facts.as_mut() else { return };
25+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
26+
let mut extractor = AccessFactsExtractor {
27+
var_defined_at: &mut facts.var_defined_at,
28+
var_used_at: &mut facts.var_used_at,
29+
var_dropped_at: &mut facts.var_dropped_at,
30+
path_accessed_at_base: &mut facts.path_accessed_at_base,
31+
location_table,
32+
move_data,
33+
};
34+
extractor.visit_body(body);
2635

27-
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
28-
let mut extractor = AccessFactsExtractor {
29-
var_defined_at: &mut facts.var_defined_at,
30-
var_used_at: &mut facts.var_used_at,
31-
var_dropped_at: &mut facts.var_dropped_at,
32-
path_accessed_at_base: &mut facts.path_accessed_at_base,
33-
location_table,
34-
move_data,
35-
};
36-
extractor.visit_body(body);
37-
38-
for (local, local_decl) in body.local_decls.iter_enumerated() {
39-
debug!(
40-
"add use_of_var_derefs_origin facts - local={:?}, type={:?}",
41-
local, local_decl.ty
42-
);
43-
tcx.for_each_free_region(&local_decl.ty, |region| {
44-
let region_vid = universal_regions.to_region_vid(region);
45-
facts.use_of_var_derefs_origin.push((local, region_vid.into()));
46-
});
47-
}
36+
for (local, local_decl) in body.local_decls.iter_enumerated() {
37+
debug!("add use_of_var_derefs_origin facts - local={:?}, type={:?}", local, local_decl.ty);
38+
tcx.for_each_free_region(&local_decl.ty, |region| {
39+
let region_vid = universal_regions.to_region_vid(region);
40+
facts.use_of_var_derefs_origin.push((local, region_vid.into()));
41+
});
4842
}
4943
}
5044

compiler/rustc_borrowck/src/polonius/legacy/mod.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ pub(crate) fn emit_facts<'tcx>(
3939
location_table: &LocationTable,
4040
body: &Body<'tcx>,
4141
borrow_set: &BorrowSet<'tcx>,
42-
move_data: &MoveData<'_>,
43-
universal_region_relations: &UniversalRegionRelations<'_>,
42+
move_data: &MoveData<'tcx>,
43+
universal_region_relations: &UniversalRegionRelations<'tcx>,
4444
) {
4545
let Some(all_facts) = all_facts else {
4646
// We don't do anything if there are no facts to fill.
@@ -202,13 +202,12 @@ pub(crate) fn emit_drop_facts<'tcx>(
202202
all_facts: &mut Option<AllFacts>,
203203
) {
204204
debug!("emit_drop_facts(local={:?}, kind={:?}", local, kind);
205-
if let Some(facts) = all_facts.as_mut() {
206-
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
207-
tcx.for_each_free_region(kind, |drop_live_region| {
208-
let region_vid = universal_regions.to_region_vid(drop_live_region);
209-
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));
210-
});
211-
}
205+
let Some(facts) = all_facts.as_mut() else { return };
206+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
207+
tcx.for_each_free_region(kind, |drop_live_region| {
208+
let region_vid = universal_regions.to_region_vid(drop_live_region);
209+
facts.drop_of_var_derefs_origin.push((local, region_vid.into()));
210+
});
212211
}
213212

214213
/// 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>(
219218
location_table: &LocationTable,
220219
all_facts: &mut Option<AllFacts>,
221220
) {
222-
if let Some(facts) = all_facts {
223-
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
224-
facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map(
225-
|constraint: &OutlivesConstraint<'_>| {
226-
if let Some(from_location) = constraint.locations.from_location() {
227-
Either::Left(iter::once((
228-
constraint.sup.into(),
229-
constraint.sub.into(),
230-
location_table.mid_index(from_location),
231-
)))
232-
} else {
233-
Either::Right(location_table.all_points().map(move |location| {
221+
let Some(facts) = all_facts else { return };
222+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
223+
facts.subset_base.extend(constraints.outlives_constraints.outlives().iter().flat_map(
224+
|constraint: &OutlivesConstraint<'_>| {
225+
if let Some(from_location) = constraint.locations.from_location() {
226+
Either::Left(iter::once((
227+
constraint.sup.into(),
228+
constraint.sub.into(),
229+
location_table.mid_index(from_location),
230+
)))
231+
} else {
232+
Either::Right(
233+
location_table.all_points().map(move |location| {
234234
(constraint.sup.into(), constraint.sub.into(), location)
235-
}))
236-
}
237-
},
238-
));
239-
}
235+
}),
236+
)
237+
}
238+
},
239+
));
240240
}

0 commit comments

Comments
 (0)