Fixed unsoundness hole.

This commit is contained in:
Alexander Regueiro 2018-11-01 03:08:04 +00:00
parent 469c3bf75b
commit a62d0785a6
3 changed files with 15 additions and 8 deletions

View File

@ -636,7 +636,7 @@ pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>) -> TraitRef<'tcx> {
TraitRef { def_id: def_id, substs: substs } TraitRef { def_id: def_id, substs: substs }
} }
/// Returns a TraitRef of the form `P0: Foo<P1..Pn>` where `Pi` /// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
/// are the parameters defined on trait. /// are the parameters defined on trait.
pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> { pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> {
TraitRef { TraitRef {

View File

@ -974,9 +974,10 @@ fn conv_object_ty_poly_trait_ref(&self,
let principal = self.instantiate_poly_trait_ref(&trait_bounds[0], let principal = self.instantiate_poly_trait_ref(&trait_bounds[0],
dummy_self, dummy_self,
&mut projection_bounds); &mut projection_bounds);
debug!("principal: {:?}", principal);
for trait_bound in trait_bounds[1..].iter() { for trait_bound in trait_bounds[1..].iter() {
// Sanity check for non-principal trait bounds // sanity check for non-principal trait bounds
self.instantiate_poly_trait_ref(trait_bound, self.instantiate_poly_trait_ref(trait_bound,
dummy_self, dummy_self,
&mut vec![]); &mut vec![]);
@ -1008,9 +1009,9 @@ fn conv_object_ty_poly_trait_ref(&self,
}) })
}); });
// check that there are no gross object safety violations, // Check that there are no gross object safety violations;
// most importantly, that the supertraits don't contain Self, // most importantly, that the supertraits don't contain Self,
// to avoid ICE-s. // to avoid ICEs.
let object_safety_violations = let object_safety_violations =
tcx.astconv_object_safety_violations(principal.def_id()); tcx.astconv_object_safety_violations(principal.def_id());
if !object_safety_violations.is_empty() { if !object_safety_violations.is_empty() {
@ -1020,7 +1021,7 @@ fn conv_object_ty_poly_trait_ref(&self,
return tcx.types.err; return tcx.types.err;
} }
// use a BTreeSet to keep output in a more consistent order // Use a BTreeSet to keep output in a more consistent order.
let mut associated_types = BTreeSet::default(); let mut associated_types = BTreeSet::default();
for tr in traits::supertraits(tcx, principal) { for tr in traits::supertraits(tcx, principal) {
@ -1059,7 +1060,7 @@ fn conv_object_ty_poly_trait_ref(&self,
v.sort_by(|a, b| a.stable_cmp(tcx, b)); v.sort_by(|a, b| a.stable_cmp(tcx, b));
let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter())); let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
// Explicitly specified region bound. Use that. // Use explicitly-specified region bound.
let region_bound = if !lifetime.is_elided() { let region_bound = if !lifetime.is_elided() {
self.ast_region_to_region(lifetime, None) self.ast_region_to_region(lifetime, None)
} else { } else {

View File

@ -319,7 +319,8 @@ fn type_param_predicates<'a, 'tcx>(
let icx = ItemCtxt::new(tcx, item_def_id); let icx = ItemCtxt::new(tcx, item_def_id);
result result
.predicates .predicates
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, true)); .extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
OnlySelfBounds(true)));
result result
} }
@ -716,7 +717,7 @@ fn super_predicates_of<'a, 'tcx>(
// as one of its "superpredicates". // as one of its "superpredicates".
let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id); let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id);
let superbounds2 = icx.type_parameter_bounds_in_generics( let superbounds2 = icx.type_parameter_bounds_in_generics(
generics, item.id, self_param_ty, !is_trait_alias); generics, item.id, self_param_ty, OnlySelfBounds(!is_trait_alias));
// Combine the two lists to form the complete set of superbounds: // Combine the two lists to form the complete set of superbounds:
let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect(); let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect();
@ -1694,6 +1695,7 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
let icx = ItemCtxt::new(tcx, def_id); let icx = ItemCtxt::new(tcx, def_id);
let no_generics = hir::Generics::empty(); let no_generics = hir::Generics::empty();
let empty_trait_items = HirVec::new();
let mut predicates = UniquePredicates::new(); let mut predicates = UniquePredicates::new();
@ -1738,6 +1740,10 @@ fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter:
is_trait = Some((ty::TraitRef::identity(tcx, def_id), items)); is_trait = Some((ty::TraitRef::identity(tcx, def_id), items));
generics generics
} }
ItemKind::TraitAlias(ref generics, _) => {
is_trait = Some((ty::TraitRef::identity(tcx, def_id), &empty_trait_items));
generics
}
ItemKind::Existential(ExistTy { ItemKind::Existential(ExistTy {
ref bounds, ref bounds,
impl_trait_fn, impl_trait_fn,