Check only predicates with a single param with a concrete default.

This is the most conservative possible and should be always correct.
This commit is contained in:
leonardo.yvens 2018-02-09 08:42:11 -02:00
parent ac17948d0f
commit c74f85f935
4 changed files with 50 additions and 102 deletions

View file

@ -14,12 +14,15 @@ struct Foo<U, V=i32>(U, V) where U: Trait<V>;
trait Marker {}
struct TwoParams<T, U>(T, U);
impl Marker for TwoParams<i32, i32> {}
// Check that defaults are substituted simultaneously.
// Clauses with more than 1 param are not checked.
struct IndividuallyBogus<T = i32, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Marker;
struct BogusTogether<T = u32, U = i32>(T, U) where TwoParams<T, U>: Marker;
// Clauses with non-defaulted params are not checked.
struct NonDefaultedInClause<T, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Marker;
struct DefaultedLhs<U, V=i32>(U, V) where V: Trait<U>;
// Dependent defaults.
struct Dependent<T: Copy, U = T>(T, U) where U: Copy;
// Dependent defaults are not checked.
struct Dependent<T, U = T>(T, U) where U: Copy;
trait SelfBound<T: Copy=Self> {}
fn main() {}

View file

@ -30,25 +30,11 @@ struct WhereClause<T=String>(T) where T: Copy;
trait TraitBound<T:Copy=String> {}
//~^ error: the trait bound `std::string::String: std::marker::Copy` is not satisfied [E0277]
trait SelfBound<T:Copy=Self> {}
//~^ error: the trait bound `Self: std::marker::Copy` is not satisfied [E0277]
trait Super<T: Copy> { }
trait Base<T = String>: Super<T> { }
//~^ error: the trait bound `T: std::marker::Copy` is not satisfied [E0277]
trait ProjectionPred<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {}
//~^ error: the trait bound `i32: std::ops::Add<u8>` is not satisfied [E0277]
// Defaults must work together.
struct TwoParams<T = u32, U = i32>(T, U) where T: Bar<U>;
//~^ the trait bound `u32: Bar<i32>` is not satisfied [E0277]
trait Bar<V> {}
impl Bar<String> for u32 { }
impl Bar<i32> for String { }
// Dependent defaults.
struct Dependent<T, U = T>(T, U) where U: Copy;
//~^ the trait bound `T: std::marker::Copy` is not satisfied [E0277]
//~^ error: cannot add `u8` to `i32` [E0277]
fn main() { }

View file

@ -25,13 +25,14 @@ note: required by `Foo`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `A: std::iter::Iterator` is not satisfied
--> $DIR/type-check-defaults.rs:21:1
--> $DIR/type-check-defaults.rs:21:32
|
21 | struct WellFormedProjection<A, T=<A as Iterator>::Item>(A, T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `A` is not an iterator; maybe try calling `.iter()` or a similar method
| ^ `A` is not an iterator; maybe try calling `.iter()` or a similar method
|
= help: the trait `std::iter::Iterator` is not implemented for `A`
= help: consider adding a `where A: std::iter::Iterator` bound
= note: required by `std::iter::Iterator`
error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not satisfied
--> $DIR/type-check-defaults.rs:24:1
@ -57,59 +58,27 @@ error[E0277]: the trait bound `std::string::String: std::marker::Copy` is not sa
|
= note: required by `std::marker::Copy`
error[E0277]: the trait bound `Self: std::marker::Copy` is not satisfied
--> $DIR/type-check-defaults.rs:33:1
|
33 | trait SelfBound<T:Copy=Self> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `Self`
|
= help: consider adding a `where Self: std::marker::Copy` bound
= note: required by `std::marker::Copy`
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/type-check-defaults.rs:37:1
--> $DIR/type-check-defaults.rs:34:1
|
37 | trait Base<T = String>: Super<T> { }
34 | trait Base<T = String>: Super<T> { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= help: consider adding a `where T: std::marker::Copy` bound
note: required by `Super`
--> $DIR/type-check-defaults.rs:36:1
--> $DIR/type-check-defaults.rs:33:1
|
36 | trait Super<T: Copy> { }
33 | trait Super<T: Copy> { }
| ^^^^^^^^^^^^^^^^^^^^
error[E0277]: the trait bound `i32: std::ops::Add<u8>` is not satisfied
--> $DIR/type-check-defaults.rs:40:1
error[E0277]: cannot add `u8` to `i32`
--> $DIR/type-check-defaults.rs:37:1
|
40 | trait ProjectionPred<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {}
37 | trait ProjectionPred<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `i32 + u8`
|
= help: the trait `std::ops::Add<u8>` is not implemented for `i32`
= note: required by `std::ops::Add`
error[E0277]: the trait bound `u32: Bar<i32>` is not satisfied
--> $DIR/type-check-defaults.rs:44:1
|
44 | struct TwoParams<T = u32, U = i32>(T, U) where T: Bar<U>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar<i32>` is not implemented for `u32`
|
= help: the following implementations were found:
<u32 as Bar<std::string::String>>
note: required by `Bar`
--> $DIR/type-check-defaults.rs:46:1
|
46 | trait Bar<V> {}
| ^^^^^^^^^^^^
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/type-check-defaults.rs:51:1
|
51 | struct Dependent<T, U = T>(T, U) where U: Copy;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
|
= help: consider adding a `where T: std::marker::Copy` bound
= note: required by `std::marker::Copy`
error: aborting due to 11 previous errors
error: aborting due to 8 previous errors