1
Fork 0

add new coherence tests and update the documentation

This commit is contained in:
Niko Matsakis 2020-06-05 21:14:34 +00:00
parent be0d10f149
commit 93e29823a9
5 changed files with 53 additions and 4 deletions

View file

@ -0,0 +1,26 @@
// Test that impls for these two types are considered ovelapping:
//
// * `for<'r> fn(fn(&'r u32))`
// * `fn(fn(&'a u32)` where `'a` is free
//
// This is because, for `'a = 'static`, the two types overlap.
// Effectively for them to be equal to you get:
//
// * `for<'r> fn(fn(&'r u32)) <: fn(fn(&'static u32))`
// * true if `exists<'r> { 'r: 'static }` (obviously true)
// * `fn(fn(&'static u32)) <: for<'r> fn(fn(&'r u32))`
// * true if `forall<'r> { 'static: 'r }` (also true)
trait Trait {}
impl Trait for for<'r> fn(fn(&'r ())) {}
impl<'a> Trait for fn(fn(&'a ())) {}
//~^ ERROR conflicting implementations
//
// Note in particular that we do NOT get a future-compatibility warning
// here. This is because the new leak-check proposed in [MCP 295] does not
// "error" when these two types are equated.
//
// [MCP 295]: https://github.com/rust-lang/compiler-team/issues/295
fn main() {}

View file

@ -0,0 +1,13 @@
error[E0119]: conflicting implementations of trait `Trait` for type `for<'r> fn(fn(&'r ()))`:
--> $DIR/coherence-fn-covariant-bound-vs-static.rs:14:1
|
LL | impl Trait for for<'r> fn(fn(&'r ())) {}
| ------------------------------------- first implementation here
LL | impl<'a> Trait for fn(fn(&'a ())) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'r> fn(fn(&'r ()))`
|
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
error: aborting due to previous error
For more information about this error, try `rustc --explain E0119`.

View file

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

View file

@ -10,8 +10,6 @@
// * `'c` can be the intersection of `'a` and `'b` (and there is always an intersection)
// * `'a` and `'b` can both be equal to `'c`
#![deny(coherence_leak_check)]
trait Trait {}
impl Trait for for<'a, 'b> fn(&'a u32, &'b u32) {}
impl Trait for for<'c> fn(&'c u32, &'c u32) {

View file

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