Skip to content

Commit 16a5234

Browse files
authored
Rollup merge of rust-lang#82525 - RalfJung:unaligned-ref-warn, r=petrochenkov
make unaligned_references future-incompat lint warn-by-default and also remove the safe_packed_borrows lint that it replaces. `std::ptr::addr_of!` has hit beta now and will hit stable in a month, so I propose we start fixing rust-lang#27060 for real: creating a reference to a field of a packed struct needs to eventually become a hard error; this PR makes it a warn-by-default future-incompat lint. (The lint already existed, this just raises its default level.) At the same time I removed the corresponding code from unsafety checking; really there's no reason an `unsafe` block should make any difference here. For references to packed fields outside `unsafe` blocks, this means `unaligned_refereces` replaces the previous `safe_packed_borrows` warning with a link to rust-lang#82523 (and no more talk about unsafe blocks making any difference). So behavior barely changes, the warning is just worded differently. For references to packed fields inside `unsafe` blocks, this PR shows a new future-incompat warning. Closes rust-lang#46043 because that lint no longer exists.
2 parents 04270c8 + 23427d8 commit 16a5234

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

core/src/ptr/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ pub const unsafe fn read<T>(src: *const T) -> T {
767767
/// unaligned: 0x01020304,
768768
/// };
769769
///
770+
/// #[allow(unaligned_references)]
770771
/// let v = unsafe {
771772
/// // Here we attempt to take the address of a 32-bit integer which is not aligned.
772773
/// let unaligned =
@@ -960,6 +961,7 @@ pub const unsafe fn write<T>(dst: *mut T, src: T) {
960961
/// let v = 0x01020304;
961962
/// let mut packed: Packed = unsafe { std::mem::zeroed() };
962963
///
964+
/// #[allow(unaligned_references)]
963965
/// let v = unsafe {
964966
/// // Here we attempt to take the address of a 32-bit integer which is not aligned.
965967
/// let unaligned =

0 commit comments

Comments
 (0)