Check WF of predicate with defaults only if all in LHS have default

Given a trait predicate, if all params appearing in the LHS have
defaults then it should be a backwards compatible predicate. We verify
that by checking the WF of predicate with all defaults substituted
simultaneously.
This commit is contained in:
leonardo.yvens 2018-01-21 12:09:06 -02:00
parent 35499aa9fc
commit addc404d32
5 changed files with 99 additions and 110 deletions

View file

@ -11,4 +11,11 @@
trait Trait<T> {}
struct Foo<U, V=i32>(U, V) where U: Trait<V>;
trait Trait2 {}
struct TwoParams<T, U>(T, U);
impl Trait2 for TwoParams<i32, i32> {}
// Check that defaults are substituted simultaneously.
struct IndividuallyBogus<T = i32, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Trait2;
// Clauses with non-defaulted params are not checked.
struct NonDefaultedInClause<T, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Trait2;
fn main() {}

View file

@ -33,19 +33,15 @@ trait TraitBound<T:Copy=String> {}
trait SelfBound<T:Copy=Self> {}
//~^ error: the trait bound `Self: std::marker::Copy` is not satisfied [E0277]
trait FooTrait<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {}
//~^ error: the trait bound `i32: std::ops::Add<u8>` is not satisfied [E0277]
trait Trait {}
struct TwoParams<T, U>(T, U);
impl Trait for TwoParams<i32, i32> {}
// Check that each default is substituted individually in the clauses.
struct Bogus<T = i32, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Trait;
//~^ error: the trait bound `TwoParams<i32, U>: Trait` is not satisfied [E0277]
//~^^ error: the trait bound `TwoParams<T, i32>: Trait` 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 Trait<T> {}
struct DefaultedLhs<U, V=i32>(U, V) where V: Trait<U>;
//~^ error: the trait bound `i32: Trait<U>` is not satisfied [E0277]
// FIXME: Deal with projection predicates
// trait ProjectionPred<T:Iterator = IntoIter<i32>> where T::Item : Add<u8> {}
// ~^ error: the trait bound `i32: std::ops::Add<u8>` is not satisfied [E0277]
fn main() { }

View file

@ -66,53 +66,30 @@ error[E0277]: the trait bound `Self: std::marker::Copy` is not satisfied
= help: consider adding a `where Self: std::marker::Copy` bound
= note: required by `std::marker::Copy`
error[E0277]: the trait bound `i32: std::ops::Add<u8>` is not satisfied
--> $DIR/type-check-defaults.rs:36:1
|
36 | trait FooTrait<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 `TwoParams<i32, U>: Trait` is not satisfied
--> $DIR/type-check-defaults.rs:43:1
|
43 | struct Bogus<T = i32, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Trait;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `TwoParams<i32, U>`
|
= help: consider adding a `where TwoParams<i32, U>: Trait` bound
note: required by `Trait`
--> $DIR/type-check-defaults.rs:39:1
|
39 | trait Trait {}
| ^^^^^^^^^^^
error[E0277]: the trait bound `TwoParams<T, i32>: Trait` is not satisfied
--> $DIR/type-check-defaults.rs:43:1
|
43 | struct Bogus<T = i32, U = i32>(TwoParams<T, U>) where TwoParams<T, U>: Trait;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `TwoParams<T, i32>`
|
= help: consider adding a `where TwoParams<T, i32>: Trait` bound
note: required by `Trait`
--> $DIR/type-check-defaults.rs:39:1
|
39 | trait Trait {}
| ^^^^^^^^^^^
error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/type-check-defaults.rs:48:1
--> $DIR/type-check-defaults.rs:37:1
|
48 | trait Base<T = String>: Super<T> { }
37 | 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:47:1
--> $DIR/type-check-defaults.rs:36:1
|
47 | trait Super<T: Copy> { }
36 | trait Super<T: Copy> { }
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 11 previous errors
error[E0277]: the trait bound `i32: Trait<U>` is not satisfied
--> $DIR/type-check-defaults.rs:41:1
|
41 | struct DefaultedLhs<U, V=i32>(U, V) where V: Trait<U>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait<U>` is not implemented for `i32`
|
note: required by `Trait`
--> $DIR/type-check-defaults.rs:40:1
|
40 | trait Trait<T> {}
| ^^^^^^^^^^^^^^
error: aborting due to 9 previous errors