Skip to content

Commit 67d1755

Browse files
authored
Rollup merge of #91308 - BGR360:issue-88586, r=jackh726
Fix ICE when lowering `trait A where for<'a> Self: 'a` Fixes #88586. r? `@jackh726` Jack, this fix is much smaller in scope than what I think you were proposing in the issue. Let me know if you had a vision for a larger refactor here. cc `@JohnTitor`
2 parents 233c50e + 6df2c78 commit 67d1755

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

compiler/rustc_typeck/src/collect.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl ItemCtxt<'tcx> {
666666
Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name),
667667
None => true,
668668
})
669-
.flat_map(|b| predicates_from_bound(self, ty, b));
669+
.flat_map(|b| predicates_from_bound(self, ty, b, ty::List::empty()));
670670

671671
let param_def_id = self.tcx.hir().local_def_id(param_id).to_def_id();
672672
let from_where_clauses = ast_generics
@@ -685,15 +685,17 @@ impl ItemCtxt<'tcx> {
685685
} else {
686686
None
687687
};
688+
let bvars = self.tcx.late_bound_vars(bp.bounded_ty.hir_id);
689+
688690
bp.bounds
689691
.iter()
690692
.filter(|b| match assoc_name {
691693
Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name),
692694
None => true,
693695
})
694-
.filter_map(move |b| bt.map(|bt| (bt, b)))
696+
.filter_map(move |b| bt.map(|bt| (bt, b, bvars)))
695697
})
696-
.flat_map(|(bt, b)| predicates_from_bound(self, bt, b));
698+
.flat_map(|(bt, b, bvars)| predicates_from_bound(self, bt, b, bvars));
697699

698700
from_ty_params.chain(from_where_clauses).collect()
699701
}
@@ -2433,14 +2435,10 @@ fn predicates_from_bound<'tcx>(
24332435
astconv: &dyn AstConv<'tcx>,
24342436
param_ty: Ty<'tcx>,
24352437
bound: &'tcx hir::GenericBound<'tcx>,
2438+
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
24362439
) -> Vec<(ty::Predicate<'tcx>, Span)> {
24372440
let mut bounds = Bounds::default();
2438-
astconv.add_bounds(
2439-
param_ty,
2440-
std::array::IntoIter::new([bound]),
2441-
&mut bounds,
2442-
ty::List::empty(),
2443-
);
2441+
astconv.add_bounds(param_ty, [bound].into_iter(), &mut bounds, bound_vars);
24442442
bounds.predicates(astconv.tcx(), param_ty)
24452443
}
24462444

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Regression test for #88586: a higher-ranked outlives bound on Self in a trait
2+
// definition caused an ICE when debug_assertions were enabled.
3+
//
4+
// FIXME: The error output in the absence of the ICE is unhelpful; this should be improved.
5+
6+
trait A where for<'a> Self: 'a
7+
//~^ ERROR the parameter type `Self` may not live long enough
8+
{
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0311]: the parameter type `Self` may not live long enough
2+
--> $DIR/issue-88586-hr-self-outlives-in-trait-def.rs:6:1
3+
|
4+
LL | / trait A where for<'a> Self: 'a
5+
LL | |
6+
LL | | {
7+
LL | | }
8+
| |_^
9+
|
10+
= help: consider adding an explicit lifetime bound `Self: 'a`...
11+
= note: ...so that the type `Self` will meet its required lifetime bounds...
12+
note: ...that is required by this bound
13+
--> $DIR/issue-88586-hr-self-outlives-in-trait-def.rs:6:29
14+
|
15+
LL | trait A where for<'a> Self: 'a
16+
| ^^
17+
18+
error: aborting due to previous error
19+

0 commit comments

Comments
 (0)