Skip to content

Commit bd0cde9

Browse files
committed
also consider HR bounds
1 parent 0defdc0 commit bd0cde9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
218218
diag: &mut Diag<'_>,
219219
lower_bound: RegionVid,
220220
) {
221-
let mut suggestions = vec![];
222221
let tcx = self.infcx.tcx;
223222

224223
// find generic associated types in the given region 'lower_bound'
@@ -242,7 +241,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
242241

243242
// find higher-ranked trait bounds bounded to the generic associated types
244243
let mut hrtb_bounds = vec![];
245-
gat_id_and_generics.iter().flatten().for_each(|(gat_hir_id, generics)| {
244+
gat_id_and_generics.iter().flatten().for_each(|&(gat_hir_id, generics)| {
246245
for pred in generics.predicates {
247246
let BoundPredicate(WhereBoundPredicate { bound_generic_params, bounds, .. }) =
248247
pred.kind
@@ -251,17 +250,32 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
251250
};
252251
if bound_generic_params
253252
.iter()
254-
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id)
253+
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
255254
.is_some()
256255
{
257256
for bound in *bounds {
258257
hrtb_bounds.push(bound);
259258
}
259+
} else {
260+
for bound in *bounds {
261+
if let Trait(trait_bound) = bound {
262+
if trait_bound
263+
.bound_generic_params
264+
.iter()
265+
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
266+
.is_some()
267+
{
268+
hrtb_bounds.push(bound);
269+
return;
270+
}
271+
}
272+
}
260273
}
261274
}
262275
});
263276
debug!(?hrtb_bounds);
264277

278+
let mut suggestions = vec![];
265279
hrtb_bounds.iter().for_each(|bound| {
266280
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }) = bound else {
267281
return;

tests/ui/generic-associated-types/extended/lending_iterator.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ error: `Self` does not live long enough
1212
|
1313
LL | <B as FromLendingIterator<A>>::from_iter(self)
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
17+
--> $DIR/lending_iterator.rs:4:21
18+
|
19+
LL | fn from_iter<T: for<'x> LendingIterator<Item<'x> = A>>(iter: T) -> Self;
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1521

1622
error: aborting due to 2 previous errors
1723

0 commit comments

Comments
 (0)