Skip to content

Commit 2fda456

Browse files
committed
extract region_value_str helper
1 parent f277b39 commit 2fda456

File tree

3 files changed

+73
-77
lines changed

3 files changed

+73
-77
lines changed

src/librustc_mir/borrow_check/nll/constraint_generation.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use borrow_check::borrow_set::BorrowSet;
1212
use borrow_check::location::LocationTable;
1313
use borrow_check::nll::ToRegionVid;
1414
use borrow_check::nll::facts::AllFacts;
15-
use borrow_check::nll::region_infer::values::{RegionValueElements, RegionValues};
15+
use borrow_check::nll::region_infer::values::RegionValues;
1616
use rustc::infer::InferCtxt;
1717
use rustc::mir::visit::TyContext;
1818
use rustc::mir::visit::Visitor;
@@ -24,7 +24,6 @@ use rustc::ty::{self, CanonicalTy, ClosureSubsts, GeneratorSubsts, RegionVid};
2424

2525
pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>(
2626
infcx: &InferCtxt<'cx, 'gcx, 'tcx>,
27-
elements: &RegionValueElements,
2827
liveness_constraints: &mut RegionValues<RegionVid>,
2928
all_facts: &mut Option<AllFacts>,
3029
location_table: &LocationTable,
@@ -37,7 +36,6 @@ pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>(
3736
liveness_constraints,
3837
location_table,
3938
all_facts,
40-
elements,
4139
};
4240

4341
for (bb, data) in mir.basic_blocks().iter_enumerated() {
@@ -52,7 +50,6 @@ struct ConstraintGeneration<'cg, 'cx: 'cg, 'gcx: 'tcx, 'tcx: 'cx> {
5250
location_table: &'cg LocationTable,
5351
liveness_constraints: &'cg mut RegionValues<RegionVid>,
5452
borrow_set: &'cg BorrowSet<'tcx>,
55-
elements: &'cg RegionValueElements,
5653
}
5754

5855
impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx, 'tcx> {
@@ -205,7 +202,7 @@ impl<'cx, 'cg, 'gcx, 'tcx> ConstraintGeneration<'cx, 'cg, 'gcx, 'tcx> {
205202
.tcx
206203
.for_each_free_region(&live_ty, |live_region| {
207204
let vid = live_region.to_region_vid();
208-
self.liveness_constraints.add_element(&self.elements, vid, location);
205+
self.liveness_constraints.add_element(vid, location);
209206
});
210207
}
211208
}

src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
143143

144144
constraint_generation::generate_constraints(
145145
infcx,
146-
&elements,
147146
&mut liveness_constraints,
148147
&mut all_facts,
149148
location_table,

src/librustc_mir/borrow_check/nll/region_infer/values.rs

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,7 @@ impl<N: Idx> RegionValues<N> {
192192

193193
/// True if `sup_region` contains all the CFG points that
194194
/// `sub_region` contains. Ignores universal regions.
195-
crate fn contains_points(
196-
&self,
197-
sup_region: N,
198-
sub_region: N,
199-
) -> bool {
195+
crate fn contains_points(&self, sup_region: N, sub_region: N) -> bool {
200196
// This could be done faster by comparing the bitsets. But I
201197
// am lazy.
202198
if let Some(sub_row) = self.points.row(sub_region) {
@@ -252,72 +248,7 @@ impl<N: Idx> RegionValues<N> {
252248

253249
/// Returns a "pretty" string value of the region. Meant for debugging.
254250
crate fn region_value_str(&self, r: N) -> String {
255-
let mut result = String::new();
256-
result.push_str("{");
257-
258-
// Set to Some(l1, l2) when we have observed all the locations
259-
// from l1..=l2 (inclusive) but not yet printed them. This
260-
// gets extended if we then see l3 where l3 is the successor
261-
// to l2.
262-
let mut open_location: Option<(Location, Location)> = None;
263-
264-
let mut sep = "";
265-
let mut push_sep = |s: &mut String| {
266-
s.push_str(sep);
267-
sep = ", ";
268-
};
269-
270-
for element in self.elements_contained_in(r) {
271-
match element {
272-
RegionElement::Location(l) => {
273-
if let Some((location1, location2)) = open_location {
274-
if location2.block == l.block
275-
&& location2.statement_index == l.statement_index - 1
276-
{
277-
open_location = Some((location1, l));
278-
continue;
279-
}
280-
281-
push_sep(&mut result);
282-
Self::push_location_range(&mut result, location1, location2);
283-
}
284-
285-
open_location = Some((l, l));
286-
}
287-
288-
RegionElement::RootUniversalRegion(fr) => {
289-
if let Some((location1, location2)) = open_location {
290-
push_sep(&mut result);
291-
Self::push_location_range(&mut result, location1, location2);
292-
open_location = None;
293-
}
294-
295-
push_sep(&mut result);
296-
result.push_str(&format!("{:?}", fr));
297-
}
298-
}
299-
}
300-
301-
if let Some((location1, location2)) = open_location {
302-
push_sep(&mut result);
303-
Self::push_location_range(&mut result, location1, location2);
304-
}
305-
306-
result.push_str("}");
307-
308-
result
309-
}
310-
311-
fn push_location_range(str: &mut String, location1: Location, location2: Location) {
312-
if location1 == location2 {
313-
str.push_str(&format!("{:?}", location1));
314-
} else {
315-
assert_eq!(location1.block, location2.block);
316-
str.push_str(&format!(
317-
"{:?}[{}..={}]",
318-
location1.block, location1.statement_index, location2.statement_index
319-
));
320-
}
251+
region_value_str(self.elements_contained_in(r))
321252
}
322253
}
323254

@@ -372,3 +303,72 @@ impl ToElementIndex for RegionVid {
372303
values.free_regions.contains(row, self)
373304
}
374305
}
306+
307+
crate fn region_value_str(elements: impl IntoIterator<Item = RegionElement>) -> String {
308+
let mut result = String::new();
309+
result.push_str("{");
310+
311+
// Set to Some(l1, l2) when we have observed all the locations
312+
// from l1..=l2 (inclusive) but not yet printed them. This
313+
// gets extended if we then see l3 where l3 is the successor
314+
// to l2.
315+
let mut open_location: Option<(Location, Location)> = None;
316+
317+
let mut sep = "";
318+
let mut push_sep = |s: &mut String| {
319+
s.push_str(sep);
320+
sep = ", ";
321+
};
322+
323+
for element in elements {
324+
match element {
325+
RegionElement::Location(l) => {
326+
if let Some((location1, location2)) = open_location {
327+
if location2.block == l.block
328+
&& location2.statement_index == l.statement_index - 1
329+
{
330+
open_location = Some((location1, l));
331+
continue;
332+
}
333+
334+
push_sep(&mut result);
335+
push_location_range(&mut result, location1, location2);
336+
}
337+
338+
open_location = Some((l, l));
339+
}
340+
341+
RegionElement::RootUniversalRegion(fr) => {
342+
if let Some((location1, location2)) = open_location {
343+
push_sep(&mut result);
344+
push_location_range(&mut result, location1, location2);
345+
open_location = None;
346+
}
347+
348+
push_sep(&mut result);
349+
result.push_str(&format!("{:?}", fr));
350+
}
351+
}
352+
}
353+
354+
if let Some((location1, location2)) = open_location {
355+
push_sep(&mut result);
356+
push_location_range(&mut result, location1, location2);
357+
}
358+
359+
result.push_str("}");
360+
361+
return result;
362+
363+
fn push_location_range(str: &mut String, location1: Location, location2: Location) {
364+
if location1 == location2 {
365+
str.push_str(&format!("{:?}", location1));
366+
} else {
367+
assert_eq!(location1.block, location2.block);
368+
str.push_str(&format!(
369+
"{:?}[{}..={}]",
370+
location1.block, location1.statement_index, location2.statement_index
371+
));
372+
}
373+
}
374+
}

0 commit comments

Comments
 (0)