Skip to content

Commit 8b15302

Browse files
committed
Replace a find with a loop to simplify the logic.
1 parent 562d846 commit 8b15302

File tree

1 file changed

+22
-19
lines changed
  • compiler/rustc_borrowck/src/region_infer

1 file changed

+22
-19
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,26 +1647,29 @@ impl<'tcx> RegionInferenceContext<'tcx> {
16471647
let longer_fr_scc = self.constraint_sccs.scc(longer_fr);
16481648
debug!("check_bound_universal_region: longer_fr_scc={:?}", longer_fr_scc,);
16491649

1650-
// If we have some bound universal region `'a`, then the only
1651-
// elements it can contain is itself -- we don't know anything
1652-
// else about it!
1653-
let Some(error_element) = ({
1654-
self.scc_values.elements_contained_in(longer_fr_scc).find(|element| match element {
1655-
RegionElement::Location(_) => true,
1656-
RegionElement::RootUniversalRegion(_) => true,
1657-
RegionElement::PlaceholderRegion(placeholder1) => placeholder != *placeholder1,
1658-
})
1659-
}) else {
1660-
return;
1661-
};
1662-
debug!("check_bound_universal_region: error_element = {:?}", error_element);
1650+
for error_element in self.scc_values.elements_contained_in(longer_fr_scc) {
1651+
match error_element {
1652+
RegionElement::Location(_) | RegionElement::RootUniversalRegion(_) => {}
1653+
// If we have some bound universal region `'a`, then the only
1654+
// elements it can contain is itself -- we don't know anything
1655+
// else about it!
1656+
RegionElement::PlaceholderRegion(placeholder1) => {
1657+
if placeholder == placeholder1 {
1658+
continue;
1659+
}
1660+
}
1661+
}
16631662

1664-
// Find the region that introduced this `error_element`.
1665-
errors_buffer.push(RegionErrorKind::BoundUniversalRegionError {
1666-
longer_fr,
1667-
error_element,
1668-
placeholder,
1669-
});
1663+
errors_buffer.push(RegionErrorKind::BoundUniversalRegionError {
1664+
longer_fr,
1665+
error_element,
1666+
placeholder,
1667+
});
1668+
1669+
// Stop after the first error, it gets too noisy otherwise, and does not provide more information.
1670+
break;
1671+
}
1672+
debug!("check_bound_universal_region: all bounds satisfied");
16701673
}
16711674

16721675
#[instrument(level = "debug", skip(self, infcx, errors_buffer))]

0 commit comments

Comments
 (0)