WF checks on closure arguments.#151510
WF checks on closure arguments.#151510LorrensP-2158466 wants to merge 4 commits intorust-lang:mainfrom
Conversation
| error: lifetime may not live long enough | ||
| --> $DIR/check-wf-of-closure-args.rs:13:41 | ||
| | | ||
| LL | let _: for<'x> fn(MyTy<&'x str>) = |x| wf(x); | ||
| | ^ | ||
| | | | ||
| | has type `MyTy<&'1 str>` | ||
| | requires that `'1` must outlive `'static` | ||
|
|
||
| error: aborting due to 2 previous errors |
There was a problem hiding this comment.
I find that the error message is a bit worse now, compared to the old:
error[E0521]: borrowed data escapes outside of closure
--> src/lib.rs:10:44
|
10 | let _: for<'x> fn(MyTy<&'x str>) = |x| wf(x); // FAIL
| - ^^^^^
| | |
| | `x` escapes the closure body here
| | argument requires that `'1` must outlive `'static`
| `x` is a reference that is only valid in the closure body
| has type `MyTy<&'1 str>`
| | - - has type `&'1 i32` | ||
| | | | ||
| | has type `&Cell<&'2 i32>` | ||
| | has type `&'2 Cell<&i32>` |
There was a problem hiding this comment.
This also looks wrong, is it due to the removed normalization?
There was a problem hiding this comment.
I don't like the name right now, so TODO.
Also, this test, when run with current nightly, indeeds performs a use-after-free. But now we error on it, it can thus be removed to this:
use std::sync::OnceLock;
type Payload = Box<i32>;
static STORAGE: OnceLock<& ()> = OnceLock::new();
trait Store {}
impl Store for &'static Payload {}
struct MyTy<T: Store>(T);
trait IsFn {}
impl IsFn for for<'x> fn(&'x Payload) -> MyTy<&'x Payload> {}
fn bar<F: IsFn>(_: F) {}
fn main() {
bar::<for<'a> fn(&'a Payload) -> MyTy<&'a Payload>>(|x| unsafe {
std::mem::transmute::<&Payload, MyTy<&Payload>>(x)
});
}
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
CI x86_64-gnu-tools failed with an error I don't understand: |
615d765 to
734d270
Compare
|
@bors try |
This comment has been minimized.
This comment has been minimized.
WF checks on closure arguments.
|
@craterbot check |
|
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
☔ The latest upstream changes (presumably #151701) made this pull request unmergeable. Please resolve the merge conflicts. |
|
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
|
🎉 Experiment
Footnotes
|
|
Why was the |
Fixes #104478.
Enables WF checks on the arguments of a closure.
The now removed function
ascribe_user_type_skip_wfmentioned that skipping WF was done due to backwards compatibility reasons. We should probably run a crater-check and other things, right?r? @lcnr