From d302f61b8a49bdc2629aa90d28d75c3ec633819f Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 29 May 2023 10:33:37 -0400 Subject: [PATCH 1/4] Swap out CURRENT_RUSTC_VERSION to 1.71.0 --- compiler/rustc_feature/src/accepted.rs | 4 ++-- compiler/rustc_feature/src/active.rs | 10 ++++----- library/alloc/src/string.rs | 2 +- library/core/src/ffi/c_str.rs | 4 ++-- library/core/src/hash/mod.rs | 2 +- library/core/src/intrinsics.rs | 2 +- library/core/src/num/nonzero.rs | 28 ++++++++++++------------- library/core/src/ptr/const_ptr.rs | 4 ++-- library/core/src/ptr/mod.rs | 4 ++-- library/core/src/ptr/mut_ptr.rs | 4 ++-- library/core/src/slice/mod.rs | 2 +- library/core/src/tuple.rs | 4 ++-- library/std/src/os/windows/io/handle.rs | 6 +++--- library/std/src/os/windows/io/socket.rs | 6 +++--- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 5b2e4d15dfebe..0170d52e82a2e 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -131,7 +131,7 @@ declare_features! ( /// Allows `crate` in paths. (accepted, crate_in_paths, "1.30.0", Some(45477), None), /// Allows using `#[debugger_visualizer]` attribute. - (accepted, debugger_visualizer, "CURRENT_RUSTC_VERSION", Some(95939), None), + (accepted, debugger_visualizer, "1.71.0", Some(95939), None), /// Allows rustc to inject a default alloc_error_handler (accepted, default_alloc_error_handler, "1.68.0", Some(66741), None), /// Allows using assigning a default type to type parameters in algebraic data type definitions. @@ -281,7 +281,7 @@ declare_features! ( /// Allows use of the postfix `?` operator in expressions. (accepted, question_mark, "1.13.0", Some(31436), None), /// Allows the use of raw-dylibs (RFC 2627). - (accepted, raw_dylib, "CURRENT_RUSTC_VERSION", Some(58713), None), + (accepted, raw_dylib, "1.71.0", Some(58713), None), /// Allows keywords to be escaped for use as identifiers. (accepted, raw_identifiers, "1.30.0", Some(48589), None), /// Allows relaxing the coherence rules such that diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 57e55752027c7..dde9890dfa5d6 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -165,7 +165,7 @@ declare_features! ( /// Allows the `multiple_supertrait_upcastable` lint. (active, multiple_supertrait_upcastable, "1.69.0", None, None), /// Allow negative trait bounds. This is an internal-only feature for testing the trait solver! - (incomplete, negative_bounds, "CURRENT_RUSTC_VERSION", None, None), + (incomplete, negative_bounds, "1.71.0", None, None), /// Allows using `#[omit_gdb_pretty_printer_section]`. (active, omit_gdb_pretty_printer_section, "1.5.0", None, None), /// Allows using `#[prelude_import]` on glob `use` items. @@ -314,15 +314,15 @@ declare_features! ( /// Allows async functions to be declared, implemented, and used in traits. (active, async_fn_in_trait, "1.66.0", Some(91611), None), /// Allows builtin # foo() syntax - (active, builtin_syntax, "CURRENT_RUSTC_VERSION", Some(110680), None), + (active, builtin_syntax, "1.71.0", Some(110680), None), /// Allows `c"foo"` literals. - (active, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None), + (active, c_str_literals, "1.71.0", Some(105723), None), /// Treat `extern "C"` function as nounwind. (active, c_unwind, "1.52.0", Some(74990), None), /// Allows using C-variadics. (active, c_variadic, "1.34.0", Some(44930), None), /// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour. - (active, cfg_overflow_checks, "CURRENT_RUSTC_VERSION", Some(111466), None), + (active, cfg_overflow_checks, "1.71.0", Some(111466), None), /// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used. (active, cfg_sanitize, "1.41.0", Some(39699), None), /// Allows `cfg(target_abi = "...")`. @@ -338,7 +338,7 @@ declare_features! ( /// Allow conditional compilation depending on rust version (active, cfg_version, "1.45.0", Some(64796), None), /// Allows to use the `#[cfi_encoding = ""]` attribute. - (active, cfi_encoding, "CURRENT_RUSTC_VERSION", Some(89653), None), + (active, cfi_encoding, "1.71.0", Some(89653), None), /// Allows `for<...>` on closures and generators. (active, closure_lifetime_binder, "1.64.0", Some(97362), None), /// Allows `#[track_caller]` on closures and generators. diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index c524d4c036709..59e3f887b5232 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2624,7 +2624,7 @@ impl ToString for String { } #[cfg(not(no_global_oom_handling))] -#[stable(feature = "fmt_arguments_to_string_specialization", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "fmt_arguments_to_string_specialization", since = "1.71.0")] impl ToString for fmt::Arguments<'_> { #[inline] fn to_string(&self) -> String { diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 201bacb28c7ee..e1e1a9b408d23 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -531,8 +531,8 @@ impl CStr { /// # } /// ``` #[inline] - #[stable(feature = "cstr_is_empty", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "cstr_is_empty", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "cstr_is_empty", since = "1.71.0")] + #[rustc_const_stable(feature = "cstr_is_empty", since = "1.71.0")] pub const fn is_empty(&self) -> bool { // SAFETY: We know there is at least one byte; for empty strings it // is the NUL terminator. diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index ca7c0772de86e..794a57f09226c 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -695,7 +695,7 @@ pub trait BuildHasher { /// bh.hash_one(&OrderAmbivalentPair(2, 10)) /// ); /// ``` - #[stable(feature = "build_hasher_simple_hash_one", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "build_hasher_simple_hash_one", since = "1.71.0")] fn hash_one(&self, x: T) -> u64 where Self: Sized, diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 23ded42fa6679..f5c5dd29f505a 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2260,7 +2260,7 @@ extern "rust-intrinsic" { /// This intrinsic can *only* be called where the pointer is a local without /// projections (`read_via_copy(ptr)`, not `read_via_copy(*ptr)`) so that it /// trivially obeys runtime-MIR rules about derefs in operands. - #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[rustc_nounwind] pub fn read_via_copy(ptr: *const T) -> T; diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 38a1c42d9e825..7f06e170ad0f0 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -769,8 +769,8 @@ macro_rules! nonzero_signed_operations { /// ``` #[must_use] #[inline] - #[stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "nonzero_negation_ops", since = "1.71.0")] + #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")] pub const fn is_positive(self) -> bool { self.get().is_positive() } @@ -794,8 +794,8 @@ macro_rules! nonzero_signed_operations { /// ``` #[must_use] #[inline] - #[stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "nonzero_negation_ops", since = "1.71.0")] + #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")] pub const fn is_negative(self) -> bool { self.get().is_negative() } @@ -819,8 +819,8 @@ macro_rules! nonzero_signed_operations { /// # } /// ``` #[inline] - #[stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "nonzero_negation_ops", since = "1.71.0")] + #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")] pub const fn checked_neg(self) -> Option<$Ty> { if let Some(result) = self.get().checked_neg() { // SAFETY: negation of nonzero cannot yield zero values. @@ -851,8 +851,8 @@ macro_rules! nonzero_signed_operations { /// # } /// ``` #[inline] - #[stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "nonzero_negation_ops", since = "1.71.0")] + #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")] pub const fn overflowing_neg(self) -> ($Ty, bool) { let (result, overflow) = self.get().overflowing_neg(); // SAFETY: negation of nonzero cannot yield zero values. @@ -884,8 +884,8 @@ macro_rules! nonzero_signed_operations { /// # } /// ``` #[inline] - #[stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "nonzero_negation_ops", since = "1.71.0")] + #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")] pub const fn saturating_neg(self) -> $Ty { if let Some(result) = self.checked_neg() { return result; @@ -916,8 +916,8 @@ macro_rules! nonzero_signed_operations { /// # } /// ``` #[inline] - #[stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] - #[rustc_const_stable(feature = "nonzero_negation_ops", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "nonzero_negation_ops", since = "1.71.0")] + #[rustc_const_stable(feature = "nonzero_negation_ops", since = "1.71.0")] pub const fn wrapping_neg(self) -> $Ty { let result = self.get().wrapping_neg(); // SAFETY: negation of nonzero cannot yield zero values. @@ -925,7 +925,7 @@ macro_rules! nonzero_signed_operations { } } - #[stable(feature = "signed_nonzero_neg", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] impl Neg for $Ty { type Output = $Ty; @@ -937,7 +937,7 @@ macro_rules! nonzero_signed_operations { } forward_ref_unop! { impl Neg, neg for $Ty, - #[stable(feature = "signed_nonzero_neg", since = "CURRENT_RUSTC_VERSION")] } + #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] } )+ } } diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 5ee1b5e4afc78..6e1e862d3cd49 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1195,7 +1195,7 @@ impl *const T { /// /// [`ptr::read`]: crate::ptr::read() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[inline] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read(self) -> T @@ -1236,7 +1236,7 @@ impl *const T { /// /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[inline] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read_unaligned(self) -> T diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index ff9fa48f31136..d0cb2f715d067 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1139,7 +1139,7 @@ pub const unsafe fn replace(dst: *mut T, mut src: T) -> T { /// [valid]: self#safety #[inline] #[stable(feature = "rust1", since = "1.0.0")] -#[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] +#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[rustc_allow_const_fn_unstable(const_mut_refs, const_maybe_uninit_as_mut_ptr)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read(src: *const T) -> T { @@ -1256,7 +1256,7 @@ pub const unsafe fn read(src: *const T) -> T { /// ``` #[inline] #[stable(feature = "ptr_unaligned", since = "1.17.0")] -#[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] +#[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[rustc_allow_const_fn_unstable(const_mut_refs, const_maybe_uninit_as_mut_ptr)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read_unaligned(src: *const T) -> T { diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 5edd291fb76aa..2fe5164c3f060 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -1305,7 +1305,7 @@ impl *mut T { /// /// [`ptr::read`]: crate::ptr::read() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read(self) -> T @@ -1346,7 +1346,7 @@ impl *mut T { /// /// [`ptr::read_unaligned`]: crate::ptr::read_unaligned() #[stable(feature = "pointer_methods", since = "1.26.0")] - #[rustc_const_stable(feature = "const_ptr_read", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_ptr_read", since = "1.71.0")] #[inline(always)] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces pub const unsafe fn read_unaligned(self) -> T diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 1f19555522974..ea0181e35ac8e 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -1854,7 +1854,7 @@ impl [T] { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_slice_split_at_not_mut", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "const_slice_split_at_not_mut", since = "1.71.0")] #[rustc_allow_const_fn_unstable(slice_split_at_unchecked)] #[inline] #[track_caller] diff --git a/library/core/src/tuple.rs b/library/core/src/tuple.rs index 172e5fccb61aa..a1388dfeee643 100644 --- a/library/core/src/tuple.rs +++ b/library/core/src/tuple.rs @@ -100,7 +100,7 @@ macro_rules! tuple_impls { } } - #[stable(feature = "array_tuple_conv", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "array_tuple_conv", since = "1.71.0")] impl From<[T; ${count(T)}]> for ($(${ignore(T)} T,)+) { #[inline] #[allow(non_snake_case)] @@ -110,7 +110,7 @@ macro_rules! tuple_impls { } } - #[stable(feature = "array_tuple_conv", since = "CURRENT_RUSTC_VERSION")] + #[stable(feature = "array_tuple_conv", since = "1.71.0")] impl From<($(${ignore(T)} T,)+)> for [T; ${count(T)}] { #[inline] #[allow(non_snake_case)] diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index cbf8209a5ad43..274af08a3881c 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -437,7 +437,7 @@ impl AsHandle for &mut T { } } -#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "as_windows_ptrs", since = "1.71.0")] /// This impl allows implementing traits that require `AsHandle` on Arc. /// ``` /// # #[cfg(windows)] mod group_cfg { @@ -457,7 +457,7 @@ impl AsHandle for crate::sync::Arc { } } -#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl AsHandle for crate::rc::Rc { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { @@ -465,7 +465,7 @@ impl AsHandle for crate::rc::Rc { } } -#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl AsHandle for Box { #[inline] fn as_handle(&self) -> BorrowedHandle<'_> { diff --git a/library/std/src/os/windows/io/socket.rs b/library/std/src/os/windows/io/socket.rs index 0c90d55c024fb..6359835cad5d9 100644 --- a/library/std/src/os/windows/io/socket.rs +++ b/library/std/src/os/windows/io/socket.rs @@ -254,7 +254,7 @@ impl AsSocket for &mut T { } } -#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "as_windows_ptrs", since = "1.71.0")] /// This impl allows implementing traits that require `AsSocket` on Arc. /// ``` /// # #[cfg(windows)] mod group_cfg { @@ -274,7 +274,7 @@ impl AsSocket for crate::sync::Arc { } } -#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl AsSocket for crate::rc::Rc { #[inline] fn as_socket(&self) -> BorrowedSocket<'_> { @@ -282,7 +282,7 @@ impl AsSocket for crate::rc::Rc { } } -#[stable(feature = "as_windows_ptrs", since = "CURRENT_RUSTC_VERSION")] +#[stable(feature = "as_windows_ptrs", since = "1.71.0")] impl AsSocket for Box { #[inline] fn as_socket(&self) -> BorrowedSocket<'_> { From fe18edca5ebe7dda7b4167e53b271bf5bb7db761 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 29 May 2023 10:34:01 -0400 Subject: [PATCH 2/4] Switch to beta channel --- src/ci/channel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/channel b/src/ci/channel index bf867e0ae5b6c..65b2df87f7df3 100644 --- a/src/ci/channel +++ b/src/ci/channel @@ -1 +1 @@ -nightly +beta From 3af6f2eeef039e8819defc210d4cad91eae88cc8 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 27 May 2023 14:52:14 -0400 Subject: [PATCH 3/4] Add a test for misaligned pointer derefs inside addr_of! --- tests/ui/mir/addrof_alignment.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/ui/mir/addrof_alignment.rs diff --git a/tests/ui/mir/addrof_alignment.rs b/tests/ui/mir/addrof_alignment.rs new file mode 100644 index 0000000000000..892638bfb92bd --- /dev/null +++ b/tests/ui/mir/addrof_alignment.rs @@ -0,0 +1,15 @@ +// run-pass +// ignore-wasm32-bare: No panic messages +// compile-flags: -C debug-assertions + +struct Misalignment { + a: u32, +} + +fn main() { + let items: [Misalignment; 2] = [Misalignment { a: 0 }, Misalignment { a: 1 }]; + unsafe { + let ptr: *const Misalignment = items.as_ptr().cast::().add(1).cast::(); + let _ptr = core::ptr::addr_of!((*ptr).a); + } +} From f4e937955c630b72dc958b19574ffbc9e329cacf Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Sat, 27 May 2023 14:52:41 -0400 Subject: [PATCH 4/4] Exclude Rvalue::AddressOf for raw pointer deref alignment checks --- compiler/rustc_mir_transform/src/check_alignment.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index d60184e0ebef6..1fe8ea0789286 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -75,6 +75,14 @@ struct PointerFinder<'tcx, 'a> { } impl<'tcx, 'a> Visitor<'tcx> for PointerFinder<'tcx, 'a> { + fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + if let Rvalue::AddressOf(..) = rvalue { + // Ignore dereferences inside of an AddressOf + return; + } + self.super_rvalue(rvalue, location); + } + fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) { if let PlaceContext::NonUse(_) = context { return;