-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
2229: Handle capturing a reference into a repr packed struct #82878
Conversation
This comment has been minimized.
This comment has been minimized.
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.
r=me
@bors r+ |
📌 Commit efe0319f05bbccafe282bd6c6eed5bdff06edf1b has been approved by |
@bors r- I want to think about this layout call for one second |
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.
OK, one nit but i'm ready to land.
let pos = place.projections.iter().enumerate().position(|(i, p)| { | ||
let ty = place.ty_before_projection(i); | ||
|
||
match p.kind { |
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.
There are a lot of matches and ifs here. It'd be nice to have a comment indicating what you are looking for. Something like:
// Return true for fields of packed structs, unless those fields have alignment 1.
RFC 1240 states that it is unsafe to capture references into a packed-struct. This PR ensures that when a closure captures a precise path, we aren't violating this safety constraint. To acheive so we restrict the capture precision to the struct itself. An interesting edge case: ```rust struct Foo(String); let foo: Foo; let c = || { println!("{}", foo.0); let x = foo.0; } ``` Given how closures get desugared today, foo.0 will be moved into the closure, making the `println!`, safe. However this can be very subtle and also will be unsafe if the closure gets inline. Closes: rust-lang/project-rfc-2229#33
@nikomatsakis updated |
@bors r+ delegate+ |
📌 Commit 612a9b2 has been approved by |
✌️ @arora-aman can now approve this pull request |
…akis 2229: Handle capturing a reference into a repr packed struct RFC 1240 states that it is unsafe to capture references into a packed-struct. This PR ensures that when a closure captures a precise path, we aren't violating this safety constraint. To acheive so we restrict the capture precision to the struct itself. An interesting edge case where we decided to restrict precision: ```rust struct Foo(String); let foo: Foo; let c = || { println!("{}", foo.0); let x = foo.0; } ``` Given how closures get desugared today, foo.0 will be moved into the closure, making the `println!`, safe. However this can be very subtle and also will be unsafe if the closure gets inline. Closes: rust-lang/project-rfc-2229#33 r? `@nikomatsakis`
☀️ Test successful - checks-actions |
RFC 1240 states that it is unsafe to capture references into a
packed-struct. This PR ensures that when a closure captures a precise
path, we aren't violating this safety constraint.
To acheive so we restrict the capture precision to the struct itself.
An interesting edge case where we decided to restrict precision:
Given how closures get desugared today, foo.0 will be moved into the
closure, making the
println!
, safe. However this can be very subtleand also will be unsafe if the closure gets inline.
Closes: rust-lang/project-rfc-2229#33
r? @nikomatsakis