-
Notifications
You must be signed in to change notification settings - Fork 498
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
Remove obsolete note about soundness hole in type-layout.md #1367
Conversation
Issue rust-lang/rust#27060 has been resolved, so it is no longer possible to safely create unaligned pointers to packed struct fields.
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 for opening the PR! It would be good to get this cleaned up.
I was wondering if instead it would be good to include a note here that is more of a reminder about the things to be concerned about? Perhaps something along the following:
Note: References to unaligned fields are not allowed because it is [undefined behavior].
When fields are unaligned due to an alignment modifier, consider the following options for using references and dereferences:#[repr(packed)] struct Packed { f1: u8, f2: u16, } let mut e = Packed { f1: 1, f2: 2 }; // Instead of creating a reference to a field, copy the value to a local variable. let x = e.f2; // Or in situations like `println!` which creates a reference, use braces // to change it to a copy of the value. println!("{}", {e.f2}); // Or if you need a pointer, use the unaligned methods for reading and writing // instead of dereferencing the pointer directly. let ptr: *const u16 = std::ptr::addr_of!(e.f2); let value = unsafe { ptr.read_unaligned() }; let mut_ptr: *mut u16 = std::ptr::addr_of_mut!(e.f2); unsafe { mut_ptr.write_unaligned(3) }
As part of #1326, we also probably need to eventually specify the restrictions about creating unaligned references (probably in the pointers page?). Also, I don't think we ever define what "unaligned" means, which probably should be eventually covered.
I'm not sure if this particular place is the right place to get into all the specifics of what the rules are, though I haven't thought too much about how to organize it.
Also there is a link to 27060 at the bottom of the page that should be removed.
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.
Thanks!
Update books ## rust-lang/book 1 commits in 21cf840842bdf768a798869f06373c96c1cc5122..668c64760b5c7ea654facb4ba5fe9faddfda27cc 2023-06-29 13:50:36 UTC to 2023-06-29 13:50:36 UTC - Remove adjective about what kind of number this is ## rust-lang/edition-guide 2 commits in f63e578b92ff43e8cc38fcaa257b660f45c8a8c2..2751bdcef125468ea2ee006c11992cd1405aebe5 2023-07-10 14:29:51 UTC to 2023-07-08 18:05:44 UTC - Update a link to a section in the cargo workspaces. (rust-lang/edition-guide#283) - b'...' byte strings -> byte chars (rust-lang/edition-guide#282) ## rust-embedded/book 2 commits in f2aed2fe8e9f55508c86ba3aa4b6789b18a08a22..1e5556dd1b864109985d5871616ae6b9164bcead 2023-06-29 07:34:47 UTC to 2023-06-27 23:43:06 UTC - add constgebra to list of math crates (rust-embedded/book#358) - Switch to GHMQ (rust-embedded/book#357) ## rust-lang/nomicon 1 commits in c369e4b489332f8721fbae630354fa83385d457d..302b995bcb24b70fd883980fd174738c3a10b705 2023-07-05 16:08:32 UTC to 2023-07-05 16:08:32 UTC - Minor improvements (rust-lang/nomicon#414) ## rust-lang/reference 5 commits in 5ca365eac678cb0d41a20b3204546d6ed70c7171..1ea0178266b3f3f613b0fabdaf16a83961c99cdb 2023-07-08 22:11:07 UTC to 2023-06-26 16:51:55 UTC - Remove doc of unstable feature of never type (rust-lang/reference#1376) - Typo: 'assingee' to 'assignee' in expressions.md (rust-lang/reference#1377) - str type: make sentence more readable (rust-lang/reference#1374) - Remove obsolete note about soundness hole in type-layout.md (rust-lang/reference#1367) - Typo: 'a' to 'an' in destructors.md (rust-lang/reference#1371) ## rust-lang/rust-by-example 1 commits in 57636d6926762861f34e030d52ca25a71e95e5bf..8a87926a985ce32ca1fad1be4008ee161a0b91eb 2023-07-07 22:44:06 UTC to 2023-07-07 22:44:06 UTC - Hint for RGB color calculation (rust-lang/rust-by-example#1726) ## rust-lang/rustc-dev-guide 18 commits in 17fe3e9..b5a12d9 2023-07-09 14:50:50 UTC to 2023-06-28 04:55:24 UTC - fix: update link to function coverage (rust-lang/rustc-dev-guide#1727) - Fix a bug in getting-started.md (rust-lang/rustc-dev-guide#1726) - improve explanation of placing tests in separate file (rust-lang/rustc-dev-guide#1721) - various fixes/improvements to Contributing chapter (rust-lang/rustc-dev-guide#1723) - ty::ConstKind has moved (rust-lang/rustc-dev-guide#1724) - document `./x test --rustc-args` option (rust-lang/rustc-dev-guide#1719) - tests/run-make files have moved (rust-lang/rustc-dev-guide#1716) - replace dead link (rust-lang/rustc-dev-guide#1717) - fix link (rust-lang/rustc-dev-guide#1718) - update link (rust-lang/rustc-dev-guide#1709) - typo (rust-lang/rustc-dev-guide#1706) - OwningRef exists no more (rust-lang/rustc-dev-guide#1715) - Try to avoid confusion (rust-lang/rustc-dev-guide#1713) - Issue1707 doc simply use x (rust-lang/rustc-dev-guide#1710) - include rustc-dev-guide's own issues in suggested search (rust-lang/rustc-dev-guide#1708) - Improve feature gate and x.py docs (rust-lang/rustc-dev-guide#1701) - Fix some links (rust-lang/rustc-dev-guide#1705) - Define more lint terms. (rust-lang/rustc-dev-guide#1681)
Update books ## rust-lang/book 1 commits in 21cf840842bdf768a798869f06373c96c1cc5122..668c64760b5c7ea654facb4ba5fe9faddfda27cc 2023-06-29 13:50:36 UTC to 2023-06-29 13:50:36 UTC - Remove adjective about what kind of number this is ## rust-lang/edition-guide 2 commits in f63e578b92ff43e8cc38fcaa257b660f45c8a8c2..2751bdcef125468ea2ee006c11992cd1405aebe5 2023-07-10 14:29:51 UTC to 2023-07-08 18:05:44 UTC - Update a link to a section in the cargo workspaces. (rust-lang/edition-guide#283) - b'...' byte strings -> byte chars (rust-lang/edition-guide#282) ## rust-embedded/book 2 commits in f2aed2fe8e9f55508c86ba3aa4b6789b18a08a22..1e5556dd1b864109985d5871616ae6b9164bcead 2023-06-29 07:34:47 UTC to 2023-06-27 23:43:06 UTC - add constgebra to list of math crates (rust-embedded/book#358) - Switch to GHMQ (rust-embedded/book#357) ## rust-lang/nomicon 1 commits in c369e4b489332f8721fbae630354fa83385d457d..302b995bcb24b70fd883980fd174738c3a10b705 2023-07-05 16:08:32 UTC to 2023-07-05 16:08:32 UTC - Minor improvements (rust-lang/nomicon#414) ## rust-lang/reference 5 commits in 5ca365eac678cb0d41a20b3204546d6ed70c7171..1ea0178266b3f3f613b0fabdaf16a83961c99cdb 2023-07-08 22:11:07 UTC to 2023-06-26 16:51:55 UTC - Remove doc of unstable feature of never type (rust-lang/reference#1376) - Typo: 'assingee' to 'assignee' in expressions.md (rust-lang/reference#1377) - str type: make sentence more readable (rust-lang/reference#1374) - Remove obsolete note about soundness hole in type-layout.md (rust-lang/reference#1367) - Typo: 'a' to 'an' in destructors.md (rust-lang/reference#1371) ## rust-lang/rust-by-example 1 commits in 57636d6926762861f34e030d52ca25a71e95e5bf..8a87926a985ce32ca1fad1be4008ee161a0b91eb 2023-07-07 22:44:06 UTC to 2023-07-07 22:44:06 UTC - Hint for RGB color calculation (rust-lang/rust-by-example#1726) ## rust-lang/rustc-dev-guide 18 commits in 17fe3e9..b5a12d9 2023-07-09 14:50:50 UTC to 2023-06-28 04:55:24 UTC - fix: update link to function coverage (rust-lang/rustc-dev-guide#1727) - Fix a bug in getting-started.md (rust-lang/rustc-dev-guide#1726) - improve explanation of placing tests in separate file (rust-lang/rustc-dev-guide#1721) - various fixes/improvements to Contributing chapter (rust-lang/rustc-dev-guide#1723) - ty::ConstKind has moved (rust-lang/rustc-dev-guide#1724) - document `./x test --rustc-args` option (rust-lang/rustc-dev-guide#1719) - tests/run-make files have moved (rust-lang/rustc-dev-guide#1716) - replace dead link (rust-lang/rustc-dev-guide#1717) - fix link (rust-lang/rustc-dev-guide#1718) - update link (rust-lang/rustc-dev-guide#1709) - typo (rust-lang/rustc-dev-guide#1706) - OwningRef exists no more (rust-lang/rustc-dev-guide#1715) - Try to avoid confusion (rust-lang/rustc-dev-guide#1713) - Issue1707 doc simply use x (rust-lang/rustc-dev-guide#1710) - include rustc-dev-guide's own issues in suggested search (rust-lang/rustc-dev-guide#1708) - Improve feature gate and x.py docs (rust-lang/rustc-dev-guide#1701) - Fix some links (rust-lang/rustc-dev-guide#1705) - Define more lint terms. (rust-lang/rustc-dev-guide#1681)
Issue rust-lang/rust#27060 has been resolved, so it is no longer possible to safely create unaligned pointers to packed struct fields.