Skip to content

Commit

Permalink
add new tests from MCP and the tracking issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jun 22, 2020
1 parent 3a68d56 commit be0d10f
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/ui/coherence/coherence-fn-implied-bounds.rs
@@ -0,0 +1,14 @@
// Example of coherence impls that we accept

#![deny(coherence_leak_check)]

trait Trait {}

impl Trait for for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32 {}

impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 {
//~^ ERROR conflicting implementations
//~| WARNING this was previously accepted by the compiler
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/coherence/coherence-fn-implied-bounds.stderr
@@ -0,0 +1,20 @@
error: conflicting implementations of trait `Trait` for type `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32`:
--> $DIR/coherence-fn-implied-bounds.rs:9:1
|
LL | impl Trait for for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32 {}
| ------------------------------------------------------------------ first implementation here
LL |
LL | impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32`
|
note: the lint level is defined here
--> $DIR/coherence-fn-implied-bounds.rs:3:9
|
LL | #![deny(coherence_leak_check)]
| ^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
= 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

27 changes: 27 additions & 0 deletions src/test/ui/coherence/coherence-fn-inputs.rs
@@ -0,0 +1,27 @@
// Test that we consider these two types completely equal:
//
// * `for<'a, 'b> fn(&'a u32, &'b u32)`
// * `for<'c> fn(&'c u32, &'c u32)`
//
// For a long time we considered these to be distinct types. But in fact they
// are equivalent, if you work through the implications of subtyping -- this is
// because:
//
// * `'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) {
//~^ 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() {}
13 changes: 13 additions & 0 deletions src/test/ui/coherence/coherence-fn-inputs.stderr
@@ -0,0 +1,13 @@
error[E0119]: conflicting implementations of trait `Trait` for type `for<'a, 'b> fn(&'a u32, &'b u32)`:
--> $DIR/coherence-fn-inputs.rs:17:1
|
LL | impl Trait for for<'a, 'b> fn(&'a u32, &'b u32) {}
| ----------------------------------------------- first implementation here
LL | impl Trait for for<'c> fn(&'c u32, &'c u32) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u32, &'b u32)`
|
= 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`.
21 changes: 21 additions & 0 deletions src/test/ui/coherence/coherence-free-vs-bound-region.rs
@@ -0,0 +1,21 @@
// Capture a coherence pattern from wasm-bindgen that we discovered as part of
// future-compatibility warning #56105. This pattern currently receives a lint
// warning but we probably want to support it long term.
//
// Key distinction: we are implementing once for `A` (take ownership) and one
// for `&A` (borrow).
//
// c.f. #56105

#![deny(coherence_leak_check)]

trait TheTrait {}

impl<'a> TheTrait for fn(&'a u8) {}

impl TheTrait for fn(&u8) {
//~^ ERROR conflicting implementations of trait
//~| WARNING this was previously accepted by the compiler
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/coherence/coherence-free-vs-bound-region.stderr
@@ -0,0 +1,20 @@
error: conflicting implementations of trait `TheTrait` for type `fn(&u8)`:
--> $DIR/coherence-free-vs-bound-region.rs:16:1
|
LL | impl<'a> TheTrait for fn(&'a u8) {}
| -------------------------------- first implementation here
LL |
LL | impl TheTrait for fn(&u8) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&u8)`
|
note: the lint level is defined here
--> $DIR/coherence-free-vs-bound-region.rs:10:9
|
LL | #![deny(coherence_leak_check)]
| ^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
= 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

37 changes: 37 additions & 0 deletions src/test/ui/coherence/coherence-wasm-bindgen.rs
@@ -0,0 +1,37 @@
// Capture a coherence pattern from wasm-bindgen that we discovered as part of
// future-compatibility warning #56105. This pattern currently receives a lint
// warning but we probably want to support it long term.
//
// Key distinction: we are implementing once for `A` (take ownership) and one
// for `&A` (borrow).
//
// c.f. #56105

#![deny(coherence_leak_check)]

trait IntoWasmAbi {
fn some_method(&self) {}
}

trait FromWasmAbi {}
trait RefFromWasmAbi {}
trait ReturnWasmAbi {}

impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(A) -> R + 'b)
where
A: FromWasmAbi,
R: ReturnWasmAbi,
{
}

// Explicitly writing the bound lifetime.
impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn for<'x> Fn(&'x A) -> R + 'b)
where
A: RefFromWasmAbi,
R: ReturnWasmAbi,
{
//~^^^^^ ERROR conflicting implementation
//~| WARNING this was previously accepted
}

fn main() {}
32 changes: 32 additions & 0 deletions src/test/ui/coherence/coherence-wasm-bindgen.stderr
@@ -0,0 +1,32 @@
error: conflicting implementations of trait `IntoWasmAbi` for type `&dyn std::ops::Fn(&_) -> _`:
--> $DIR/coherence-wasm-bindgen.rs:28:1
|
LL | / impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(A) -> R + 'b)
LL | | where
LL | | A: FromWasmAbi,
LL | | R: ReturnWasmAbi,
LL | | {
LL | | }
| |_- first implementation here
...
LL | / impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn for<'x> Fn(&'x A) -> R + 'b)
LL | | where
LL | | A: RefFromWasmAbi,
LL | | R: ReturnWasmAbi,
... |
LL | |
LL | | }
| |_^ conflicting implementation for `&dyn std::ops::Fn(&_) -> _`
|
note: the lint level is defined here
--> $DIR/coherence-wasm-bindgen.rs:10:9
|
LL | #![deny(coherence_leak_check)]
| ^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
= note: downstream crates may implement trait `FromWasmAbi` for type `&_`
= 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

13 changes: 13 additions & 0 deletions src/test/ui/hr-subtype/return-static.rs
@@ -0,0 +1,13 @@
// check-pass

fn make<T>() -> T {
panic!()
}

fn take<T>(x: T) {}

fn main() {
let x: for<'a> fn(&'a u32) -> _ = make();
let y: &'static u32 = x(&22);
take::<for<'b> fn(&'b u32) -> &'b u32>(x);
}

0 comments on commit be0d10f

Please sign in to comment.