diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index b8cf472309ba5..f6ae748560750 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -19,6 +19,7 @@ #![allow(internal_features)] #![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))] #![feature(core_io_borrowed_buf)] +#![feature(diagnostic_on_unknown)] #![feature(map_try_insert)] #![feature(negative_impls)] #![feature(read_buf)] diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 85f0ce7e6af00..cacb8582ae3c6 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2928,9 +2928,13 @@ pub mod kw { /// /// Given that `sym` is imported, use them like `sym::symbol_name`. /// For example `sym::rustfmt` or `sym::u8`. +#[diagnostic::on_unknown( + label = "`{Unresolved}` is not a pre-interned symbol", + note = "consider adding `{Unresolved}` to the `symbols!` invocation in compiler/rustc_span/src/symbol.rs" +)] pub mod sym { - // Used from a macro in `librustc_feature/accepted.rs` use super::Symbol; + // Used from a macro in `librustc_feature/accepted.rs` pub use super::kw::MacroRules as macro_rules; #[doc(inline)] pub use super::sym_generated::*; diff --git a/library/core/src/intrinsics/fallback.rs b/library/core/src/intrinsics/fallback.rs index a477c2e1a70bd..d2794a5b1202d 100644 --- a/library/core/src/intrinsics/fallback.rs +++ b/library/core/src/intrinsics/fallback.rs @@ -151,11 +151,11 @@ impl_disjoint_bitor! { pub const trait FunnelShift: Copy + 'static { /// See [`super::unchecked_funnel_shl`]; we just need the trait indirection to handle /// different types since calling intrinsics with generics doesn't work. - unsafe fn unchecked_funnel_shl(self, rhs: Self, shift: u32) -> Self; + unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self; /// See [`super::unchecked_funnel_shr`]; we just need the trait indirection to handle /// different types since calling intrinsics with generics doesn't work. - unsafe fn unchecked_funnel_shr(self, rhs: Self, shift: u32) -> Self; + unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self; } macro_rules! impl_funnel_shifts { @@ -164,7 +164,7 @@ macro_rules! impl_funnel_shifts { const impl FunnelShift for $type { #[cfg_attr(miri, track_caller)] #[inline] - unsafe fn unchecked_funnel_shl(self, rhs: Self, shift: u32) -> Self { + unsafe fn unchecked_funnel_shl(self, right: Self, shift: u32) -> Self { // This implementation is also used by Miri so we have to check the precondition. // SAFETY: this is guaranteed by the caller unsafe { super::assume(shift < $type::BITS) }; @@ -181,7 +181,7 @@ macro_rules! impl_funnel_shifts { unsafe { super::disjoint_bitor( super::unchecked_shl(self, shift), - super::unchecked_shr(rhs, $type::BITS - shift), + super::unchecked_shr(right, $type::BITS - shift), ) } } @@ -189,12 +189,12 @@ macro_rules! impl_funnel_shifts { #[cfg_attr(miri, track_caller)] #[inline] - unsafe fn unchecked_funnel_shr(self, rhs: Self, shift: u32) -> Self { + unsafe fn unchecked_funnel_shr(self, right: Self, shift: u32) -> Self { // This implementation is also used by Miri so we have to check the precondition. // SAFETY: this is guaranteed by the caller unsafe { super::assume(shift < $type::BITS) }; if shift == 0 { - rhs + right } else { // SAFETY: // - `shift < T::BITS`, which satisfies `unchecked_shr` @@ -206,7 +206,7 @@ macro_rules! impl_funnel_shifts { unsafe { super::disjoint_bitor( super::unchecked_shl(self, $type::BITS - shift), - super::unchecked_shr(rhs, shift), + super::unchecked_shr(right, shift), ) } } diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 478af470637d7..aeb81bb5d6661 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -382,11 +382,11 @@ impl i8 { Min = -128, Max = 127, rot = 2, - rot_op = "-0x7e", - rot_result = "0xa", - swap_op = "0x12", - swapped = "0x12", - reversed = "0x48", + rot_op = "-0x7e", + rot_result = "0x0a", + swap_op = "0x12", + swapped = "0x12", + reversed = "0x48", le_bytes = "[0x12]", be_bytes = "[0x12]", to_xe_bytes_doc = i8_xe_bytes_doc!(), @@ -407,11 +407,11 @@ impl i16 { Min = -32768, Max = 32767, rot = 4, - rot_op = "-0x5ffd", - rot_result = "0x3a", - swap_op = "0x1234", - swapped = "0x3412", - reversed = "0x2c48", + rot_op = "-0x5ffd", + rot_result = "0x003a", + swap_op = "0x1234", + swapped = "0x3412", + reversed = "0x2c48", le_bytes = "[0x34, 0x12]", be_bytes = "[0x12, 0x34]", to_xe_bytes_doc = "", @@ -432,11 +432,11 @@ impl i32 { Min = -2147483648, Max = 2147483647, rot = 8, - rot_op = "0x10000b3", - rot_result = "0xb301", - swap_op = "0x12345678", - swapped = "0x78563412", - reversed = "0x1e6a2c48", + rot_op = "0x010000b3", + rot_result = "0x0000b301", + swap_op = "0x12345678", + swapped = "0x78563412", + reversed = "0x1e6a2c48", le_bytes = "[0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78]", to_xe_bytes_doc = "", @@ -457,11 +457,11 @@ impl i64 { Min = -9223372036854775808, Max = 9223372036854775807, rot = 12, - rot_op = "0xaa00000000006e1", - rot_result = "0x6e10aa", - swap_op = "0x1234567890123456", - swapped = "0x5634129078563412", - reversed = "0x6a2c48091e6a2c48", + rot_op = "0x0aa00000000006e1", + rot_result = "0x00000000006e10aa", + swap_op = "0x1234567890123456", + swapped = "0x5634129078563412", + reversed = "0x6a2c48091e6a2c48", le_bytes = "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", to_xe_bytes_doc = "", @@ -482,11 +482,11 @@ impl i128 { Min = -170141183460469231731687303715884105728, Max = 170141183460469231731687303715884105727, rot = 16, - rot_op = "0x13f40000000000000000000000004f76", - rot_result = "0x4f7613f4", - swap_op = "0x12345678901234567890123456789012", - swapped = "0x12907856341290785634129078563412", - reversed = "0x48091e6a2c48091e6a2c48091e6a2c48", + rot_op = "0x13f40000000000000000000000004f76", + rot_result = "0x0000000000000000000000004f7613f4", + swap_op = "0x12345678901234567890123456789012", + swapped = "0x12907856341290785634129078563412", + reversed = "0x48091e6a2c48091e6a2c48091e6a2c48", le_bytes = "[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \ 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, \ @@ -510,11 +510,11 @@ impl isize { Min = -32768, Max = 32767, rot = 4, - rot_op = "-0x5ffd", - rot_result = "0x3a", - swap_op = "0x1234", - swapped = "0x3412", - reversed = "0x2c48", + rot_op = "-0x5ffd", + rot_result = "0x003a", + swap_op = "0x1234", + swapped = "0x3412", + reversed = "0x2c48", le_bytes = "[0x34, 0x12]", be_bytes = "[0x12, 0x34]", to_xe_bytes_doc = usize_isize_to_xe_bytes_doc!(), @@ -536,11 +536,11 @@ impl isize { Min = -2147483648, Max = 2147483647, rot = 8, - rot_op = "0x10000b3", - rot_result = "0xb301", - swap_op = "0x12345678", - swapped = "0x78563412", - reversed = "0x1e6a2c48", + rot_op = "0x010000b3", + rot_result = "0x0000b301", + swap_op = "0x12345678", + swapped = "0x78563412", + reversed = "0x1e6a2c48", le_bytes = "[0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78]", to_xe_bytes_doc = usize_isize_to_xe_bytes_doc!(), @@ -562,11 +562,11 @@ impl isize { Min = -9223372036854775808, Max = 9223372036854775807, rot = 12, - rot_op = "0xaa00000000006e1", - rot_result = "0x6e10aa", - swap_op = "0x1234567890123456", - swapped = "0x5634129078563412", - reversed = "0x6a2c48091e6a2c48", + rot_op = "0x0aa00000000006e1", + rot_result = "0x00000000006e10aa", + swap_op = "0x1234567890123456", + swapped = "0x5634129078563412", + reversed = "0x6a2c48091e6a2c48", le_bytes = "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", to_xe_bytes_doc = usize_isize_to_xe_bytes_doc!(), @@ -588,17 +588,17 @@ impl u8 { BITS_MINUS_ONE = 7, MAX = 255, rot = 2, - rot_op = "0x82", - rot_result = "0xa", - fsh_op = "0x36", - fshl_result = "0x8", - fshr_result = "0x8d", - clmul_lhs = "0x12", - clmul_rhs = "0x34", + rot_op = "0x82", + rot_result = "0x0a", + fsh_op = "0x36", + fshl_result = "0x08", + fshr_result = "0x8d", + clmul_lhs = "0x12", + clmul_rhs = "0x34", clmul_result = "0x28", - swap_op = "0x12", - swapped = "0x12", - reversed = "0x48", + swap_op = "0x12", + swapped = "0x12", + reversed = "0x48", le_bytes = "[0x12]", be_bytes = "[0x12]", to_xe_bytes_doc = u8_xe_bytes_doc!(), @@ -1236,17 +1236,17 @@ impl u16 { BITS_MINUS_ONE = 15, MAX = 65535, rot = 4, - rot_op = "0xa003", - rot_result = "0x3a", - fsh_op = "0x2de", - fshl_result = "0x30", - fshr_result = "0x302d", - clmul_lhs = "0x9012", - clmul_rhs = "0xcd34", - clmul_result = "0x928", - swap_op = "0x1234", - swapped = "0x3412", - reversed = "0x2c48", + rot_op = "0xa003", + rot_result = "0x003a", + fsh_op = "0x02de", + fshl_result = "0x0030", + fshr_result = "0x302d", + clmul_lhs = "0x9012", + clmul_rhs = "0xcd34", + clmul_result = "0x0928", + swap_op = "0x1234", + swapped = "0x3412", + reversed = "0x2c48", le_bytes = "[0x34, 0x12]", be_bytes = "[0x12, 0x34]", to_xe_bytes_doc = "", @@ -1292,17 +1292,17 @@ impl u32 { BITS_MINUS_ONE = 31, MAX = 4294967295, rot = 8, - rot_op = "0x10000b3", - rot_result = "0xb301", - fsh_op = "0x2fe78e45", - fshl_result = "0xb32f", - fshr_result = "0xb32fe78e", - clmul_lhs = "0x56789012", - clmul_rhs = "0xf52ecd34", + rot_op = "0x010000b3", + rot_result = "0x0000b301", + fsh_op = "0x2fe78e45", + fshl_result = "0x0000b32f", + fshr_result = "0xb32fe78e", + clmul_lhs = "0x56789012", + clmul_rhs = "0xf52ecd34", clmul_result = "0x9b980928", - swap_op = "0x12345678", - swapped = "0x78563412", - reversed = "0x1e6a2c48", + swap_op = "0x12345678", + swapped = "0x78563412", + reversed = "0x1e6a2c48", le_bytes = "[0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78]", to_xe_bytes_doc = "", @@ -1324,17 +1324,17 @@ impl u64 { BITS_MINUS_ONE = 63, MAX = 18446744073709551615, rot = 12, - rot_op = "0xaa00000000006e1", - rot_result = "0x6e10aa", - fsh_op = "0x2fe78e45983acd98", - fshl_result = "0x6e12fe", - fshr_result = "0x6e12fe78e45983ac", - clmul_lhs = "0x7890123456789012", - clmul_rhs = "0xdd358416f52ecd34", - clmul_result = "0xa6299579b980928", - swap_op = "0x1234567890123456", - swapped = "0x5634129078563412", - reversed = "0x6a2c48091e6a2c48", + rot_op = "0x0aa00000000006e1", + rot_result = "0x00000000006e10aa", + fsh_op = "0x2fe78e45983acd98", + fshl_result = "0x00000000006e12fe", + fshr_result = "0x6e12fe78e45983ac", + clmul_lhs = "0x7890123456789012", + clmul_rhs = "0xdd358416f52ecd34", + clmul_result = "0x0a6299579b980928", + swap_op = "0x1234567890123456", + swapped = "0x5634129078563412", + reversed = "0x6a2c48091e6a2c48", le_bytes = "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", to_xe_bytes_doc = "", @@ -1356,17 +1356,17 @@ impl u128 { BITS_MINUS_ONE = 127, MAX = 340282366920938463463374607431768211455, rot = 16, - rot_op = "0x13f40000000000000000000000004f76", - rot_result = "0x4f7613f4", - fsh_op = "0x2fe78e45983acd98039000008736273", - fshl_result = "0x4f7602fe", - fshr_result = "0x4f7602fe78e45983acd9803900000873", - clmul_lhs = "0x12345678901234567890123456789012", - clmul_rhs = "0x4317e40ab4ddcf05dd358416f52ecd34", + rot_op = "0x13f40000000000000000000000004f76", + rot_result = "0x0000000000000000000000004f7613f4", + fsh_op = "0x02fe78e45983acd98039000008736273", + fshl_result = "0x0000000000000000000000004f7602fe", + fshr_result = "0x4f7602fe78e45983acd9803900000873", + clmul_lhs = "0x12345678901234567890123456789012", + clmul_rhs = "0x4317e40ab4ddcf05dd358416f52ecd34", clmul_result = "0xb9cf660de35d0c170a6299579b980928", - swap_op = "0x12345678901234567890123456789012", - swapped = "0x12907856341290785634129078563412", - reversed = "0x48091e6a2c48091e6a2c48091e6a2c48", + swap_op = "0x12345678901234567890123456789012", + swapped = "0x12907856341290785634129078563412", + reversed = "0x48091e6a2c48091e6a2c48091e6a2c48", le_bytes = "[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \ 0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, \ @@ -1390,17 +1390,17 @@ impl usize { BITS_MINUS_ONE = 15, MAX = 65535, rot = 4, - rot_op = "0xa003", - rot_result = "0x3a", - fsh_op = "0x2de", - fshl_result = "0x30", - fshr_result = "0x302d", - clmul_lhs = "0x9012", - clmul_rhs = "0xcd34", - clmul_result = "0x928", - swap_op = "0x1234", - swapped = "0x3412", - reversed = "0x2c48", + rot_op = "0xa003", + rot_result = "0x003a", + fsh_op = "0x02de", + fshl_result = "0x0030", + fshr_result = "0x302d", + clmul_lhs = "0x9012", + clmul_rhs = "0xcd34", + clmul_result = "0x0928", + swap_op = "0x1234", + swapped = "0x3412", + reversed = "0x2c48", le_bytes = "[0x34, 0x12]", be_bytes = "[0x12, 0x34]", to_xe_bytes_doc = usize_isize_to_xe_bytes_doc!(), @@ -1422,17 +1422,17 @@ impl usize { BITS_MINUS_ONE = 31, MAX = 4294967295, rot = 8, - rot_op = "0x10000b3", - rot_result = "0xb301", - fsh_op = "0x2fe78e45", - fshl_result = "0xb32f", - fshr_result = "0xb32fe78e", - clmul_lhs = "0x56789012", - clmul_rhs = "0xf52ecd34", + rot_op = "0x010000b3", + rot_result = "0x0000b301", + fsh_op = "0x2fe78e45", + fshl_result = "0x0000b32f", + fshr_result = "0xb32fe78e", + clmul_lhs = "0x56789012", + clmul_rhs = "0xf52ecd34", clmul_result = "0x9b980928", - swap_op = "0x12345678", - swapped = "0x78563412", - reversed = "0x1e6a2c48", + swap_op = "0x12345678", + swapped = "0x78563412", + reversed = "0x1e6a2c48", le_bytes = "[0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78]", to_xe_bytes_doc = usize_isize_to_xe_bytes_doc!(), @@ -1454,17 +1454,17 @@ impl usize { BITS_MINUS_ONE = 63, MAX = 18446744073709551615, rot = 12, - rot_op = "0xaa00000000006e1", - rot_result = "0x6e10aa", - fsh_op = "0x2fe78e45983acd98", - fshl_result = "0x6e12fe", - fshr_result = "0x6e12fe78e45983ac", - clmul_lhs = "0x7890123456789012", - clmul_rhs = "0xdd358416f52ecd34", + rot_op = "0x0aa00000000006e1", + rot_result = "0x00000000006e10aa", + fsh_op = "0x2fe78e45983acd98", + fshl_result = "0x00000000006e12fe", + fshr_result = "0x6e12fe78e45983ac", + clmul_lhs = "0x7890123456789012", + clmul_rhs = "0xdd358416f52ecd34", clmul_result = "0xa6299579b980928", - swap_op = "0x1234567890123456", - swapped = "0x5634129078563412", - reversed = "0x6a2c48091e6a2c48", + swap_op = "0x1234567890123456", + swapped = "0x5634129078563412", + reversed = "0x6a2c48091e6a2c48", le_bytes = "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", be_bytes = "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", to_xe_bytes_doc = usize_isize_to_xe_bytes_doc!(), diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 2e69c67c3597a..5d5df10694197 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -504,74 +504,116 @@ macro_rules! uint_impl { return intrinsics::rotate_right(self, n); } - /// Performs a left funnel shift (concatenates `self` with `rhs`, with `self` - /// making up the most significant half, then shifts the combined value left - /// by `n`, and most significant half is extracted to produce the result). + /// Performs a left funnel shift. /// - /// Please note this isn't the same operation as the `<<` shifting operator or - /// [`rotate_left`](Self::rotate_left), although `a.funnel_shl(a, n)` is *equivalent* - /// to `a.rotate_left(n)`. + /// This operation can be thought of as concatenating `self` and `right` into an + /// integer twice the size of + #[doc = concat!("`", stringify!($SelfT) , "`,")] + /// performing a left shift by `n`, and returning the **left half** of the result. + /// + /// The name comes from "funneling" a wider integer to a narrower integer. /// /// # Panics /// - /// If `n` is greater than or equal to the number of bits in `self` + /// This function will panic if `n` is greater than or equal to the number of + /// bits in `self`. /// /// # Examples /// - /// Basic usage: + /// ``` + /// #![feature(funnel_shifts)] + /// + #[doc = concat!("let a = ", $rot_op, "_", stringify!($SelfT), ";")] + #[doc = concat!("let b = ", $fsh_op, "_", stringify!($SelfT), ";")] + /// + #[doc = concat!("assert_eq!(a.funnel_shl(b, ", $rot, "), ", $fshl_result, ");")] + /// + /// // Using zeros as the right operand acts as a normal shift left + #[doc = concat!("assert_eq!(a.funnel_shl(0, ", $rot, "), a << ", $rot, ");")] + /// + /// // Shifting by 0 returns `self` unchanged + #[doc = concat!("assert_eq!(a.funnel_shl(b, 0), a);")] /// + /// // Using the same value as the right operand acts as a rotate + #[doc = concat!("assert_eq!(a.funnel_shl(a, ", $rot, "), a.rotate_left(", $rot, "));")] /// ``` + /// + /// Note that while `funnel_shl` can act as a rotate, it does not allow for + /// rotating by an unbounded amount like [`rotate_left`](Self::rotate_left) does: + /// + /// ```should_panic /// #![feature(funnel_shifts)] - #[doc = concat!("let a = ", $rot_op, stringify!($SelfT), ";")] - #[doc = concat!("let b = ", $fsh_op, stringify!($SelfT), ";")] - #[doc = concat!("let m = ", $fshl_result, ";")] /// - #[doc = concat!("assert_eq!(a.funnel_shl(b, ", $rot, "), m);")] + #[doc = concat!("let a = ", stringify!($SelfT), "::MAX;")] + /// // Okay + #[doc = concat!("let _ = a.rotate_left(", stringify!($SelfT), "::BITS);")] + /// // Panics + #[doc = concat!("let _ = a.funnel_shl(a, ", stringify!($SelfT), "::BITS);")] /// ``` #[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] #[unstable(feature = "funnel_shifts", issue = "145686")] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] + #[must_use = "this returns the result of the operation, without modifying the original"] #[inline(always)] - pub const fn funnel_shl(self, rhs: Self, n: u32) -> Self { + pub const fn funnel_shl(self, right: Self, n: u32) -> Self { assert!(n < Self::BITS, "attempt to funnel shift left with overflow"); // SAFETY: just checked that `shift` is in-range - unsafe { self.unchecked_funnel_shl(rhs, n) } + unsafe { self.unchecked_funnel_shl(right, n) } } - /// Performs a right funnel shift (concatenates `self` and `rhs`, with `self` - /// making up the most significant half, then shifts the combined value right - /// by `n`, and least significant half is extracted to produce the result). + /// Performs a right funnel shift. + /// + /// This operation can be thought of as concatenating `self` and `right` into an + /// integer twice the size of + #[doc = concat!("`", stringify!($SelfT) , "`,")] + /// performing a right shift by `n`, and returning the **left half** of the result. /// - /// Please note this isn't the same operation as the `>>` shifting operator or - /// [`rotate_right`](Self::rotate_right), although `a.funnel_shr(a, n)` is *equivalent* - /// to `a.rotate_right(n)`. + /// The name comes from "funneling" a wider integer to a narrower integer. /// /// # Panics /// - /// If `n` is greater than or equal to the number of bits in `self` + /// This function will panic if `n` is greater than or equal to the number of + /// bits in `self`. /// /// # Examples /// - /// Basic usage: + /// ``` + /// #![feature(funnel_shifts)] + /// + #[doc = concat!("let a = ", $rot_op, "_", stringify!($SelfT), ";")] + #[doc = concat!("let b = ", $fsh_op, "_", stringify!($SelfT), ";")] + /// + #[doc = concat!("assert_eq!(a.funnel_shr(b, ", $rot, "), ", $fshr_result, ");")] + /// + /// // Using zeros as the left operand acts as a normal shift right + #[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".funnel_shr(a, ", $rot, "), a >> ", $rot, ");")] /// + /// // Shifting by 0 returns `right` unchanged + #[doc = concat!("assert_eq!(b.funnel_shr(a, 0), a);")] + /// + /// // Using the same value as the right operand acts as a rotate + #[doc = concat!("assert_eq!(a.funnel_shr(a, ", $rot, "), a.rotate_right(", $rot, "));")] /// ``` + /// + /// Note that while `funnel_shr` can act as a rotate, it does not allow for + /// rotating by an unbounded amount like [`rotate_right`](Self::rotate_right) does: + /// + /// ```should_panic /// #![feature(funnel_shifts)] - #[doc = concat!("let a = ", $rot_op, stringify!($SelfT), ";")] - #[doc = concat!("let b = ", $fsh_op, stringify!($SelfT), ";")] - #[doc = concat!("let m = ", $fshr_result, ";")] /// - #[doc = concat!("assert_eq!(a.funnel_shr(b, ", $rot, "), m);")] + #[doc = concat!("let a = ", stringify!($SelfT), "::MAX;")] + /// // Okay + #[doc = concat!("let _ = a.rotate_right(", stringify!($SelfT), "::BITS);")] + /// // Panics + #[doc = concat!("let _ = a.funnel_shr(a, ", stringify!($SelfT), "::BITS);")] /// ``` #[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] #[unstable(feature = "funnel_shifts", issue = "145686")] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] + #[must_use = "this returns the result of the operation, without modifying the original"] #[inline(always)] - pub const fn funnel_shr(self, rhs: Self, n: u32) -> Self { + pub const fn funnel_shr(self, right: Self, n: u32) -> Self { assert!(n < Self::BITS, "attempt to funnel shift right with overflow"); // SAFETY: just checked that `shift` is in-range - unsafe { self.unchecked_funnel_shr(rhs, n) } + unsafe { self.unchecked_funnel_shr(right, n) } } /// Unchecked funnel shift left. @@ -584,11 +626,10 @@ macro_rules! uint_impl { /// #[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] #[unstable(feature = "funnel_shifts", issue = "145686")] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] + #[must_use = "this returns the result of the operation, without modifying the original"] #[inline(always)] #[track_caller] - pub const unsafe fn unchecked_funnel_shl(self, low: Self, n: u32) -> Self { + pub const unsafe fn unchecked_funnel_shl(self, right: Self, n: u32) -> Self { assert_unsafe_precondition!( check_language_ub, concat!(stringify!($SelfT), "::unchecked_funnel_shl cannot overflow"), @@ -597,7 +638,7 @@ macro_rules! uint_impl { // SAFETY: this is guaranteed to be safe by the caller. unsafe { - intrinsics::unchecked_funnel_shl(self, low, n) + intrinsics::unchecked_funnel_shl(self, right, n) } } @@ -611,11 +652,10 @@ macro_rules! uint_impl { /// #[rustc_const_unstable(feature = "funnel_shifts", issue = "145686")] #[unstable(feature = "funnel_shifts", issue = "145686")] - #[must_use = "this returns the result of the operation, \ - without modifying the original"] + #[must_use = "this returns the result of the operation, without modifying the original"] #[inline(always)] #[track_caller] - pub const unsafe fn unchecked_funnel_shr(self, low: Self, n: u32) -> Self { + pub const unsafe fn unchecked_funnel_shr(self, right: Self, n: u32) -> Self { assert_unsafe_precondition!( check_language_ub, concat!(stringify!($SelfT), "::unchecked_funnel_shr cannot overflow"), @@ -624,7 +664,7 @@ macro_rules! uint_impl { // SAFETY: this is guaranteed to be safe by the caller. unsafe { - intrinsics::unchecked_funnel_shr(self, low, n) + intrinsics::unchecked_funnel_shr(self, right, n) } } diff --git a/library/std_detect/src/detect/os/darwin/aarch64.rs b/library/std_detect/src/detect/os/darwin/aarch64.rs index 5805d5cc36460..35009a2b147cd 100644 --- a/library/std_detect/src/detect/os/darwin/aarch64.rs +++ b/library/std_detect/src/detect/os/darwin/aarch64.rs @@ -36,7 +36,7 @@ pub(crate) fn detect_features() -> cache::Initializer { // Armv8.0 features not using the standard identifiers let fp = _sysctlbyname(c"hw.optional.floatingpoint"); - let asimd = _sysctlbyname(c"hw.optional.AdvSIMD"); + let asimd = _sysctlbyname(c"hw.optional.AdvSIMD") || _sysctlbyname(c"hw.optional.arm.AdvSIMD"); let crc_old = _sysctlbyname(c"hw.optional.armv8_crc32"); // Armv8 and Armv9 features using the standard identifiers diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs index 527140eca3a18..e4c05d58004a7 100644 --- a/src/tools/rustfmt/src/macros.rs +++ b/src/tools/rustfmt/src/macros.rs @@ -27,6 +27,7 @@ use crate::config::StyleEdition; use crate::config::lists::*; use crate::expr::{RhsAssignKind, rewrite_array, rewrite_assign_rhs}; use crate::header::{HeaderPart, format_header}; +use crate::is_nightly_channel; use crate::lists::{ListFormatting, itemize_list, write_list}; use crate::overflow; use crate::parse::macros::cfg_select::{CfgSelectFormatPredicate, parse_cfg_select_arms}; @@ -247,7 +248,7 @@ fn rewrite_macro_inner( } } - if macro_name.ends_with("cfg_select!") { + if is_nightly_channel!() && macro_name.ends_with("cfg_select!") { match format_cfg_select(context, shape, mac.span(), ¯o_name, style, ts.clone()) { Ok(rw) => return Ok(rw), Err(err) => match err { diff --git a/src/tools/rustfmt/src/test/mod.rs b/src/tools/rustfmt/src/test/mod.rs index 29904c6c7765f..201a581549914 100644 --- a/src/tools/rustfmt/src/test/mod.rs +++ b/src/tools/rustfmt/src/test/mod.rs @@ -754,6 +754,15 @@ fn check_files(files: Vec, opt_config: &Option) -> (Vec Config { }; for (key, val) in &sig_comments { - if key != "target" && key != "config" && key != "unstable" { + if key != "target" && key != "config" && key != "unstable" && key != "stable" { config.override_value(key, val); if config.is_default(key) { warn!("Default value {} used explicitly for {}", val, key); diff --git a/src/tools/rustfmt/tests/source/cfg_select.rs b/src/tools/rustfmt/tests/source/cfg_select.rs index 794967afeb26b..26f276edeef6e 100644 --- a/src/tools/rustfmt/tests/source/cfg_select.rs +++ b/src/tools/rustfmt/tests/source/cfg_select.rs @@ -1,3 +1,4 @@ +// rustfmt-unstable: true // rustfmt-style_edition: 2024 // rustfmt-skip_children: true diff --git a/src/tools/rustfmt/tests/source/cfg_select_stable.rs b/src/tools/rustfmt/tests/source/cfg_select_stable.rs new file mode 100644 index 0000000000000..7f37a155cfcd0 --- /dev/null +++ b/src/tools/rustfmt/tests/source/cfg_select_stable.rs @@ -0,0 +1,10 @@ +// rustfmt-stable: true + +// While we gate the `cfg_select!` formatting behind the `is_nightly_channel!()` check +// this test helps ensure that we don't start formatting `cfg_select!` on the `stable` +// or `beta` release channels. It is intentionally formatted incorrectly. As soon as the +// `is_nightly_channel!()` gate is removed this will start formatting and we can remove this test. +cfg_select! ( + unix => 1, + windows => 1, +); diff --git a/src/tools/rustfmt/tests/target/cfg_select.rs b/src/tools/rustfmt/tests/target/cfg_select.rs index fa242c7d2062f..fa70ea80dad38 100644 --- a/src/tools/rustfmt/tests/target/cfg_select.rs +++ b/src/tools/rustfmt/tests/target/cfg_select.rs @@ -1,3 +1,4 @@ +// rustfmt-unstable: true // rustfmt-style_edition: 2024 // rustfmt-skip_children: true diff --git a/src/tools/rustfmt/tests/target/cfg_select_stable.rs b/src/tools/rustfmt/tests/target/cfg_select_stable.rs new file mode 100644 index 0000000000000..7f37a155cfcd0 --- /dev/null +++ b/src/tools/rustfmt/tests/target/cfg_select_stable.rs @@ -0,0 +1,10 @@ +// rustfmt-stable: true + +// While we gate the `cfg_select!` formatting behind the `is_nightly_channel!()` check +// this test helps ensure that we don't start formatting `cfg_select!` on the `stable` +// or `beta` release channels. It is intentionally formatted incorrectly. As soon as the +// `is_nightly_channel!()` gate is removed this will start formatting and we can remove this test. +cfg_select! ( + unix => 1, + windows => 1, +); diff --git a/tests/ui/consts/const-fn-vec-box-dyn-any-84170.rs b/tests/ui/consts/const-fn-vec-box-dyn-any-84170.rs new file mode 100644 index 0000000000000..64de852f46d6f --- /dev/null +++ b/tests/ui/consts/const-fn-vec-box-dyn-any-84170.rs @@ -0,0 +1,14 @@ +// Regression test for #84170: a `const fn` returning `Vec>` was rejected +// with E0723 "trait bounds other than `Sized` on const fn parameters are unstable" even +// though no trait object value is created. +//@ check-pass + +#![allow(dead_code)] + +const fn newv() -> Vec> { + Vec::new() +} + +const fn new(_val: &Vec>) {} + +fn main() {}