1 //! Checks that associated type defaults are properly validated.
4 //! * Default types are checked against where clauses on the assoc. type
5 //! (eg. `type Assoc: Clone = NotClone`)
7 #![feature(associated_type_defaults)]
11 // Assoc. type bounds must hold for the default type
13 type Ty: Clone = NotClone;
14 //~^ ERROR the trait bound `NotClone: Clone` is not satisfied
17 // Where-clauses defined on the trait must also be considered
23 //~^ ERROR the trait bound `NotClone: Clone` is not satisfied
26 // Involved type parameters must fulfill all bounds required by defaults that mention them
28 type Bar: Clone = Vec<T>;
29 //~^ ERROR the trait bound `T: Clone` is not satisfied
33 // `(): Foo<Self>` might hold for some possible impls but not all.
34 type Assoc: Foo<Self> = ();
35 //~^ ERROR the trait bound `(): Foo<Self>` is not satisfied
39 impl<T> IsU8<u8> for T {}
41 // Test that mentioning the assoc. type inside where clauses is not allowed
43 Vec<Self::Assoc>: Clone,
44 Self::Assoc: IsU8<Self::Assoc>,
45 bool: IsU8<Self::Assoc>,
50 // Test that we get all expected errors if that default is unsuitable
52 Vec<Self::Assoc>: Clone,
53 Self::Assoc: IsU8<Self::Assoc>,
54 bool: IsU8<Self::Assoc>,
56 type Assoc = NotClone;
57 //~^ ERROR the trait bound `NotClone: IsU8<NotClone>` is not satisfied
60 // Test behavior of the check when defaults refer to other defaults:
62 // Shallow substitution rejects this trait since `Baz` isn't guaranteed to be
65 type Bar: Clone = Vec<Self::Baz>;
66 //~^ ERROR the trait bound `<Self as Foo2<T>>::Baz: Clone` is not satisfied
70 // Adding a `T: Clone` bound doesn't help since the requirement doesn't see `T`
71 // because of the shallow substitution. If we did a deep substitution instead,
72 // this would be accepted.
73 trait Foo25<T: Clone> {
74 type Bar: Clone = Vec<Self::Baz>;
75 //~^ ERROR the trait bound `<Self as Foo25<T>>::Baz: Clone` is not satisfied
79 // Adding the `Baz: Clone` bound isn't enough since the default is type
80 // parameter `T`, which also might not be `Clone`.
86 type Bar = Vec<Self::Baz>;
88 //~^ ERROR the trait bound `T: Clone` is not satisfied
91 // This one finally works, with `Clone` bounds on all assoc. types and the type
97 type Bar: Clone = Vec<Self::Baz>;