Skip to content

Commit

Permalink
avoid giving a principal to marker-only trait objects
Browse files Browse the repository at this point in the history
Fixes #33140.
  • Loading branch information
arielb1 committed Jan 3, 2019
1 parent 3aa1503 commit 571a15b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ty/sty.rs
Expand Up @@ -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
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/librustc_typeck/astconv.rs
Expand Up @@ -1138,13 +1138,19 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
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.
Expand Down

0 comments on commit 571a15b

Please sign in to comment.