address tmandry nits

This commit is contained in:
Niko Matsakis 2018-11-19 10:47:34 -05:00
parent cf2f7cccb4
commit 1db7193162
4 changed files with 14 additions and 63 deletions

View file

@ -1,40 +1,14 @@
// Test that two distinct impls which match subtypes of one another
// yield coherence errors (or not) depending on the variance.
trait Contravariant {
trait TheTrait {
fn foo(&self) { }
}
impl Contravariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
}
impl Contravariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
//~^ ERROR
}
///////////////////////////////////////////////////////////////////////////
trait Covariant {
fn foo(&self) { }
}
impl Covariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
}
impl Covariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
//~^ ERROR
}
///////////////////////////////////////////////////////////////////////////
trait Invariant {
fn foo(&self) { }
}
impl Invariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
}
impl Invariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
//~^ ERROR
}

View file

@ -1,30 +1,12 @@
error[E0119]: conflicting implementations of trait `Contravariant` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
error[E0119]: conflicting implementations of trait `TheTrait` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
--> $DIR/coherence-subtyping.rs:11:1
|
LL | impl Contravariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
| -------------------------------------------------------------- first implementation here
LL | impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
| --------------------------------------------------------- first implementation here
...
LL | impl Contravariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
error[E0119]: conflicting implementations of trait `Covariant` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
--> $DIR/coherence-subtyping.rs:24:1
|
LL | impl Covariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
| ---------------------------------------------------------- first implementation here
...
LL | impl Covariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
error[E0119]: conflicting implementations of trait `Invariant` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
--> $DIR/coherence-subtyping.rs:37:1
|
LL | impl Invariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
| ---------------------------------------------------------- first implementation here
...
LL | impl Invariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
error: aborting due to 3 previous errors
error: aborting due to previous error
For more information about this error, try `rustc --explain E0119`.

View file

@ -3,21 +3,16 @@
// In particular, we test this pattern in trait solving, where it is not connected
// to any part of the source code.
trait Trait<T> {}
fn foo<'a>() -> fn(&'a u32) {
panic!()
}
fn main() {
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
// Here, proving that `fn(&'a u32) <: for<'b> fn(&'b u32)`:
//
// - The impl provides the clause `forall<'a> { (): Trait<fn(&'a u32)> }`
// - We instantiate `'a` existentially to get `(): Trait<fn(&?a u32)>`
// - We unify `fn(&?a u32)` with `for<'b> fn(&'b u32)`
// - This requires (among other things) instantiating `'b` universally,
// yielding `fn(&!b u32)`, in a fresh universe U1
// - So we get `?a = !b` but the universe U0 assigned to `?a` cannot name `!b`.
// - instantiates `'b` with a placeholder `!b`,
// - requires that `&!b u32 <: &'a u32` and hence that `!b: 'a`,
// - but we can never know this.
let _: for<'b> fn(&'b u32) = foo(); //~ ERROR mismatched types
}

View file

@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/hrtb-exists-forall-fn.rs:22:34
--> $DIR/hrtb-exists-forall-fn.rs:17:34
|
LL | let _: for<'b> fn(&'b u32) = foo(); //~ ERROR mismatched types
| ^^^^^ one type is more general than the other