Skip to content

Commit

Permalink
address tmandry nits
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 2, 2019
1 parent cf2f7cc commit 1db7193
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 63 deletions.
32 changes: 3 additions & 29 deletions src/test/ui/coherence/coherence-subtyping.rs
@@ -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
}

Expand Down
30 changes: 6 additions & 24 deletions src/test/ui/coherence/coherence-subtyping.stderr
@@ -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`.
13 changes: 4 additions & 9 deletions src/test/ui/hrtb/hrtb-exists-forall-fn.rs
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/test/ui/hrtb/hrtb-exists-forall-fn.stderr
@@ -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
Expand Down

0 comments on commit 1db7193

Please sign in to comment.