Skip to content

Commit 1db7193

Browse files
committed
address tmandry nits
1 parent cf2f7cc commit 1db7193

File tree

4 files changed

+14
-63
lines changed

4 files changed

+14
-63
lines changed

src/test/ui/coherence/coherence-subtyping.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,14 @@
11
// Test that two distinct impls which match subtypes of one another
22
// yield coherence errors (or not) depending on the variance.
33

4-
trait Contravariant {
4+
trait TheTrait {
55
fn foo(&self) { }
66
}
77

8-
impl Contravariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
8+
impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
99
}
1010

11-
impl Contravariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
12-
//~^ ERROR
13-
}
14-
15-
///////////////////////////////////////////////////////////////////////////
16-
17-
trait Covariant {
18-
fn foo(&self) { }
19-
}
20-
21-
impl Covariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
22-
}
23-
24-
impl Covariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
25-
//~^ ERROR
26-
}
27-
28-
///////////////////////////////////////////////////////////////////////////
29-
30-
trait Invariant {
31-
fn foo(&self) { }
32-
}
33-
34-
impl Invariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
35-
}
36-
37-
impl Invariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
11+
impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
3812
//~^ ERROR
3913
}
4014

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
error[E0119]: conflicting implementations of trait `Contravariant` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
1+
error[E0119]: conflicting implementations of trait `TheTrait` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
22
--> $DIR/coherence-subtyping.rs:11:1
33
|
4-
LL | impl Contravariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
5-
| -------------------------------------------------------------- first implementation here
4+
LL | impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
5+
| --------------------------------------------------------- first implementation here
66
...
7-
LL | impl Contravariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
7+
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
99

10-
error[E0119]: conflicting implementations of trait `Covariant` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
11-
--> $DIR/coherence-subtyping.rs:24:1
12-
|
13-
LL | impl Covariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
14-
| ---------------------------------------------------------- first implementation here
15-
...
16-
LL | impl Covariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
18-
19-
error[E0119]: conflicting implementations of trait `Invariant` for type `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`:
20-
--> $DIR/coherence-subtyping.rs:37:1
21-
|
22-
LL | impl Invariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
23-
| ---------------------------------------------------------- first implementation here
24-
...
25-
LL | impl Invariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
26-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
27-
28-
error: aborting due to 3 previous errors
10+
error: aborting due to previous error
2911

3012
For more information about this error, try `rustc --explain E0119`.

src/test/ui/hrtb/hrtb-exists-forall-fn.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33
// In particular, we test this pattern in trait solving, where it is not connected
44
// to any part of the source code.
55

6-
trait Trait<T> {}
7-
86
fn foo<'a>() -> fn(&'a u32) {
97
panic!()
108
}
119

1210
fn main() {
13-
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
11+
// Here, proving that `fn(&'a u32) <: for<'b> fn(&'b u32)`:
1412
//
15-
// - The impl provides the clause `forall<'a> { (): Trait<fn(&'a u32)> }`
16-
// - We instantiate `'a` existentially to get `(): Trait<fn(&?a u32)>`
17-
// - We unify `fn(&?a u32)` with `for<'b> fn(&'b u32)`
18-
// - This requires (among other things) instantiating `'b` universally,
19-
// yielding `fn(&!b u32)`, in a fresh universe U1
20-
// - So we get `?a = !b` but the universe U0 assigned to `?a` cannot name `!b`.
13+
// - instantiates `'b` with a placeholder `!b`,
14+
// - requires that `&!b u32 <: &'a u32` and hence that `!b: 'a`,
15+
// - but we can never know this.
2116

2217
let _: for<'b> fn(&'b u32) = foo(); //~ ERROR mismatched types
2318
}

src/test/ui/hrtb/hrtb-exists-forall-fn.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/hrtb-exists-forall-fn.rs:22:34
2+
--> $DIR/hrtb-exists-forall-fn.rs:17:34
33
|
44
LL | let _: for<'b> fn(&'b u32) = foo(); //~ ERROR mismatched types
55
| ^^^^^ one type is more general than the other

0 commit comments

Comments
 (0)