typeck: Ensure proper bound vars passed to add_bounds
.
Fixes the ICE in #88586.
This commit is contained in:
parent
4919988fe1
commit
9155f672bf
3 changed files with 37 additions and 9 deletions
|
@ -666,7 +666,7 @@ impl ItemCtxt<'tcx> {
|
||||||
Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name),
|
Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name),
|
||||||
None => true,
|
None => true,
|
||||||
})
|
})
|
||||||
.flat_map(|b| predicates_from_bound(self, ty, b));
|
.flat_map(|b| predicates_from_bound(self, ty, b, ty::List::empty()));
|
||||||
|
|
||||||
let param_def_id = self.tcx.hir().local_def_id(param_id).to_def_id();
|
let param_def_id = self.tcx.hir().local_def_id(param_id).to_def_id();
|
||||||
let from_where_clauses = ast_generics
|
let from_where_clauses = ast_generics
|
||||||
|
@ -685,15 +685,17 @@ impl ItemCtxt<'tcx> {
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
let bvars = self.tcx.late_bound_vars(bp.bounded_ty.hir_id);
|
||||||
|
|
||||||
bp.bounds
|
bp.bounds
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|b| match assoc_name {
|
.filter(|b| match assoc_name {
|
||||||
Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name),
|
Some(assoc_name) => self.bound_defines_assoc_item(b, assoc_name),
|
||||||
None => true,
|
None => true,
|
||||||
})
|
})
|
||||||
.filter_map(move |b| bt.map(|bt| (bt, b)))
|
.filter_map(move |b| bt.map(|bt| (bt, b, bvars)))
|
||||||
})
|
})
|
||||||
.flat_map(|(bt, b)| predicates_from_bound(self, bt, b));
|
.flat_map(|(bt, b, bvars)| predicates_from_bound(self, bt, b, bvars));
|
||||||
|
|
||||||
from_ty_params.chain(from_where_clauses).collect()
|
from_ty_params.chain(from_where_clauses).collect()
|
||||||
}
|
}
|
||||||
|
@ -2433,14 +2435,10 @@ fn predicates_from_bound<'tcx>(
|
||||||
astconv: &dyn AstConv<'tcx>,
|
astconv: &dyn AstConv<'tcx>,
|
||||||
param_ty: Ty<'tcx>,
|
param_ty: Ty<'tcx>,
|
||||||
bound: &'tcx hir::GenericBound<'tcx>,
|
bound: &'tcx hir::GenericBound<'tcx>,
|
||||||
|
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
|
||||||
) -> Vec<(ty::Predicate<'tcx>, Span)> {
|
) -> Vec<(ty::Predicate<'tcx>, Span)> {
|
||||||
let mut bounds = Bounds::default();
|
let mut bounds = Bounds::default();
|
||||||
astconv.add_bounds(
|
astconv.add_bounds(param_ty, std::array::IntoIter::new([bound]), &mut bounds, bound_vars);
|
||||||
param_ty,
|
|
||||||
std::array::IntoIter::new([bound]),
|
|
||||||
&mut bounds,
|
|
||||||
ty::List::empty(),
|
|
||||||
);
|
|
||||||
bounds.predicates(astconv.tcx(), param_ty)
|
bounds.predicates(astconv.tcx(), param_ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// Regression test for #88586: a higher-ranked outlives bound on Self in a trait
|
||||||
|
// definition caused an ICE when debug_assertions were enabled.
|
||||||
|
//
|
||||||
|
// The error output is incidentally unhelpful; this should be improved.
|
||||||
|
|
||||||
|
trait A where for<'a> Self: 'a
|
||||||
|
//~^ ERROR the parameter type `Self` may not live long enough
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,19 @@
|
||||||
|
error[E0311]: the parameter type `Self` may not live long enough
|
||||||
|
--> $DIR/issue-88586-hr-self-outlives-in-trait-def.rs:6:1
|
||||||
|
|
|
||||||
|
LL | / trait A where for<'a> Self: 'a
|
||||||
|
LL | |
|
||||||
|
LL | | {
|
||||||
|
LL | | }
|
||||||
|
| |_^
|
||||||
|
|
|
||||||
|
= help: consider adding an explicit lifetime bound `Self: 'a`...
|
||||||
|
= note: ...so that the type `Self` will meet its required lifetime bounds...
|
||||||
|
note: ...that is required by this bound
|
||||||
|
--> $DIR/issue-88586-hr-self-outlives-in-trait-def.rs:6:29
|
||||||
|
|
|
||||||
|
LL | trait A where for<'a> Self: 'a
|
||||||
|
| ^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue