about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Regueiro <alexreg@me.com>2018-11-01 03:08:04 +0000
committerAlexander Regueiro <alexreg@me.com>2018-11-03 04:09:35 +0000
commita62d0785a6b0770f2241a3e91853d842609d4d7c (patch)
tree687eafcacf879cde77eba340fb1df82c0980db75
parent469c3bf75b5768611f65c65c3bbafab3c315dcdf (diff)
downloadrust-a62d0785a6b0770f2241a3e91853d842609d4d7c.tar.gz
rust-a62d0785a6b0770f2241a3e91853d842609d4d7c.zip
Fixed unsoundness hole.
-rw-r--r--src/librustc/ty/sty.rs2
-rw-r--r--src/librustc_typeck/astconv.rs11
-rw-r--r--src/librustc_typeck/collect.rs10
3 files changed, 15 insertions, 8 deletions
diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs
index 62e38ad9bfa..49cd87e2dc5 100644
--- a/src/librustc/ty/sty.rs
+++ b/src/librustc/ty/sty.rs
@@ -636,7 +636,7 @@ impl<'tcx> TraitRef<'tcx> {
         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.
     pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> {
         TraitRef {
diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs
index 9556be6ebfc..e44cfec82ad 100644
--- a/src/librustc_typeck/astconv.rs
+++ b/src/librustc_typeck/astconv.rs
@@ -974,9 +974,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
         let principal = self.instantiate_poly_trait_ref(&trait_bounds[0],
                                                         dummy_self,
                                                         &mut projection_bounds);
+        debug!("principal: {:?}", principal);
 
         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,
                                             dummy_self,
                                             &mut vec![]);
@@ -1008,9 +1009,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
             })
         });
 
-        // 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,
-        // to avoid ICE-s.
+        // to avoid ICEs.
         let object_safety_violations =
             tcx.astconv_object_safety_violations(principal.def_id());
         if !object_safety_violations.is_empty() {
@@ -1020,7 +1021,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
             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();
 
         for tr in traits::supertraits(tcx, principal) {
@@ -1059,7 +1060,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
         v.sort_by(|a, b| a.stable_cmp(tcx, b));
         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() {
             self.ast_region_to_region(lifetime, None)
         } else {
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 9ffbe1a68b8..917fb887e0b 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -319,7 +319,8 @@ fn type_param_predicates<'a, 'tcx>(
     let icx = ItemCtxt::new(tcx, item_def_id);
     result
         .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
 }
 
@@ -716,7 +717,7 @@ fn super_predicates_of<'a, 'tcx>(
     // as one of its "superpredicates".
     let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id);
     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:
     let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect();
@@ -1694,6 +1695,7 @@ fn explicit_predicates_of<'a, 'tcx>(
 
     let icx = ItemCtxt::new(tcx, def_id);
     let no_generics = hir::Generics::empty();
+    let empty_trait_items = HirVec::new();
 
     let mut predicates = UniquePredicates::new();
 
@@ -1738,6 +1740,10 @@ fn explicit_predicates_of<'a, 'tcx>(
                     is_trait = Some((ty::TraitRef::identity(tcx, def_id), items));
                     generics
                 }
+                ItemKind::TraitAlias(ref generics, _) => {
+                    is_trait = Some((ty::TraitRef::identity(tcx, def_id), &empty_trait_items));
+                    generics
+                }
                 ItemKind::Existential(ExistTy {
                     ref bounds,
                     impl_trait_fn,