Skip to content

Commit 6d3ee41

Browse files
author
Alexander Regueiro
committed
Added error for duplicate bindings of associated type.
1 parent 0e89f57 commit 6d3ee41

14 files changed

+184
-117
lines changed

src/librustc/traits/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ pub use self::select::{EvaluationResult, IntercrateAmbiguityCause, OverflowError
5050
pub use self::specialize::{OverlapError, specialization_graph, translate_substs};
5151
pub use self::specialize::find_associated_item;
5252
pub use self::engine::{TraitEngine, TraitEngineExt};
53-
pub use self::util::elaborate_predicates;
54-
pub use self::util::supertraits;
55-
pub use self::util::Supertraits;
56-
pub use self::util::supertrait_def_ids;
57-
pub use self::util::SupertraitDefIds;
53+
pub use self::util::{elaborate_predicates, elaborate_trait_ref, elaborate_trait_refs};
54+
pub use self::util::{supertraits, supertrait_def_ids, Supertraits, SupertraitDefIds};
5855
pub use self::util::transitive_bounds;
5956

6057
#[allow(dead_code)]

src/librustc/ty/mod.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,14 @@ impl<'tcx> TyS<'tcx> {
544544
pub fn is_primitive_ty(&self) -> bool {
545545
match self.sty {
546546
TyKind::Bool |
547-
TyKind::Char |
548-
TyKind::Int(_) |
549-
TyKind::Uint(_) |
550-
TyKind::Float(_) |
551-
TyKind::Infer(InferTy::IntVar(_)) |
552-
TyKind::Infer(InferTy::FloatVar(_)) |
553-
TyKind::Infer(InferTy::FreshIntTy(_)) |
554-
TyKind::Infer(InferTy::FreshFloatTy(_)) => true,
547+
TyKind::Char |
548+
TyKind::Int(_) |
549+
TyKind::Uint(_) |
550+
TyKind::Float(_) |
551+
TyKind::Infer(InferTy::IntVar(_)) |
552+
TyKind::Infer(InferTy::FloatVar(_)) |
553+
TyKind::Infer(InferTy::FreshIntTy(_)) |
554+
TyKind::Infer(InferTy::FreshFloatTy(_)) => true,
555555
TyKind::Ref(_, x, _) => x.is_primitive_ty(),
556556
_ => false,
557557
}
@@ -1042,15 +1042,15 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> {
10421042

10431043
#[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
10441044
pub enum Predicate<'tcx> {
1045-
/// Corresponds to `where Foo : Bar<A,B,C>`. `Foo` here would be
1045+
/// Corresponds to `where Foo: Bar<A,B,C>`. `Foo` here would be
10461046
/// the `Self` type of the trait reference and `A`, `B`, and `C`
10471047
/// would be the type parameters.
10481048
Trait(PolyTraitPredicate<'tcx>),
10491049

1050-
/// where `'a : 'b`
1050+
/// where `'a: 'b`
10511051
RegionOutlives(PolyRegionOutlivesPredicate<'tcx>),
10521052

1053-
/// where `T : 'a`
1053+
/// where `T: 'a`
10541054
TypeOutlives(PolyTypeOutlivesPredicate<'tcx>),
10551055

10561056
/// where `<T as TraitRef>::Name == X`, approximately.
@@ -1063,7 +1063,7 @@ pub enum Predicate<'tcx> {
10631063
/// trait must be object-safe
10641064
ObjectSafe(DefId),
10651065

1066-
/// No direct syntax. May be thought of as `where T : FnFoo<...>`
1066+
/// No direct syntax. May be thought of as `where T: FnFoo<...>`
10671067
/// for some substitutions `...` and `T` being a closure type.
10681068
/// Satisfied (or refuted) once we know the closure's kind.
10691069
ClosureKind(DefId, ClosureSubsts<'tcx>, ClosureKind),
@@ -1112,11 +1112,11 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
11121112
//
11131113
// Let's start with an easy case. Consider two traits:
11141114
//
1115-
// trait Foo<'a> : Bar<'a,'a> { }
1115+
// trait Foo<'a>: Bar<'a,'a> { }
11161116
// trait Bar<'b,'c> { }
11171117
//
1118-
// Now, if we have a trait reference `for<'x> T : Foo<'x>`, then
1119-
// we can deduce that `for<'x> T : Bar<'x,'x>`. Basically, if we
1118+
// Now, if we have a trait reference `for<'x> T: Foo<'x>`, then
1119+
// we can deduce that `for<'x> T: Bar<'x,'x>`. Basically, if we
11201120
// knew that `Foo<'x>` (for any 'x) then we also know that
11211121
// `Bar<'x,'x>` (for any 'x). This more-or-less falls out from
11221122
// normal substitution.
@@ -1129,21 +1129,21 @@ impl<'a, 'gcx, 'tcx> Predicate<'tcx> {
11291129
//
11301130
// Another example to be careful of is this:
11311131
//
1132-
// trait Foo1<'a> : for<'b> Bar1<'a,'b> { }
1132+
// trait Foo1<'a>: for<'b> Bar1<'a,'b> { }
11331133
// trait Bar1<'b,'c> { }
11341134
//
1135-
// Here, if we have `for<'x> T : Foo1<'x>`, then what do we know?
1136-
// The answer is that we know `for<'x,'b> T : Bar1<'x,'b>`. The
1135+
// Here, if we have `for<'x> T: Foo1<'x>`, then what do we know?
1136+
// The answer is that we know `for<'x,'b> T: Bar1<'x,'b>`. The
11371137
// reason is similar to the previous example: any impl of
1138-
// `T:Foo1<'x>` must show that `for<'b> T : Bar1<'x, 'b>`. So
1138+
// `T:Foo1<'x>` must show that `for<'b> T: Bar1<'x, 'b>`. So
11391139
// basically we would want to collapse the bound lifetimes from
11401140
// the input (`trait_ref`) and the supertraits.
11411141
//
11421142
// To achieve this in practice is fairly straightforward. Let's
11431143
// consider the more complicated scenario:
11441144
//
1145-
// - We start out with `for<'x> T : Foo1<'x>`. In this case, `'x`
1146-
// has a De Bruijn index of 1. We want to produce `for<'x,'b> T : Bar1<'x,'b>`,
1145+
// - We start out with `for<'x> T: Foo1<'x>`. In this case, `'x`
1146+
// has a De Bruijn index of 1. We want to produce `for<'x,'b> T: Bar1<'x,'b>`,
11471147
// where both `'x` and `'b` would have a DB index of 1.
11481148
// The substitution from the input trait-ref is therefore going to be
11491149
// `'a => 'x` (where `'x` has a DB index of 1).
@@ -1219,7 +1219,7 @@ impl<'tcx> PolyTraitPredicate<'tcx> {
12191219
}
12201220

12211221
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
1222-
pub struct OutlivesPredicate<A,B>(pub A, pub B); // `A : B`
1222+
pub struct OutlivesPredicate<A,B>(pub A, pub B); // `A: B`
12231223
pub type PolyOutlivesPredicate<A,B> = ty::Binder<OutlivesPredicate<A,B>>;
12241224
pub type RegionOutlivesPredicate<'tcx> = OutlivesPredicate<ty::Region<'tcx>,
12251225
ty::Region<'tcx>>;
@@ -2476,7 +2476,7 @@ impl<'tcx> TyS<'tcx> {
24762476
///
24772477
/// Note: prefer `ty.walk()` where possible.
24782478
pub fn maybe_walk<F>(&'tcx self, mut f: F)
2479-
where F : FnMut(Ty<'tcx>) -> bool
2479+
where F: FnMut(Ty<'tcx>) -> bool
24802480
{
24812481
let mut walker = self.walk();
24822482
while let Some(ty) = walker.next() {

src/librustc/ty/sty.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
627627
/// A complete reference to a trait. These take numerous guises in syntax,
628628
/// but perhaps the most recognizable form is in a where clause:
629629
///
630-
/// T : Foo<U>
630+
/// T: Foo<U>
631631
///
632632
/// This would be represented by a trait-reference where the def-id is the
633633
/// def-id for the trait `Foo` and the substs define `T` as parameter 0,
@@ -637,8 +637,8 @@ impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> {
637637
/// that case the `Self` parameter is absent from the substitutions.
638638
///
639639
/// Note that a `TraitRef` introduces a level of region binding, to
640-
/// account for higher-ranked trait bounds like `T : for<'a> Foo<&'a
641-
/// U>` or higher-ranked object types.
640+
/// account for higher-ranked trait bounds like `T: for<'a> Foo<&'a U>`
641+
/// or higher-ranked object types.
642642
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
643643
pub struct TraitRef<'tcx> {
644644
pub def_id: DefId,
@@ -663,7 +663,7 @@ impl<'tcx> TraitRef<'tcx> {
663663
self.substs.type_at(0)
664664
}
665665

666-
pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
666+
pub fn input_types<'a>(&'a self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'a {
667667
// Select only the "input types" from a trait-reference. For
668668
// now this is all the types that appear in the
669669
// trait-reference, but it should eventually exclude
@@ -886,16 +886,16 @@ pub struct ProjectionTy<'tcx> {
886886
/// The parameters of the associated item.
887887
pub substs: &'tcx Substs<'tcx>,
888888

889-
/// The DefId of the TraitItem for the associated type N.
889+
/// The `DefId` of the `TraitItem` for the associated type `N`.
890890
///
891-
/// Note that this is not the DefId of the TraitRef containing this
892-
/// associated type, which is in tcx.associated_item(item_def_id).container.
891+
/// Note that this is not the `DefId` of the `TraitRef` containing this
892+
/// associated type, which is in `tcx.associated_item(item_def_id).container`.
893893
pub item_def_id: DefId,
894894
}
895895

896896
impl<'a, 'tcx> ProjectionTy<'tcx> {
897-
/// Construct a ProjectionTy by searching the trait from trait_ref for the
898-
/// associated item named item_name.
897+
/// Construct a `ProjectionTy` by searching the trait from `trait_ref` for the
898+
/// associated item named `item_name`.
899899
pub fn from_ref_and_name(
900900
tcx: TyCtxt<'_, '_, '_>, trait_ref: ty::TraitRef<'tcx>, item_name: Ident
901901
) -> ProjectionTy<'tcx> {

src/librustc/ty/subst.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::marker::PhantomData;
2727
use std::mem;
2828
use std::num::NonZeroUsize;
2929

30-
/// An entity in the Rust typesystem, which can be one of
30+
/// An entity in the Rust type system, which can be one of
3131
/// several kinds (only types and lifetimes for now).
3232
/// To reduce memory usage, a `Kind` is a interned pointer,
3333
/// with the lowest 2 bits being reserved for a tag to
@@ -171,17 +171,17 @@ impl<'tcx> Decodable for Kind<'tcx> {
171171
pub type Substs<'tcx> = List<Kind<'tcx>>;
172172

173173
impl<'a, 'gcx, 'tcx> Substs<'tcx> {
174-
/// Creates a Substs that maps each generic parameter to itself.
174+
/// Creates a `Substs` that maps each generic parameter to itself.
175175
pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId)
176176
-> &'tcx Substs<'tcx> {
177177
Substs::for_item(tcx, def_id, |param, _| {
178178
tcx.mk_param_from_def(param)
179179
})
180180
}
181181

182-
/// Creates a Substs for generic parameter definitions,
182+
/// Creates a `Substs` for generic parameter definitions,
183183
/// by calling closures to obtain each kind.
184-
/// The closures get to observe the Substs as they're
184+
/// The closures get to observe the `Substs` as they're
185185
/// being built, which can be used to correctly
186186
/// substitute defaults of generic parameters.
187187
pub fn for_item<F>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
@@ -242,7 +242,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
242242
}
243243

244244
#[inline]
245-
pub fn types(&'a self) -> impl DoubleEndedIterator<Item=Ty<'tcx>> + 'a {
245+
pub fn types(&'a self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'a {
246246
self.iter().filter_map(|k| {
247247
if let UnpackedKind::Type(ty) = k.unpack() {
248248
Some(ty)
@@ -253,7 +253,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
253253
}
254254

255255
#[inline]
256-
pub fn regions(&'a self) -> impl DoubleEndedIterator<Item=ty::Region<'tcx>> + 'a {
256+
pub fn regions(&'a self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> + 'a {
257257
self.iter().filter_map(|k| {
258258
if let UnpackedKind::Lifetime(lt) = k.unpack() {
259259
Some(lt)
@@ -332,7 +332,7 @@ impl<'tcx> serialize::UseSpecializedDecodable for &'tcx Substs<'tcx> {}
332332
// `foo`. Or use `foo.subst_spanned(tcx, substs, Some(span))` when
333333
// there is more information available (for better errors).
334334

335-
pub trait Subst<'tcx> : Sized {
335+
pub trait Subst<'tcx>: Sized {
336336
fn subst<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
337337
substs: &[Kind<'tcx>]) -> Self {
338338
self.subst_spanned(tcx, substs, None)

0 commit comments

Comments
 (0)