Skip to content

Commit ea0224f

Browse files
committed
error_report: rustfmt
1 parent 739320a commit ea0224f

File tree

1 file changed

+72
-35
lines changed

1 file changed

+72
-35
lines changed

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

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::fmt;
12-
use borrow_check::nll::region_infer::{ConstraintIndex, RegionInferenceContext};
1311
use borrow_check::nll::region_infer::values::ToElementIndex;
12+
use borrow_check::nll::region_infer::{Cause, ConstraintIndex, RegionInferenceContext};
13+
use borrow_check::nll::region_infer::{ConstraintIndex, RegionInferenceContext};
1414
use borrow_check::nll::type_check::Locations;
1515
use rustc::hir::def_id::DefId;
16-
use rustc::infer::InferCtxt;
1716
use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
18-
use rustc::mir::{self, Location, Mir, Place, StatementKind, TerminatorKind, Rvalue};
17+
use rustc::infer::InferCtxt;
18+
use rustc::mir::{self, Location, Mir, Place, Rvalue, StatementKind, TerminatorKind};
1919
use rustc::ty::RegionVid;
2020
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2121
use rustc_data_structures::indexed_vec::IndexVec;
22+
use std::fmt;
2223
use syntax_pos::Span;
2324

2425
/// Constraints that are considered interesting can be categorized to
@@ -50,16 +51,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5051
/// When reporting an error, it is useful to be able to determine which constraints influenced
5152
/// the region being reported as an error. This function finds all of the paths from the
5253
/// constraint.
53-
fn find_constraint_paths_from_region(
54-
&self,
55-
r0: RegionVid
56-
) -> Vec<Vec<ConstraintIndex>> {
54+
fn find_constraint_paths_from_region(&self, r0: RegionVid) -> Vec<Vec<ConstraintIndex>> {
5755
let constraints = self.constraints.clone();
5856

5957
// Mapping of regions to the previous region and constraint index that led to it.
6058
let mut previous = FxHashMap();
6159
// Regions yet to be visited.
62-
let mut next = vec! [ r0 ];
60+
let mut next = vec![r0];
6361
// Regions that have been visited.
6462
let mut visited = FxHashSet();
6563
// Ends of paths.
@@ -68,8 +66,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6866
// When we've still got points to visit...
6967
while let Some(current) = next.pop() {
7068
// ...take the next point...
71-
debug!("find_constraint_paths_from_region: current={:?} visited={:?} next={:?}",
72-
current, visited, next);
69+
debug!(
70+
"find_constraint_paths_from_region: current={:?} visited={:?} next={:?}",
71+
current, visited, next
72+
);
7373
// ...but make sure not to visit this point again...
7474
visited.insert(current);
7575

@@ -78,8 +78,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7878
for (index, constraint) in constraints.iter_enumerated() {
7979
if constraint.sub == current {
8080
// ...add the regions that join us with to the path we've taken...
81-
debug!("find_constraint_paths_from_region: index={:?} constraint={:?}",
82-
index, constraint);
81+
debug!(
82+
"find_constraint_paths_from_region: index={:?} constraint={:?}",
83+
index, constraint
84+
);
8385
let next_region = constraint.sup.clone();
8486

8587
// ...unless we've visited it since this was added...
@@ -95,27 +97,41 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9597

9698
if upcoming.is_empty() {
9799
// If we didn't find any edges then this is the end of a path...
98-
debug!("find_constraint_paths_from_region: new end region current={:?}", current);
100+
debug!(
101+
"find_constraint_paths_from_region: new end region current={:?}",
102+
current
103+
);
99104
end_regions.insert(current);
100105
} else {
101106
// ...but, if we did find edges, then add these to the regions yet to visit.
102-
debug!("find_constraint_paths_from_region: extend next upcoming={:?}", upcoming);
107+
debug!(
108+
"find_constraint_paths_from_region: extend next upcoming={:?}",
109+
upcoming
110+
);
103111
next.extend(upcoming);
104112
}
105-
106113
}
107114

108115
// Now we've visited each point, compute the final paths.
109116
let mut paths: Vec<Vec<ConstraintIndex>> = Vec::new();
110-
debug!("find_constraint_paths_from_region: end_regions={:?}", end_regions);
117+
debug!(
118+
"find_constraint_paths_from_region: end_regions={:?}",
119+
end_regions
120+
);
111121
for end_region in end_regions {
112-
debug!("find_constraint_paths_from_region: end_region={:?}", end_region);
122+
debug!(
123+
"find_constraint_paths_from_region: end_region={:?}",
124+
end_region
125+
);
113126

114127
// Get the constraint and region that led to this end point.
115128
// We can unwrap as we know if end_point was in the vector that it
116129
// must also be in our previous map.
117130
let (mut index, mut region) = previous.get(&end_region).unwrap();
118-
debug!("find_constraint_paths_from_region: index={:?} region={:?}", index, region);
131+
debug!(
132+
"find_constraint_paths_from_region: index={:?} region={:?}",
133+
index, region
134+
);
119135

120136
// Keep track of the indices.
121137
let mut path: Vec<ConstraintIndex> = vec![index];
@@ -125,7 +141,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
125141
index = p.0;
126142
region = p.1;
127143

128-
debug!("find_constraint_paths_from_region: index={:?} region={:?}", index, region);
144+
debug!(
145+
"find_constraint_paths_from_region: index={:?} region={:?}",
146+
index, region
147+
);
129148
path.push(index);
130149
}
131150

@@ -140,16 +159,28 @@ impl<'tcx> RegionInferenceContext<'tcx> {
140159
/// This function will return true if a constraint is interesting and false if a constraint
141160
/// is not. It is useful in filtering constraint paths to only interesting points.
142161
fn constraint_is_interesting(&self, index: &ConstraintIndex) -> bool {
143-
self.constraints.get(*index).filter(|constraint| {
144-
debug!("constraint_is_interesting: locations={:?} constraint={:?}",
145-
constraint.locations, constraint);
146-
if let Locations::Interesting(_) = constraint.locations { true } else { false }
147-
}).is_some()
162+
self.constraints
163+
.get(*index)
164+
.filter(|constraint| {
165+
debug!(
166+
"constraint_is_interesting: locations={:?} constraint={:?}",
167+
constraint.locations, constraint
168+
);
169+
if let Locations::Interesting(_) = constraint.locations {
170+
true
171+
} else {
172+
false
173+
}
174+
})
175+
.is_some()
148176
}
149177

150178
/// This function classifies a constraint from a location.
151-
fn classify_constraint(&self, index: &ConstraintIndex,
152-
mir: &Mir<'tcx>) -> Option<(ConstraintCategory, Span)> {
179+
fn classify_constraint(
180+
&self,
181+
index: &ConstraintIndex,
182+
mir: &Mir<'tcx>,
183+
) -> Option<(ConstraintCategory, Span)> {
153184
let constraint = self.constraints.get(*index)?;
154185
let span = constraint.locations.span(mir);
155186
let location = constraint.locations.from_location()?;
@@ -182,7 +213,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
182213
_ => ConstraintCategory::Other,
183214
}
184215
}
185-
},
216+
}
186217
_ => ConstraintCategory::Other,
187218
}
188219
};
@@ -234,18 +265,21 @@ impl<'tcx> RegionInferenceContext<'tcx> {
234265
let path = constraints.iter().min_by_key(|p| p.len()).unwrap();
235266
debug!("report_error: shortest_path={:?}", path);
236267

237-
let mut categorized_path = path.iter().filter_map(|index| {
238-
self.classify_constraint(index, mir)
239-
}).collect::<Vec<(ConstraintCategory, Span)>>();
268+
let mut categorized_path = path.iter()
269+
.filter_map(|index| self.classify_constraint(index, mir))
270+
.collect::<Vec<(ConstraintCategory, Span)>>();
240271
debug!("report_error: categorized_path={:?}", categorized_path);
241272

242273
categorized_path.sort_by(|p0, p1| p0.0.cmp(&p1.0));
243274
debug!("report_error: sorted_path={:?}", categorized_path);
244275

245276
if let Some((category, span)) = &categorized_path.first() {
246277
let mut diag = infcx.tcx.sess.struct_span_err(
247-
*span, &format!("{} requires that data must outlive {}",
248-
category, outlived_fr_string),
278+
*span,
279+
&format!(
280+
"{} requires that data must outlive {}",
281+
category, outlived_fr_string
282+
),
249283
);
250284

251285
diag.emit();
@@ -269,8 +303,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
269303

270304
/// Tries to finds a good span to blame for the fact that `fr1`
271305
/// contains `fr2`.
272-
pub(super) fn blame_constraint(&self, fr1: RegionVid,
273-
elem: impl ToElementIndex) -> ConstraintIndex {
306+
pub(super) fn blame_constraint(
307+
&self,
308+
fr1: RegionVid,
309+
elem: impl ToElementIndex,
310+
) -> ConstraintIndex {
274311
// Find everything that influenced final value of `fr`.
275312
let influenced_fr1 = self.dependencies(fr1);
276313

0 commit comments

Comments
 (0)