Skip to content

Commit 571a15b

Browse files
committed
avoid giving a principal to marker-only trait objects
Fixes #33140.
1 parent 3aa1503 commit 571a15b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/librustc/ty/sty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> {
572572
pub fn principal(&self) -> Option<ExistentialTraitRef<'tcx>> {
573573
match self[0] {
574574
ExistentialPredicate::Trait(tr) => Some(tr),
575-
other => bug!("first predicate is {:?}", other),
575+
_ => None
576576
}
577577
}
578578

src/librustc_typeck/astconv.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,13 +1138,19 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
11381138
auto_traits.dedup();
11391139

11401140
// Calling `skip_binder` is okay, because the predicates are re-bound.
1141+
let principal = if tcx.trait_is_auto(existential_principal.def_id()) {
1142+
ty::ExistentialPredicate::AutoTrait(existential_principal.def_id())
1143+
} else {
1144+
ty::ExistentialPredicate::Trait(*existential_principal.skip_binder())
1145+
};
11411146
let mut v =
1142-
iter::once(ty::ExistentialPredicate::Trait(*existential_principal.skip_binder()))
1147+
iter::once(principal)
11431148
.chain(auto_traits.into_iter().map(ty::ExistentialPredicate::AutoTrait))
11441149
.chain(existential_projections
11451150
.map(|x| ty::ExistentialPredicate::Projection(*x.skip_binder())))
11461151
.collect::<SmallVec<[_; 8]>>();
11471152
v.sort_by(|a, b| a.stable_cmp(tcx, b));
1153+
v.dedup();
11481154
let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
11491155

11501156
// Use explicitly-specified region bound.

0 commit comments

Comments
 (0)