add new tests from MCP and the tracking issue
This commit is contained in:
parent
3a68d56de3
commit
be0d10f149
9 changed files with 197 additions and 0 deletions
14
src/test/ui/coherence/coherence-fn-implied-bounds.rs
Normal file
14
src/test/ui/coherence/coherence-fn-implied-bounds.rs
Normal file
|
@ -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
src/test/ui/coherence/coherence-fn-implied-bounds.stderr
Normal file
20
src/test/ui/coherence/coherence-fn-implied-bounds.stderr
Normal file
|
@ -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
src/test/ui/coherence/coherence-fn-inputs.rs
Normal file
27
src/test/ui/coherence/coherence-fn-inputs.rs
Normal file
|
@ -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
src/test/ui/coherence/coherence-fn-inputs.stderr
Normal file
13
src/test/ui/coherence/coherence-fn-inputs.stderr
Normal file
|
@ -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
src/test/ui/coherence/coherence-free-vs-bound-region.rs
Normal file
21
src/test/ui/coherence/coherence-free-vs-bound-region.rs
Normal file
|
@ -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
src/test/ui/coherence/coherence-free-vs-bound-region.stderr
Normal file
20
src/test/ui/coherence/coherence-free-vs-bound-region.stderr
Normal file
|
@ -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
src/test/ui/coherence/coherence-wasm-bindgen.rs
Normal file
37
src/test/ui/coherence/coherence-wasm-bindgen.rs
Normal file
|
@ -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
src/test/ui/coherence/coherence-wasm-bindgen.stderr
Normal file
32
src/test/ui/coherence/coherence-wasm-bindgen.stderr
Normal file
|
@ -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
src/test/ui/hr-subtype/return-static.rs
Normal file
13
src/test/ui/hr-subtype/return-static.rs
Normal file
|
@ -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);
|
||||
}
|
Loading…
Add table
Reference in a new issue