This repository was archived by the owner on Apr 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Handle #[repr(packed)]
with feature gate
#33
Closed
arora-aman opened this issue
Dec 4, 2020
· 3 comments
· Fixed by sexxi-goose/rust#49 or rust-lang/rust#82878
Closed
Handle #[repr(packed)]
with feature gate
#33
arora-aman opened this issue
Dec 4, 2020
· 3 comments
· Fixed by sexxi-goose/rust#49 or rust-lang/rust#82878
Comments
|
We only want to truncate if the alignment is not 1. eg: when using |
Note: There was an interesting case that we discussed on 2021-03-03. If you have a closure that accesses a packed field: #[repr(packed)] struct Foo { x: String }
let f: Foo;
let c = || {
let x = &f.x;
drop(f.x);
} This could conceivably be safe because the closure desugaring will move out of The workaround for users is to add |
Dylan-DPC-zz
pushed a commit
to Dylan-DPC-zz/rust
that referenced
this issue
Mar 12, 2021
…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`
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 13, 2021
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`
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: