-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
WF checks on closure arguments. #151510
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
base: main
Are you sure you want to change the base?
WF checks on closure arguments. #151510
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also looks wrong, is it due to the removed normalization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
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