From 571a15bd15f02a65f1978b9b72589beb89a60782 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Tue, 4 Dec 2018 15:17:35 +0200 Subject: [PATCH] avoid giving a principal to marker-only trait objects Fixes #33140. --- src/librustc/ty/sty.rs | 2 +- src/librustc_typeck/astconv.rs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 45fb8cf3dc9..10f89c965d1 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -572,7 +572,7 @@ impl<'tcx> List> { pub fn principal(&self) -> Option> { match self[0] { ExistentialPredicate::Trait(tr) => Some(tr), - other => bug!("first predicate is {:?}", other), + _ => None } } diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 1db7141917f..22d609ea8a4 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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::>(); 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.