Skip to content

Commit 93e2982

Browse files
committed
add new coherence tests and update the documentation
1 parent be0d10f commit 93e2982

5 files changed

+53
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Test that impls for these two types are considered ovelapping:
2+
//
3+
// * `for<'r> fn(fn(&'r u32))`
4+
// * `fn(fn(&'a u32)` where `'a` is free
5+
//
6+
// This is because, for `'a = 'static`, the two types overlap.
7+
// Effectively for them to be equal to you get:
8+
//
9+
// * `for<'r> fn(fn(&'r u32)) <: fn(fn(&'static u32))`
10+
// * true if `exists<'r> { 'r: 'static }` (obviously true)
11+
// * `fn(fn(&'static u32)) <: for<'r> fn(fn(&'r u32))`
12+
// * true if `forall<'r> { 'static: 'r }` (also true)
13+
14+
trait Trait {}
15+
16+
impl Trait for for<'r> fn(fn(&'r ())) {}
17+
impl<'a> Trait for fn(fn(&'a ())) {}
18+
//~^ ERROR conflicting implementations
19+
//
20+
// Note in particular that we do NOT get a future-compatibility warning
21+
// here. This is because the new leak-check proposed in [MCP 295] does not
22+
// "error" when these two types are equated.
23+
//
24+
// [MCP 295]: https://github.com/rust-lang/compiler-team/issues/295
25+
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0119]: conflicting implementations of trait `Trait` for type `for<'r> fn(fn(&'r ()))`:
2+
--> $DIR/coherence-fn-covariant-bound-vs-static.rs:14:1
3+
|
4+
LL | impl Trait for for<'r> fn(fn(&'r ())) {}
5+
| ------------------------------------- first implementation here
6+
LL | impl<'a> Trait for fn(fn(&'a ())) {}
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'r> fn(fn(&'r ()))`
8+
|
9+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0119`.

src/test/ui/coherence/coherence-fn-implied-bounds.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
// Example of coherence impls that we accept
1+
// Test that our leak-check is not smart enough to take implied bounds
2+
// into account (yet). Here we have two types that look like they
3+
// should not be equivalent, but because of the rules on implied
4+
// bounds we ought to know that, in fact, `'a = 'b` must always hold,
5+
// and hence they are.
6+
//
7+
// Rustc can't figure this out and hence it accepts the impls but
8+
// gives a future-compatibility warning (because we'd like to make
9+
// this an error someday).
10+
//
11+
// Note that while we would like to make this a hard error, we also
12+
// give the same warning for `coherence-wasm-bindgen.rs`, which ought
13+
// to be accepted.
214

315
#![deny(coherence_leak_check)]
416

src/test/ui/coherence/coherence-fn-inputs.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// * `'c` can be the intersection of `'a` and `'b` (and there is always an intersection)
1111
// * `'a` and `'b` can both be equal to `'c`
1212

13-
#![deny(coherence_leak_check)]
14-
1513
trait Trait {}
1614
impl Trait for for<'a, 'b> fn(&'a u32, &'b u32) {}
1715
impl Trait for for<'c> fn(&'c u32, &'c u32) {

src/test/ui/coherence/coherence-fn-inputs.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0119]: conflicting implementations of trait `Trait` for type `for<'a, 'b> fn(&'a u32, &'b u32)`:
2-
--> $DIR/coherence-fn-inputs.rs:17:1
2+
--> $DIR/coherence-fn-inputs.rs:15:1
33
|
44
LL | impl Trait for for<'a, 'b> fn(&'a u32, &'b u32) {}
55
| ----------------------------------------------- first implementation here

0 commit comments

Comments
 (0)