Skip to content

Commit 5e9fc00

Browse files
committed
WIP
1 parent fbea9f0 commit 5e9fc00

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -240,49 +240,39 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
240240
&self,
241241
diag: &mut Diag<'_>,
242242
lower_bound: RegionVid,
243-
) {
243+
) -> Option<()> {
244244
let mut suggestions = vec![];
245245
let tcx = self.infcx.tcx;
246246

247-
// find generic associated types in the given region 'lower_bound'
248-
let gat_id_and_generics = self
249-
.regioncx
250-
.placeholders_contained_in(lower_bound)
251-
.map(|placeholder| {
252-
if let Some(id) = placeholder.bound.kind.get_id()
253-
&& let Some(placeholder_id) = id.as_local()
254-
&& let gat_hir_id = tcx.local_def_id_to_hir_id(placeholder_id)
255-
&& let Some(generics_impl) =
256-
tcx.parent_hir_node(tcx.parent_hir_id(gat_hir_id)).generics()
257-
{
258-
Some((gat_hir_id, generics_impl))
259-
} else {
260-
None
261-
}
262-
})
263-
.collect::<Vec<_>>();
264-
debug!(?gat_id_and_generics);
265-
266247
// find higher-ranked trait bounds bounded to the generic associated types
248+
let scc = self.regioncx.constraint_sccs().scc(lower_bound);
249+
250+
let placeholder: ty::PlaceholderRegion = self.regioncx.placeholder_representative(scc)?;
251+
252+
let placeholder_id = placeholder.bound.kind.get_id()?.as_local()?;
253+
let gat_hir_id = self.infcx.tcx.local_def_id_to_hir_id(placeholder_id);
254+
let generics_impl =
255+
self.infcx.tcx.parent_hir_node(self.infcx.tcx.parent_hir_id(gat_hir_id)).generics()?;
256+
267257
let mut hrtb_bounds = vec![];
268-
gat_id_and_generics.iter().flatten().for_each(|(gat_hir_id, generics)| {
269-
for pred in generics.predicates {
270-
let BoundPredicate(WhereBoundPredicate { bound_generic_params, bounds, .. }) =
271-
pred.kind
272-
else {
273-
continue;
274-
};
275-
if bound_generic_params
276-
.iter()
277-
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id)
278-
.is_some()
279-
{
280-
for bound in *bounds {
281-
hrtb_bounds.push(bound);
282-
}
258+
259+
for pred in generics_impl.predicates {
260+
let BoundPredicate(WhereBoundPredicate { bound_generic_params, bounds, .. }) =
261+
pred.kind
262+
else {
263+
continue;
264+
};
265+
if bound_generic_params
266+
.iter()
267+
.rfind(|bgp| self.infcx.tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
268+
.is_some()
269+
{
270+
for bound in *bounds {
271+
hrtb_bounds.push(bound);
283272
}
284273
}
285-
});
274+
}
275+
286276
debug!(?hrtb_bounds);
287277

288278
hrtb_bounds.iter().for_each(|bound| {
@@ -327,6 +317,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
327317
Applicability::MaybeIncorrect,
328318
);
329319
}
320+
Some(())
330321
}
331322

332323
/// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`.

0 commit comments

Comments
 (0)