Skip to content

Commit 15aad83

Browse files
committed
Fix infinite loops when regions are self-referential.
1 parent f334a9e commit 15aad83

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6363
// Regions that have been visited.
6464
let mut visited = FxHashSet();
6565
// Ends of paths.
66-
let mut end_regions: Vec<RegionVid> = Vec::new();
66+
let mut end_regions = FxHashSet();
6767

6868
// When we've still got points to visit...
6969
while let Some(current) = next.pop() {
7070
// ...take the next point...
71-
debug!("find_constraint_paths_from_region: current={:?} next={:?}", current, next);
71+
debug!("find_constraint_paths_from_region: current={:?} visited={:?} next={:?}",
72+
current, visited, next);
73+
// ...but make sure not to visit this point again...
74+
visited.insert(current);
7275

7376
// ...find the edges containing it...
7477
let mut upcoming = Vec::new();
@@ -93,16 +96,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9396
if upcoming.is_empty() {
9497
// If we didn't find any edges then this is the end of a path...
9598
debug!("find_constraint_paths_from_region: new end region current={:?}", current);
96-
end_regions.push(current);
99+
end_regions.insert(current);
97100
} else {
98-
// ...but, if we did find edges, then add these to the regions yet to visit...
101+
// ...but, if we did find edges, then add these to the regions yet to visit.
99102
debug!("find_constraint_paths_from_region: extend next upcoming={:?}", upcoming);
100103
next.extend(upcoming);
101104
}
102105

103-
// ...and don't visit it again.
104-
visited.insert(current.clone());
105-
debug!("find_constraint_paths_from_region: next={:?} visited={:?}", next, visited);
106106
}
107107

108108
// Now we've visited each point, compute the final paths.

0 commit comments

Comments
 (0)