Skip to content

Commit be0d10f

Browse files
committed
add new tests from MCP and the tracking issue
1 parent 3a68d56 commit be0d10f

9 files changed

+197
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Example of coherence impls that we accept
2+
3+
#![deny(coherence_leak_check)]
4+
5+
trait Trait {}
6+
7+
impl Trait for for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32 {}
8+
9+
impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 {
10+
//~^ ERROR conflicting implementations
11+
//~| WARNING this was previously accepted by the compiler
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: conflicting implementations of trait `Trait` for type `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32`:
2+
--> $DIR/coherence-fn-implied-bounds.rs:9:1
3+
|
4+
LL | impl Trait for for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32 {}
5+
| ------------------------------------------------------------------ first implementation here
6+
LL |
7+
LL | impl Trait for for<'c> fn(&'c &'c u32, &'c &'c u32) -> &'c u32 {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a &'b u32, &'b &'a u32) -> &'b u32`
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/coherence-fn-implied-bounds.rs:3:9
12+
|
13+
LL | #![deny(coherence_leak_check)]
14+
| ^^^^^^^^^^^^^^^^^^^^
15+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
16+
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
17+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
18+
19+
error: aborting due to previous error
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Test that we consider these two types completely equal:
2+
//
3+
// * `for<'a, 'b> fn(&'a u32, &'b u32)`
4+
// * `for<'c> fn(&'c u32, &'c u32)`
5+
//
6+
// For a long time we considered these to be distinct types. But in fact they
7+
// are equivalent, if you work through the implications of subtyping -- this is
8+
// because:
9+
//
10+
// * `'c` can be the intersection of `'a` and `'b` (and there is always an intersection)
11+
// * `'a` and `'b` can both be equal to `'c`
12+
13+
#![deny(coherence_leak_check)]
14+
15+
trait Trait {}
16+
impl Trait for for<'a, 'b> fn(&'a u32, &'b u32) {}
17+
impl Trait for for<'c> fn(&'c u32, &'c u32) {
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+
27+
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<'a, 'b> fn(&'a u32, &'b u32)`:
2+
--> $DIR/coherence-fn-inputs.rs:17:1
3+
|
4+
LL | impl Trait for for<'a, 'b> fn(&'a u32, &'b u32) {}
5+
| ----------------------------------------------- first implementation here
6+
LL | impl Trait for for<'c> fn(&'c u32, &'c u32) {
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u32, &'b u32)`
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`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Capture a coherence pattern from wasm-bindgen that we discovered as part of
2+
// future-compatibility warning #56105. This pattern currently receives a lint
3+
// warning but we probably want to support it long term.
4+
//
5+
// Key distinction: we are implementing once for `A` (take ownership) and one
6+
// for `&A` (borrow).
7+
//
8+
// c.f. #56105
9+
10+
#![deny(coherence_leak_check)]
11+
12+
trait TheTrait {}
13+
14+
impl<'a> TheTrait for fn(&'a u8) {}
15+
16+
impl TheTrait for fn(&u8) {
17+
//~^ ERROR conflicting implementations of trait
18+
//~| WARNING this was previously accepted by the compiler
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: conflicting implementations of trait `TheTrait` for type `fn(&u8)`:
2+
--> $DIR/coherence-free-vs-bound-region.rs:16:1
3+
|
4+
LL | impl<'a> TheTrait for fn(&'a u8) {}
5+
| -------------------------------- first implementation here
6+
LL |
7+
LL | impl TheTrait for fn(&u8) {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `fn(&u8)`
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/coherence-free-vs-bound-region.rs:10:9
12+
|
13+
LL | #![deny(coherence_leak_check)]
14+
| ^^^^^^^^^^^^^^^^^^^^
15+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
16+
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
17+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
18+
19+
error: aborting due to previous error
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Capture a coherence pattern from wasm-bindgen that we discovered as part of
2+
// future-compatibility warning #56105. This pattern currently receives a lint
3+
// warning but we probably want to support it long term.
4+
//
5+
// Key distinction: we are implementing once for `A` (take ownership) and one
6+
// for `&A` (borrow).
7+
//
8+
// c.f. #56105
9+
10+
#![deny(coherence_leak_check)]
11+
12+
trait IntoWasmAbi {
13+
fn some_method(&self) {}
14+
}
15+
16+
trait FromWasmAbi {}
17+
trait RefFromWasmAbi {}
18+
trait ReturnWasmAbi {}
19+
20+
impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(A) -> R + 'b)
21+
where
22+
A: FromWasmAbi,
23+
R: ReturnWasmAbi,
24+
{
25+
}
26+
27+
// Explicitly writing the bound lifetime.
28+
impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn for<'x> Fn(&'x A) -> R + 'b)
29+
where
30+
A: RefFromWasmAbi,
31+
R: ReturnWasmAbi,
32+
{
33+
//~^^^^^ ERROR conflicting implementation
34+
//~| WARNING this was previously accepted
35+
}
36+
37+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: conflicting implementations of trait `IntoWasmAbi` for type `&dyn std::ops::Fn(&_) -> _`:
2+
--> $DIR/coherence-wasm-bindgen.rs:28:1
3+
|
4+
LL | / impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn Fn(A) -> R + 'b)
5+
LL | | where
6+
LL | | A: FromWasmAbi,
7+
LL | | R: ReturnWasmAbi,
8+
LL | | {
9+
LL | | }
10+
| |_- first implementation here
11+
...
12+
LL | / impl<'a, 'b, A, R> IntoWasmAbi for &'a (dyn for<'x> Fn(&'x A) -> R + 'b)
13+
LL | | where
14+
LL | | A: RefFromWasmAbi,
15+
LL | | R: ReturnWasmAbi,
16+
... |
17+
LL | |
18+
LL | | }
19+
| |_^ conflicting implementation for `&dyn std::ops::Fn(&_) -> _`
20+
|
21+
note: the lint level is defined here
22+
--> $DIR/coherence-wasm-bindgen.rs:10:9
23+
|
24+
LL | #![deny(coherence_leak_check)]
25+
| ^^^^^^^^^^^^^^^^^^^^
26+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
28+
= note: downstream crates may implement trait `FromWasmAbi` for type `&_`
29+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
30+
31+
error: aborting due to previous error
32+
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
3+
fn make<T>() -> T {
4+
panic!()
5+
}
6+
7+
fn take<T>(x: T) {}
8+
9+
fn main() {
10+
let x: for<'a> fn(&'a u32) -> _ = make();
11+
let y: &'static u32 = x(&22);
12+
take::<for<'b> fn(&'b u32) -> &'b u32>(x);
13+
}

0 commit comments

Comments
 (0)