Skip to content

Commit a62d078

Browse files
author
Alexander Regueiro
committed
Fixed unsoundness hole.
1 parent 469c3bf commit a62d078

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl<'tcx> TraitRef<'tcx> {
636636
TraitRef { def_id: def_id, substs: substs }
637637
}
638638

639-
/// Returns a TraitRef of the form `P0: Foo<P1..Pn>` where `Pi`
639+
/// Returns a `TraitRef` of the form `P0: Foo<P1..Pn>` where `Pi`
640640
/// are the parameters defined on trait.
641641
pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> {
642642
TraitRef {

src/librustc_typeck/astconv.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,10 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
974974
let principal = self.instantiate_poly_trait_ref(&trait_bounds[0],
975975
dummy_self,
976976
&mut projection_bounds);
977+
debug!("principal: {:?}", principal);
977978

978979
for trait_bound in trait_bounds[1..].iter() {
979-
// Sanity check for non-principal trait bounds
980+
// sanity check for non-principal trait bounds
980981
self.instantiate_poly_trait_ref(trait_bound,
981982
dummy_self,
982983
&mut vec![]);
@@ -1008,9 +1009,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
10081009
})
10091010
});
10101011

1011-
// check that there are no gross object safety violations,
1012+
// Check that there are no gross object safety violations;
10121013
// most importantly, that the supertraits don't contain Self,
1013-
// to avoid ICE-s.
1014+
// to avoid ICEs.
10141015
let object_safety_violations =
10151016
tcx.astconv_object_safety_violations(principal.def_id());
10161017
if !object_safety_violations.is_empty() {
@@ -1020,7 +1021,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
10201021
return tcx.types.err;
10211022
}
10221023

1023-
// use a BTreeSet to keep output in a more consistent order
1024+
// Use a BTreeSet to keep output in a more consistent order.
10241025
let mut associated_types = BTreeSet::default();
10251026

10261027
for tr in traits::supertraits(tcx, principal) {
@@ -1059,7 +1060,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
10591060
v.sort_by(|a, b| a.stable_cmp(tcx, b));
10601061
let existential_predicates = ty::Binder::bind(tcx.mk_existential_predicates(v.into_iter()));
10611062

1062-
// Explicitly specified region bound. Use that.
1063+
// Use explicitly-specified region bound.
10631064
let region_bound = if !lifetime.is_elided() {
10641065
self.ast_region_to_region(lifetime, None)
10651066
} else {

src/librustc_typeck/collect.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ fn type_param_predicates<'a, 'tcx>(
319319
let icx = ItemCtxt::new(tcx, item_def_id);
320320
result
321321
.predicates
322-
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, true));
322+
.extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty,
323+
OnlySelfBounds(true)));
323324
result
324325
}
325326

@@ -716,7 +717,7 @@ fn super_predicates_of<'a, 'tcx>(
716717
// as one of its "superpredicates".
717718
let is_trait_alias = ty::is_trait_alias(tcx, trait_def_id);
718719
let superbounds2 = icx.type_parameter_bounds_in_generics(
719-
generics, item.id, self_param_ty, !is_trait_alias);
720+
generics, item.id, self_param_ty, OnlySelfBounds(!is_trait_alias));
720721

721722
// Combine the two lists to form the complete set of superbounds:
722723
let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect();
@@ -1694,6 +1695,7 @@ fn explicit_predicates_of<'a, 'tcx>(
16941695

16951696
let icx = ItemCtxt::new(tcx, def_id);
16961697
let no_generics = hir::Generics::empty();
1698+
let empty_trait_items = HirVec::new();
16971699

16981700
let mut predicates = UniquePredicates::new();
16991701

@@ -1738,6 +1740,10 @@ fn explicit_predicates_of<'a, 'tcx>(
17381740
is_trait = Some((ty::TraitRef::identity(tcx, def_id), items));
17391741
generics
17401742
}
1743+
ItemKind::TraitAlias(ref generics, _) => {
1744+
is_trait = Some((ty::TraitRef::identity(tcx, def_id), &empty_trait_items));
1745+
generics
1746+
}
17411747
ItemKind::Existential(ExistTy {
17421748
ref bounds,
17431749
impl_trait_fn,

0 commit comments

Comments
 (0)