Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move leak-check to during coherence, candidate eval #72493

Merged
merged 13 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add new tests from MCP and the tracking issue
  • Loading branch information
nikomatsakis committed Jun 22, 2020
commit be0d10f149579d3ed53507ff8c2f6511b56456f7
14 changes: 14 additions & 0 deletions src/test/ui/coherence/coherence-fn-implied-bounds.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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);
}