Skip to content

Commit d62e857

Browse files
committed
also consider HR bounds
1 parent 4e2d420 commit d62e857

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
@@ -215,7 +215,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
215215
diag: &mut Diag<'_>,
216216
lower_bound: RegionVid,
217217
) {
218-
let mut suggestions = vec![];
219218
let tcx = self.infcx.tcx;
220219

221220
// find generic associated types in the given region 'lower_bound'
@@ -239,7 +238,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
239238

240239
// find higher-ranked trait bounds bounded to the generic associated types
241240
let mut hrtb_bounds = vec![];
242-
gat_id_and_generics.iter().flatten().for_each(|(gat_hir_id, generics)| {
241+
gat_id_and_generics.iter().flatten().for_each(|&(gat_hir_id, generics)| {
243242
for pred in generics.predicates {
244243
let BoundPredicate(WhereBoundPredicate { bound_generic_params, bounds, .. }) =
245244
pred.kind
@@ -248,17 +247,32 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
248247
};
249248
if bound_generic_params
250249
.iter()
251-
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == *gat_hir_id)
250+
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
252251
.is_some()
253252
{
254253
for bound in *bounds {
255254
hrtb_bounds.push(bound);
256255
}
256+
} else {
257+
for bound in *bounds {
258+
if let Trait(trait_bound) = bound {
259+
if trait_bound
260+
.bound_generic_params
261+
.iter()
262+
.rfind(|bgp| tcx.local_def_id_to_hir_id(bgp.def_id) == gat_hir_id)
263+
.is_some()
264+
{
265+
hrtb_bounds.push(bound);
266+
return;
267+
}
268+
}
269+
}
257270
}
258271
}
259272
});
260273
debug!(?hrtb_bounds);
261274

275+
let mut suggestions = vec![];
262276
hrtb_bounds.iter().for_each(|bound| {
263277
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }) = bound else {
264278
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)