提交 571a15bd 编写于 作者: A Ariel Ben-Yehuda

avoid giving a principal to marker-only trait objects

Fixes #33140.
上级 3aa1503a
......@@ -572,7 +572,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
pub fn principal(&self) -> Option<ExistentialTraitRef<'tcx>> {
match self[0] {
ExistentialPredicate::Trait(tr) => Some(tr),
other => bug!("first predicate is {:?}", other),
_ => None
}
}
......
......@@ -1138,13 +1138,19 @@ fn conv_object_ty_poly_trait_ref(&self,
auto_traits.dedup();
// Calling `skip_binder` is okay, because the predicates are re-bound.
let principal = if tcx.trait_is_auto(existential_principal.def_id()) {
ty::ExistentialPredicate::AutoTrait(existential_principal.def_id())
} else {
ty::ExistentialPredicate::Trait(*existential_principal.skip_binder())
};
let mut v =
iter::once(ty::ExistentialPredicate::Trait(*existential_principal.skip_binder()))
iter::once(principal)
.chain(auto_traits.into_iter().map(ty::ExistentialPredicate::AutoTrait))
.chain(existential_projections
.map(|x| ty::ExistentialPredicate::Projection(*x.skip_binder())))
.collect::<SmallVec<[_; 8]>>();
v.sort_by(|a, b| a.stable_cmp(tcx, b));
v.dedup();
let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
// Use explicitly-specified region bound.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册