From 5848c27c7995eabe0db76eb7c1360c77e9fefba4 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 20 Jul 2022 10:22:16 -0400 Subject: [PATCH 1/4] make raw_eq precondition more restrictive --- library/core/src/array/equality.rs | 7 ++++--- library/core/src/intrinsics.rs | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/core/src/array/equality.rs b/library/core/src/array/equality.rs index 33f7f494e9d84..a85f13a4b9e80 100644 --- a/library/core/src/array/equality.rs +++ b/library/core/src/array/equality.rs @@ -173,13 +173,14 @@ macro_rules! is_raw_eq_comparable { )+}; } -// SAFETY: All the ordinary integer types allow all bit patterns as distinct values +// SAFETY: All the ordinary integer types have no padding, and are no poointers. is_raw_eq_comparable!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); -// SAFETY: bool and char have *niches*, but no *padding*, so this is sound +// SAFETY: bool and char have *niches*, but no *padding* (and these are not pointer types), so this +// is sound is_raw_eq_comparable!(bool, char); -// SAFETY: Similarly, the non-zero types have a niche, but no undef, +// SAFETY: Similarly, the non-zero types have a niche, but no undef and no pointers, // and they compare like their underlying numeric type. is_raw_eq_comparable!( NonZeroU8, diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 998f7be3f7396..565c32d688874 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2277,7 +2277,8 @@ extern "rust-intrinsic" { /// /// # Safety /// - /// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized. + /// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carries a + /// pointer value. /// Note that this is a stricter criterion than just the *values* being /// fully-initialized: if `T` has padding, it's UB to call this intrinsic. /// From 2d1c683112f6bacb0dbc06379d7b1d40a93d0523 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 20 Jul 2022 10:39:21 -0400 Subject: [PATCH 2/4] fix typo Co-authored-by: Marco Colombo --- library/core/src/array/equality.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/array/equality.rs b/library/core/src/array/equality.rs index a85f13a4b9e80..97300adb0097d 100644 --- a/library/core/src/array/equality.rs +++ b/library/core/src/array/equality.rs @@ -173,7 +173,7 @@ macro_rules! is_raw_eq_comparable { )+}; } -// SAFETY: All the ordinary integer types have no padding, and are no poointers. +// SAFETY: All the ordinary integer types have no padding, and are no pointers. is_raw_eq_comparable!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); // SAFETY: bool and char have *niches*, but no *padding* (and these are not pointer types), so this From d1cace5a976bb1f098d64e72861178d221987f98 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 10 Aug 2022 16:15:21 -0400 Subject: [PATCH 3/4] grammar Co-authored-by: Frank Steffahn --- library/core/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 565c32d688874..1bb70d513bdf8 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2277,7 +2277,7 @@ extern "rust-intrinsic" { /// /// # Safety /// - /// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carries a + /// It's UB to call this if any of the *bytes* in `*a` or `*b` are uninitialized or carry a /// pointer value. /// Note that this is a stricter criterion than just the *values* being /// fully-initialized: if `T` has padding, it's UB to call this intrinsic. From 338d7c2fb07da34abab1ca5bb4a8c40ff0b4d604 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 11 Aug 2022 07:37:22 -0400 Subject: [PATCH 4/4] more typos Co-authored-by: Nicholas Nethercote --- library/core/src/array/equality.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/array/equality.rs b/library/core/src/array/equality.rs index 97300adb0097d..b2c895f882c6a 100644 --- a/library/core/src/array/equality.rs +++ b/library/core/src/array/equality.rs @@ -173,7 +173,7 @@ macro_rules! is_raw_eq_comparable { )+}; } -// SAFETY: All the ordinary integer types have no padding, and are no pointers. +// SAFETY: All the ordinary integer types have no padding, and are not pointers. is_raw_eq_comparable!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); // SAFETY: bool and char have *niches*, but no *padding* (and these are not pointer types), so this