From c3d54c6eec296efcb5c272b81ced84e70b57bac3 Mon Sep 17 00:00:00 2001 From: Yosh Date: Sat, 22 Aug 2026 14:08:39 +0200 Subject: [PATCH 1/9] Stabilize `core::mem::DropGuard` Signed-off-by: Yosh --- library/alloc/src/lib.rs | 1 - library/alloctests/lib.rs | 1 - library/core/src/mem/drop_guard.rs | 18 ++++++++---------- library/core/src/mem/mod.rs | 2 +- library/coretests/tests/lib.rs | 1 - library/std/src/lib.rs | 1 - 6 files changed, 9 insertions(+), 15 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 89b15a169dce0..89cbd75d0f6c2 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -128,7 +128,6 @@ #![feature(derive_const)] #![feature(diagnostic_on_move)] #![feature(dispatch_from_dyn)] -#![feature(drop_guard)] #![feature(ergonomic_clones)] #![feature(error_generic_member_access)] #![feature(exact_size_is_empty)] diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 77e56d3ac54f4..eca8444812521 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -28,7 +28,6 @@ #![feature(const_try)] #![feature(copied_into_inner)] #![feature(core_intrinsics)] -#![feature(drop_guard)] #![feature(exact_size_is_empty)] #![feature(extend_one)] #![feature(extend_one_unchecked)] diff --git a/library/core/src/mem/drop_guard.rs b/library/core/src/mem/drop_guard.rs index 8e6655f785466..31f1f93b65378 100644 --- a/library/core/src/mem/drop_guard.rs +++ b/library/core/src/mem/drop_guard.rs @@ -11,7 +11,6 @@ use crate::ops::{Deref, DerefMut}; /// /// ```rust /// # #![allow(unused)] -/// #![feature(drop_guard)] /// /// use std::mem::DropGuard; /// @@ -28,7 +27,7 @@ use crate::ops::{Deref, DerefMut}; /// // "Chashu likes tuna!!!" /// } /// ``` -#[unstable(feature = "drop_guard", issue = "144426")] +#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] #[doc(alias = "ScopeGuard")] #[doc(alias = "defer")] pub struct DropGuard @@ -49,14 +48,14 @@ where /// /// ```rust /// # #![allow(unused)] - /// #![feature(drop_guard)] /// /// use std::mem::DropGuard; /// /// let value = String::from("Chashu likes tuna"); /// let guard = DropGuard::new(value, |s| println!("{s}")); /// ``` - #[unstable(feature = "drop_guard", issue = "144426")] + #[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_unstable(feature = "const_drop_guard", issue = "none")] #[must_use] pub const fn new(inner: T, f: F) -> Self { Self { inner: ManuallyDrop::new(inner), f: ManuallyDrop::new(f) } @@ -73,7 +72,6 @@ where /// /// ```rust /// # #![allow(unused)] - /// #![feature(drop_guard)] /// /// use std::mem::DropGuard; /// @@ -81,7 +79,7 @@ where /// let guard = DropGuard::new(value, |s| println!("{s}")); /// assert_eq!(DropGuard::dismiss(guard), "Nori likes chicken"); /// ``` - #[unstable(feature = "drop_guard", issue = "144426")] + #[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_drop_guard", issue = "none")] #[inline] pub const fn dismiss(guard: Self) -> T @@ -107,7 +105,7 @@ where } } -#[unstable(feature = "drop_guard", issue = "144426")] +#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] const impl Deref for DropGuard where @@ -120,7 +118,7 @@ where } } -#[unstable(feature = "drop_guard", issue = "144426")] +#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_convert", issue = "143773")] const impl DerefMut for DropGuard where @@ -131,7 +129,7 @@ where } } -#[unstable(feature = "drop_guard", issue = "144426")] +#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] #[rustc_const_unstable(feature = "const_drop_guard", issue = "none")] const impl Drop for DropGuard where @@ -148,7 +146,7 @@ where } } -#[unstable(feature = "drop_guard", issue = "144426")] +#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] impl Debug for DropGuard where T: Debug, diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 26390e5071c53..64a48d7266746 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -59,7 +59,7 @@ mod transmutability; pub use transmutability::{Assume, TransmuteFrom}; mod drop_guard; -#[unstable(feature = "drop_guard", issue = "144426")] +#[stable(feature = "drop_guard", since = "CURRENT_RUSTC_VERSION")] pub use drop_guard::DropGuard; // This one has to be a re-export (rather than wrapping the underlying intrinsic) so that we can do diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index e81cae69e1852..a49d0a0e0c1f7 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -47,7 +47,6 @@ #![feature(cstr_display)] #![feature(debug_closure_helpers)] #![feature(dec2flt)] -#![feature(drop_guard)] #![feature(duration_constants)] #![feature(duration_constructors)] #![feature(exact_div)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c2007433ff5ea..3d2cfbe52f65d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -337,7 +337,6 @@ #![feature(cstr_display)] #![feature(cursor_split)] #![feature(derive_const)] -#![feature(drop_guard)] #![feature(duration_constants)] #![feature(error_generic_member_access)] #![feature(error_iter)] From 265a608daea277d5bdc666ed6598a9ff30b44d28 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 20 Aug 2026 09:34:38 +0200 Subject: [PATCH 2/9] Reapply "riscv: promote d, e, and f target_features to CfgStableToggleUnstable" This reverts commit 55c133a9912a1d2e77c3b5d057208926ca6c9c3f. --- compiler/rustc_target/src/target_features.rs | 6 ++--- ...le-target-feature-flag-enable.riscv.stderr | 2 +- ...d-target-feature-flag-disable.riscv.stderr | 2 +- ...unstable-target-feature-attribute-riscv.rs | 17 ++++++++++++++ ...able-target-feature-attribute-riscv.stderr | 23 +++++++++++++++++++ ...stable-target-feature-flag-enable-riscv.rs | 17 ++++++++++++++ ...le-target-feature-flag-enable-riscv.stderr | 10 ++++++++ 7 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 68ece92fbc9c0..c7e1a90effc66 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -680,9 +680,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("a", Stable, &["zaamo", "zalrsc"]), ("b", Stable, &["zba", "zbb", "zbs"]), ("c", Stable, &["zca"]), - ("d", Unstable(sym::riscv_target_feature), &["f"]), - ("e", Unstable(sym::riscv_target_feature), &[]), - ("f", Unstable(sym::riscv_target_feature), &["zicsr"]), + ("d", CfgStableToggleUnstable(sym::riscv_target_feature), &["f"]), + ("e", CfgStableToggleUnstable(sym::riscv_target_feature), &[]), + ("f", CfgStableToggleUnstable(sym::riscv_target_feature), &["zicsr"]), ( "forced-atomics", // Not implied by any CPU model or other feature. diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr index 1995f9d993a63..cb17e7fad296d 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr +++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr @@ -1,6 +1,6 @@ warning: unstable feature specified for `-Ctarget-feature`: `d` | - = note: this feature is not stably supported; its behavior can change in the future + = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #162235 diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr index c4ce26bfef8d3..a47e6dea6be57 100644 --- a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr +++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr @@ -1,6 +1,6 @@ warning: unstable feature specified for `-Ctarget-feature`: `d` | - = note: this feature is not stably supported; its behavior can change in the future + = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #162235 diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs new file mode 100644 index 0000000000000..24d42e3df44d3 --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs @@ -0,0 +1,17 @@ +//! Ensure cfg-only stable target_features trigger errors when enabled via attribute. +//@ compile-flags: --crate-type=lib +//@ compile-flags: --target=riscv64gc-unknown-none-elf +//@ needs-llvm-components: riscv +//@ add-minicore +//@ ignore-backends: gcc +#![feature(no_core)] +#![no_core] + +extern crate minicore; +use minicore::*; + +#[target_feature(enable = "v")] +//~^ERROR: the target feature `v` is currently unstable +#[target_feature(enable = "f")] +//~^ERROR: the target feature `f` is allowed in cfg but unstable otherwise +pub unsafe fn my_fun() {} diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr new file mode 100644 index 0000000000000..7f13c11798fcf --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr @@ -0,0 +1,23 @@ +error[E0658]: the target feature `v` is currently unstable + --> $DIR/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs:13:18 + | +LL | #[target_feature(enable = "v")] + | ^^^^^^^^^^^^ + | + = note: see issue #150257 for more information + = help: add `#![feature(riscv_target_feature)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the target feature `f` is allowed in cfg but unstable otherwise + --> $DIR/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs:15:18 + | +LL | #[target_feature(enable = "f")] + | ^^^^^^^^^^^^ + | + = note: see issue #150257 for more information + = help: add `#![feature(riscv_target_feature)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs new file mode 100644 index 0000000000000..ab2b75ed5190f --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs @@ -0,0 +1,17 @@ +//! Ensure cfg-only stable target_features trigger warnings when enabled via compile flag. +//@ check-pass +//@ compile-flags: --crate-type=lib +//@ compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=+v -Ctarget-feature=+f +// FIXME(#147881): *disable* the feature again for minicore as otherwise that will fail to build. +//@ minicore-compile-flags: -Ctarget-feature=-v -Ctarget-feature=-f +//@ needs-llvm-components: riscv +//@ ignore-backends: gcc +//@ add-minicore +#![feature(no_core)] +#![no_core] + +extern crate minicore; +use minicore::*; + +//~? WARN unstable feature specified for `-Ctarget-feature` +//~? WARN unstable feature specified for `-Ctarget-feature` diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr new file mode 100644 index 0000000000000..b0167221aabaa --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr @@ -0,0 +1,10 @@ +warning: unstable feature specified for `-Ctarget-feature`: `v` + | + = note: this feature is not stably supported; its behavior can change in the future + +warning: unstable feature specified for `-Ctarget-feature`: `f` + | + = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future + +warning: 2 warnings emitted + From 55c68a8af003e92e2559e4070b7b3f3a42f596c9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 20 Aug 2026 09:56:30 +0200 Subject: [PATCH 3/9] do not stabilize 'e' --- compiler/rustc_target/src/target_features.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index c7e1a90effc66..400f5c98ec0b7 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -681,7 +681,7 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("b", Stable, &["zba", "zbb", "zbs"]), ("c", Stable, &["zca"]), ("d", CfgStableToggleUnstable(sym::riscv_target_feature), &["f"]), - ("e", CfgStableToggleUnstable(sym::riscv_target_feature), &[]), + ("e", Unstable(sym::riscv_target_feature), &[]), // negative feature! needs special care. ("f", CfgStableToggleUnstable(sym::riscv_target_feature), &["zicsr"]), ( "forced-atomics", From dc66d145d7be6f9ad54cf9b42281a19923ddd98e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 2 Sep 2026 21:07:36 +0200 Subject: [PATCH 4/9] fully stabilize d, f --- compiler/rustc_target/src/target_features.rs | 4 ++-- ...le-target-feature-flag-enable.riscv.stderr | 8 +------ ...incompatible-target-feature-flag-enable.rs | 1 - ...d-target-feature-flag-disable.riscv.stderr | 8 +------ ...bi-required-target-feature-flag-disable.rs | 2 +- ...unstable-target-feature-attribute-riscv.rs | 17 -------------- ...able-target-feature-attribute-riscv.stderr | 23 ------------------- ...stable-target-feature-flag-enable-riscv.rs | 17 -------------- ...le-target-feature-flag-enable-riscv.stderr | 10 -------- 9 files changed, 5 insertions(+), 85 deletions(-) delete mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs delete mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr delete mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs delete mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index 400f5c98ec0b7..9826633d47033 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -680,9 +680,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("a", Stable, &["zaamo", "zalrsc"]), ("b", Stable, &["zba", "zbb", "zbs"]), ("c", Stable, &["zca"]), - ("d", CfgStableToggleUnstable(sym::riscv_target_feature), &["f"]), + ("d", Stable, &["f"]), ("e", Unstable(sym::riscv_target_feature), &[]), // negative feature! needs special care. - ("f", CfgStableToggleUnstable(sym::riscv_target_feature), &["zicsr"]), + ("f", Stable, &["zicsr"]), ( "forced-atomics", // Not implied by any CPU model or other feature. diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr index cb17e7fad296d..bc40b139095a5 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr +++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr @@ -1,13 +1,7 @@ -warning: unstable feature specified for `-Ctarget-feature`: `d` - | - = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future - = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #162235 - warning: target feature `d` must be disabled to ensure that the ABI of the current target can be implemented correctly | = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #162235 -warning: 2 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs index c6370f01c47d6..c6b5e15599d8e 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs +++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.rs @@ -19,5 +19,4 @@ extern crate minicore; use minicore::*; //~? WARN must be disabled to ensure that the ABI of the current target can be implemented correctly -//[riscv]~? WARN unstable feature specified for `-Ctarget-feature` //[x86]~? WARN use a soft-float target instead diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr index a47e6dea6be57..e8a5e98793d10 100644 --- a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr +++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr @@ -1,13 +1,7 @@ -warning: unstable feature specified for `-Ctarget-feature`: `d` - | - = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future - = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #162235 - warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly | = note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #162235 -warning: 2 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs b/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs index 47b7abd50debb..4faef8d02d673 100644 --- a/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs +++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.rs @@ -26,4 +26,4 @@ extern crate minicore; use minicore::*; //~? WARN must be enabled to ensure that the ABI of the current target can be implemented correctly -//[x86,riscv]~? WARN unstable feature specified for `-Ctarget-feature` +//[x86]~? WARN unstable feature specified for `-Ctarget-feature` diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs deleted file mode 100644 index 24d42e3df44d3..0000000000000 --- a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! Ensure cfg-only stable target_features trigger errors when enabled via attribute. -//@ compile-flags: --crate-type=lib -//@ compile-flags: --target=riscv64gc-unknown-none-elf -//@ needs-llvm-components: riscv -//@ add-minicore -//@ ignore-backends: gcc -#![feature(no_core)] -#![no_core] - -extern crate minicore; -use minicore::*; - -#[target_feature(enable = "v")] -//~^ERROR: the target feature `v` is currently unstable -#[target_feature(enable = "f")] -//~^ERROR: the target feature `f` is allowed in cfg but unstable otherwise -pub unsafe fn my_fun() {} diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr deleted file mode 100644 index 7f13c11798fcf..0000000000000 --- a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0658]: the target feature `v` is currently unstable - --> $DIR/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs:13:18 - | -LL | #[target_feature(enable = "v")] - | ^^^^^^^^^^^^ - | - = note: see issue #150257 for more information - = help: add `#![feature(riscv_target_feature)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the target feature `f` is allowed in cfg but unstable otherwise - --> $DIR/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs:15:18 - | -LL | #[target_feature(enable = "f")] - | ^^^^^^^^^^^^ - | - = note: see issue #150257 for more information - = help: add `#![feature(riscv_target_feature)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs deleted file mode 100644 index ab2b75ed5190f..0000000000000 --- a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs +++ /dev/null @@ -1,17 +0,0 @@ -//! Ensure cfg-only stable target_features trigger warnings when enabled via compile flag. -//@ check-pass -//@ compile-flags: --crate-type=lib -//@ compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=+v -Ctarget-feature=+f -// FIXME(#147881): *disable* the feature again for minicore as otherwise that will fail to build. -//@ minicore-compile-flags: -Ctarget-feature=-v -Ctarget-feature=-f -//@ needs-llvm-components: riscv -//@ ignore-backends: gcc -//@ add-minicore -#![feature(no_core)] -#![no_core] - -extern crate minicore; -use minicore::*; - -//~? WARN unstable feature specified for `-Ctarget-feature` -//~? WARN unstable feature specified for `-Ctarget-feature` diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr deleted file mode 100644 index b0167221aabaa..0000000000000 --- a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr +++ /dev/null @@ -1,10 +0,0 @@ -warning: unstable feature specified for `-Ctarget-feature`: `v` - | - = note: this feature is not stably supported; its behavior can change in the future - -warning: unstable feature specified for `-Ctarget-feature`: `f` - | - = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future - -warning: 2 warnings emitted - From d1d3129ad1c6f6d600ecadeb7a363ba06e1afb50 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 11 Sep 2026 16:18:34 +1000 Subject: [PATCH 5/9] Improve the "no space between flag name and value" warning A command like `rustc -optimize a.rs` currently gives this: ``` warning: option `-o` has no space between flag name and value, which can be confusing note: output filename `-o ptimize` is applied instead of a flag named `optimize` help: insert a space between `-o` and `ptimize` if this is intentional: `-o ptimize` ``` A top-level warning, then a top-level note, then a top-level help. Weird! This commit converts the note and the help into children of the warning, which looks better and matches how things are normally done, giving this: ``` warning: option `-o` has no space between flag name and value, which can be confusing | = note: output filename `-o ptimize` is applied instead of a flag named `optimize` = help: insert a space between `-o` and `ptimize` if this is intentional: `-o ptimize` ``` Much better. --- compiler/rustc_driver_impl/src/lib.rs | 20 +++++++++-------- .../run-make/option-output-no-space/rmake.rs | 22 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index c935efe71edc1..5af05fa6fe0fd 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1344,15 +1344,17 @@ fn warn_on_confusing_output_filename_flag( || config::CG_OPTIONS.iter().any(|option| eq_ignore_separators(option.name(), filename)) || fake_args.iter().any(|arg| eq_ignore_separators(arg, filename)) { - early_dcx.early_warn( - "option `-o` has no space between flag name and value, which can be confusing", - ); - early_dcx.early_note(format!( - "output filename `-o {name}` is applied instead of a flag named `o{name}`" - )); - early_dcx.early_help(format!( - "insert a space between `-o` and `{name}` if this is intentional: `-o {name}`" - )); + early_dcx + .early_struct_warn( + "option `-o` has no space between flag name and value, which can be confusing", + ) + .with_note(format!( + "output filename `-o {name}` is applied instead of a flag named `o{name}`" + )) + .with_help(format!( + "insert a space between `-o` and `{name}` if this is intentional: `-o {name}`" + )) + .emit(); } } } diff --git a/tests/run-make/option-output-no-space/rmake.rs b/tests/run-make/option-output-no-space/rmake.rs index 2c42f15aa89a6..63d2389890155 100644 --- a/tests/run-make/option-output-no-space/rmake.rs +++ b/tests/run-make/option-output-no-space/rmake.rs @@ -14,7 +14,7 @@ fn main() { "warning: option `-o` has no space between flag name and value, which can be confusing", ) .assert_stderr_contains( - "note: output filename `-o ptimize` is applied instead of a flag named `optimize`", + "= note: output filename `-o ptimize` is applied instead of a flag named `optimize`", ); rustc() .input("main.rs") @@ -24,7 +24,7 @@ fn main() { "warning: option `-o` has no space between flag name and value, which can be confusing", ) .assert_stderr_contains( - "note: output filename `-o 0` is applied instead of a flag named `o0`", + "= note: output filename `-o 0` is applied instead of a flag named `o0`", ); rustc().input("main.rs").arg("-o1").run(); // test real args by iter optgroups @@ -36,10 +36,10 @@ fn main() { "warning: option `-o` has no space between flag name and value, which can be confusing", ) .assert_stderr_contains( - "note: output filename `-o ut-dir` is applied instead of a flag named `out-dir`", + "= note: output filename `-o ut-dir` is applied instead of a flag named `out-dir`", ) .assert_stderr_contains( - "help: insert a space between `-o` and `ut-dir` if this is intentional: `-o ut-dir`", + "= help: insert a space between `-o` and `ut-dir` if this is intentional: `-o ut-dir`", ); // test real args by iter CG_OPTIONS rustc() @@ -50,10 +50,11 @@ fn main() { "warning: option `-o` has no space between flag name and value, which can be confusing", ) .assert_stderr_contains( - "note: output filename `-o pt_level` is applied instead of a flag named `opt_level`", + "= note: output filename `-o pt_level` is applied instead of a flag named `opt_level`", ) .assert_stderr_contains( - "help: insert a space between `-o` and `pt_level` if this is intentional: `-o pt_level`" + "= help: insert a space between `-o` and `pt_level` if this is intentional: \ + `-o pt_level`", ); // separater in-sensitive rustc() @@ -64,10 +65,11 @@ fn main() { "warning: option `-o` has no space between flag name and value, which can be confusing", ) .assert_stderr_contains( - "note: output filename `-o pt-level` is applied instead of a flag named `opt-level`", + "= note: output filename `-o pt-level` is applied instead of a flag named `opt-level`", ) .assert_stderr_contains( - "help: insert a space between `-o` and `pt-level` if this is intentional: `-o pt-level`" + "= help: insert a space between `-o` and `pt-level` if this is intentional: \ + `-o pt-level`", ); rustc() .input("main.rs") @@ -77,11 +79,11 @@ fn main() { "warning: option `-o` has no space between flag name and value, which can be confusing", ) .assert_stderr_contains( - "note: output filename `-o verflow-checks` \ + "= note: output filename `-o verflow-checks` \ is applied instead of a flag named `overflow-checks`", ) .assert_stderr_contains( - "help: insert a space between `-o` and `verflow-checks` \ + "= help: insert a space between `-o` and `verflow-checks` \ if this is intentional: `-o verflow-checks`", ); From de902bb264c2250856dc54a8c41f1c369d0769b0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 11 Sep 2026 17:02:17 +1000 Subject: [PATCH 6/9] Improve nightly option parse errors Currently the command `rustc -Zunstable-options -j3 --jobs-backend=1 a.rs`, when run on stable rustc, gives this: ``` error: the option `Z` is only accepted on the nightly compiler error: the option `jobs` is only accepted on the nightly compiler error: the option `jobs-backend` is only accepted on the nightly compiler help: consider switching to a nightly toolchain: `rustup default nightly` note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see note: for more information about Rust's stability policy, see error: 3 nightly options were parsed ``` The errors are fine, but top-level help and notes are weird. This commit changes it to this, which is more normal: ``` error: the option `Z` is only accepted on the nightly compiler error: the option `jobs` is only accepted on the nightly compiler error: the option `jobs-backend` is only accepted on the nightly compiler error: 3 nightly options were parsed | = help: consider switching to a nightly toolchain: `rustup default nightly` = note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see = note: for more information about Rust's stability policy, see ``` It's a slightly different order but that seems fine. The commit also makes two other small improvements: - An unnecessary `match opt.stability` is removed. (There's another `opt.stability` check a few lines above.) - It fixes "1 nightly option were parsed" to "1 nightly option was parsed". --- compiler/rustc_session/src/config.rs | 39 +++++++++---------- .../rustc_bootstrap.force_stable.stderr | 12 +++--- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 2ae9dfdc9c2ad..d19566f8f632e 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3194,29 +3194,28 @@ pub mod nightly_options { if really_allows_unstable_options { continue; } - match opt.stability { - OptionStability::Unstable => { - nightly_options_on_stable += 1; - let msg = format!( - "the option `{}` is only accepted on the nightly compiler", - opt.name - ); - // The non-zero nightly_options_on_stable will force an early_fatal eventually. - let _ = early_dcx.early_err(msg); - } - OptionStability::Stable => {} - } + + nightly_options_on_stable += 1; + let msg = format!("the option `{}` is only accepted on the nightly compiler", opt.name); + // The non-zero nightly_options_on_stable will force an early_fatal eventually. + let _ = early_dcx.early_err(msg); } + if nightly_options_on_stable > 0 { - early_dcx - .early_help("consider switching to a nightly toolchain: `rustup default nightly`"); - early_dcx.early_note("selecting a toolchain with `+toolchain` arguments require a rustup proxy; see "); - early_dcx.early_note("for more information about Rust's stability policy, see "); - early_dcx.early_fatal(format!( - "{} nightly option{} were parsed", - nightly_options_on_stable, - if nightly_options_on_stable > 1 { "s" } else { "" } + let (s, were) = if nightly_options_on_stable > 1 { ("s", "were") } else { ("", "was") }; + let mut err = early_dcx.early_struct_fatal(format!( + "{nightly_options_on_stable} nightly option{s} {were} parsed", )); + err.help("consider switching to a nightly toolchain: `rustup default nightly`"); + err.note( + "selecting a toolchain with `+toolchain` arguments require a rustup proxy; \ + see ", + ); + err.note( + "for more information about Rust's stability policy, see \ + ", + ); + err.emit(); } } } diff --git a/tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr b/tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr index f378f3c70dd03..32f177e752ad0 100644 --- a/tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr +++ b/tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr @@ -1,10 +1,8 @@ error: the option `Z` is only accepted on the nightly compiler -help: consider switching to a nightly toolchain: `rustup default nightly` - -note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see - -note: for more information about Rust's stability policy, see - -error: 1 nightly option were parsed +error: 1 nightly option was parsed + | + = help: consider switching to a nightly toolchain: `rustup default nightly` + = note: selecting a toolchain with `+toolchain` arguments require a rustup proxy; see + = note: for more information about Rust's stability policy, see From 396d60358fd2ed02791b8f1115c6fe52ffd15b1a Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 11 Sep 2026 17:12:42 +1000 Subject: [PATCH 7/9] Remove `EarlyDiagCtxt::early_{note,help}` They're now unused. --- compiler/rustc_session/src/session.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 6b851250eae6e..17aa00d8339d0 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -1767,14 +1767,6 @@ impl EarlyDiagCtxt { self.dcx = DiagCtxt::new(emitter); } - pub fn early_note(&self, msg: impl Into) { - self.dcx.handle().note(msg) - } - - pub fn early_help(&self, msg: impl Into) { - self.dcx.handle().struct_help(msg).emit() - } - #[must_use = "raise_fatal must be called on the returned ErrorGuaranteed in order to exit with a non-zero status code"] pub fn early_err(&self, msg: impl Into) -> ErrorGuaranteed { self.dcx.handle().err(msg) From a3038b6b2deb1e027c9a63a014712536ebb42bf0 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Mon, 15 Jun 2026 20:52:19 -0400 Subject: [PATCH 8/9] Improve into_slice_range inlining --- library/core/src/slice/index.rs | 71 ++++++++++-------- library/core/src/str/traits.rs | 4 +- .../bounds-checking/bound-tuple.rs | 75 +++++++++++++++++++ .../slice-min.rs} | 0 4 files changed, 115 insertions(+), 35 deletions(-) create mode 100644 tests/codegen-llvm/bounds-checking/bound-tuple.rs rename tests/codegen-llvm/{bounds-check-elision-slice-min.rs => bounds-checking/slice-min.rs} (100%) diff --git a/library/core/src/slice/index.rs b/library/core/src/slice/index.rs index 47f934c37cab4..522603c574bad 100644 --- a/library/core/src/slice/index.rs +++ b/library/core/src/slice/index.rs @@ -938,7 +938,7 @@ where R: ops::RangeBounds, { let len = bounds.end; - try_into_slice_range(len, (range.start_bound().copied(), range.end_bound().copied())) + try_into_slice_range(len, (range.start_bound().copied(), range.end_bound().copied())).ok() } /// Converts a pair of `ops::Bound`s into `ops::Range` without performing any @@ -961,6 +961,24 @@ pub(crate) const fn into_range_unchecked( start..end } +#[derive(Clone, Copy)] +pub(crate) enum RangeError { + EndPastLen { end: usize }, + StartPastEnd { start: usize, end: usize }, +} + +impl RangeError { + #[cfg_attr(not(panic = "immediate-abort"), inline(never), cold)] + #[cfg_attr(panic = "immediate-abort", inline)] + #[track_caller] + const fn report(self, len: usize) -> ! { + match self { + Self::EndPastLen { end } => slice_index_fail(0, end, len), + Self::StartPastEnd { start, end } => slice_index_fail(start, end, len), + } + } +} + /// Converts pair of `ops::Bound`s into `ops::Range`. /// Returns `None` on overflowing indices. #[rustc_const_unstable(feature = "const_range", issue = "none")] @@ -968,62 +986,49 @@ pub(crate) const fn into_range_unchecked( pub(crate) const fn try_into_slice_range( len: usize, (start, end): (ops::Bound, ops::Bound), -) -> Option> { +) -> Result, RangeError> { let end = match end { - ops::Bound::Included(end) if end >= len => return None, + ops::Bound::Included(end) if end >= len => return Err(RangeError::EndPastLen { end }), // Cannot overflow because `end < len` implies `end < usize::MAX`. ops::Bound::Included(end) => end + 1, - ops::Bound::Excluded(end) if end > len => return None, + ops::Bound::Excluded(end) if end > len => return Err(RangeError::EndPastLen { end }), ops::Bound::Excluded(end) => end, ops::Bound::Unbounded => len, }; let start = match start { - ops::Bound::Excluded(start) if start >= end => return None, + ops::Bound::Excluded(start) if start >= end => { + return Err(RangeError::StartPastEnd { start, end }); + } // Cannot overflow because `start < end` implies `start < usize::MAX`. ops::Bound::Excluded(start) => start + 1, - ops::Bound::Included(start) if start > end => return None, + ops::Bound::Included(start) if start > end => { + return Err(RangeError::StartPastEnd { start, end }); + } ops::Bound::Included(start) => start, ops::Bound::Unbounded => 0, }; - Some(start..end) + Ok(start..end) } /// Converts pair of `ops::Bound`s into `ops::Range`. /// Panics on overflowing indices. #[inline] +#[track_caller] +#[rustc_const_unstable(feature = "const_range", issue = "none")] pub(crate) const fn into_slice_range( len: usize, - (start, end): (ops::Bound, ops::Bound), + bounds: (ops::Bound, ops::Bound), ) -> ops::Range { - let end = match end { - ops::Bound::Included(end) if end >= len => slice_index_fail(0, end, len), - // Cannot overflow because `end < len` implies `end < usize::MAX`. - ops::Bound::Included(end) => end + 1, - - ops::Bound::Excluded(end) if end > len => slice_index_fail(0, end, len), - ops::Bound::Excluded(end) => end, - - ops::Bound::Unbounded => len, - }; - - let start = match start { - ops::Bound::Excluded(start) if start >= end => slice_index_fail(start, end, len), - // Cannot overflow because `start < end` implies `start < usize::MAX`. - ops::Bound::Excluded(start) => start + 1, - - ops::Bound::Included(start) if start > end => slice_index_fail(start, end, len), - ops::Bound::Included(start) => start, - - ops::Bound::Unbounded => 0, - }; - - start..end + match try_into_slice_range(len, bounds) { + Ok(range) => range, + Err(e) => e.report(len), + } } #[stable(feature = "slice_index_with_ops_bound_pair", since = "1.53.0")] @@ -1032,13 +1037,13 @@ unsafe impl SliceIndex<[T]> for (ops::Bound, ops::Bound) { #[inline] fn get(self, slice: &[T]) -> Option<&Self::Output> { - try_into_slice_range(slice.len(), self)?.get(slice) + try_into_slice_range(slice.len(), self).ok()?.get(slice) } #[inline] #[rustc_no_writable] fn get_mut(self, slice: &mut [T]) -> Option<&mut Self::Output> { - try_into_slice_range(slice.len(), self)?.get_mut(slice) + try_into_slice_range(slice.len(), self).ok()?.get_mut(slice) } #[inline] diff --git a/library/core/src/str/traits.rs b/library/core/src/str/traits.rs index e4bf752ad2ae6..77fa6fcfbbb3c 100644 --- a/library/core/src/str/traits.rs +++ b/library/core/src/str/traits.rs @@ -367,12 +367,12 @@ unsafe impl SliceIndex for (ops::Bound, ops::Bound) { #[inline] fn get(self, slice: &str) -> Option<&str> { - crate::slice::index::try_into_slice_range(slice.len(), self)?.get(slice) + crate::slice::index::try_into_slice_range(slice.len(), self).ok()?.get(slice) } #[inline] fn get_mut(self, slice: &mut str) -> Option<&mut str> { - crate::slice::index::try_into_slice_range(slice.len(), self)?.get_mut(slice) + crate::slice::index::try_into_slice_range(slice.len(), self).ok()?.get_mut(slice) } #[inline] diff --git a/tests/codegen-llvm/bounds-checking/bound-tuple.rs b/tests/codegen-llvm/bounds-checking/bound-tuple.rs new file mode 100644 index 0000000000000..744901c437e71 --- /dev/null +++ b/tests/codegen-llvm/bounds-checking/bound-tuple.rs @@ -0,0 +1,75 @@ +//@ compile-flags: -O -Zmerge-functions=disabled +#![crate_type = "lib"] + +use std::collections::Bound; +use std::ops::RangeBounds; + +#[no_mangle] +pub fn raw_index(buf: &[u8]) -> Option<&[u8]> { + // CHECK-LABEL: @raw_index( + // CHECK-NOT: slice_index_fail + // CHECK-NOT: br {{.*}} + if buf.len() < 4 { None } else { Some(&buf[4..]) } +} + +#[no_mangle] +pub fn bounds_indexer(buf: &[u8]) -> Option<&[u8]> { + // CHECK-LABEL: @bounds_indexer( + // CHECK-NOT: slice_index_fail + // CHECK-NOT: br {{.*}} + // CHECK: ret + if buf.len() < 4 { None } else { Some(&buf[(Bound::Included(4), Bound::Unbounded)]) } +} + +#[no_mangle] +pub fn bounds_indexer_with_range_bounds(buf: &[u8]) -> Option<&[u8]> { + // CHECK-LABEL: @bounds_indexer_with_range_bounds( + // CHECK-NOT: slice_index_fail + // CHECK-NOT: br {{.*}} + // CHECK: ret + fn index(buf: &[u8], range: impl RangeBounds) -> &[u8] { + &buf[(range.start_bound().map(|x| *x), range.end_bound().map(|x| *x))] + } + + if buf.len() < 4 { None } else { Some(index(buf, 4..)) } +} + +/* +pub mod bounds_indexer_with_range_bounds_manual_map { + #[no_mangle] + pub fn test(buf: &[u8]) -> Option<&[u8]> { + if buf.len() < 4 { None } else { Some(index(buf, 4..)) } + } + + fn index(buf: &[u8], range: impl RangeBounds) -> &[u8] { + &buf[(match range.start_bound() { + Bound::Included(&i) => Bound::Included(i), + Bound::Excluded(&i) => Bound::Excluded(i), + Bound::Unbounded => Bound::Unbounded, + }, match range.end_bound() { + Bound::Included(&i) => Bound::Included(i), + Bound::Excluded(&i) => Bound::Excluded(i), + Bound::Unbounded => Bound::Unbounded, + })] + } +} + +pub mod bounds_indexer_with_range_bounds_manually_mapped { + #[no_mangle] + pub fn bounds_indexer_with_range_boundS_manually_mapped(buf: &[u8]) -> Option<&[u8]> { + if buf.len() < 4 { None } else { Some(manually_index(buf, 4..)) } + } + + fn index(buf: &[u8], range: impl RangeBounds) -> &[u8] { + &buf[match range.start_bound() { + Bound::Included(&i) => i, + Bound::Excluded(i) => i.checked_add(1).expect("overflow"), + Bound::Unbounded => 0, + }..match range.end_bound() { + Bound::Included(&i) => i, + Bound::Excluded(i) => i.checked_sub(1).expect("overflow"), + Bound::Unbounded => buf.len(), + }] + } +} +*/ diff --git a/tests/codegen-llvm/bounds-check-elision-slice-min.rs b/tests/codegen-llvm/bounds-checking/slice-min.rs similarity index 100% rename from tests/codegen-llvm/bounds-check-elision-slice-min.rs rename to tests/codegen-llvm/bounds-checking/slice-min.rs From 81e7f004bd1d30dc4bc674b25c87dffb7fa771d5 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 16 Jun 2026 21:27:39 -0400 Subject: [PATCH 9/9] Add all the codegen test cases --- .../bounds-checking/bound-tuple.rs | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/tests/codegen-llvm/bounds-checking/bound-tuple.rs b/tests/codegen-llvm/bounds-checking/bound-tuple.rs index 744901c437e71..06decaf3960bf 100644 --- a/tests/codegen-llvm/bounds-checking/bound-tuple.rs +++ b/tests/codegen-llvm/bounds-checking/bound-tuple.rs @@ -34,32 +34,36 @@ pub fn bounds_indexer_with_range_bounds(buf: &[u8]) -> Option<&[u8]> { if buf.len() < 4 { None } else { Some(index(buf, 4..)) } } -/* -pub mod bounds_indexer_with_range_bounds_manual_map { - #[no_mangle] - pub fn test(buf: &[u8]) -> Option<&[u8]> { - if buf.len() < 4 { None } else { Some(index(buf, 4..)) } - } - +#[no_mangle] +pub fn bounds_indexer_with_range_bounds_manual_map(buf: &[u8]) -> Option<&[u8]> { + // CHECK-LABEL: @bounds_indexer_with_range_bounds_manual_map( + // CHECK-NOT: slice_index_fail + // CHECK-NOT: br {{.*}} + // CHECK: ret fn index(buf: &[u8], range: impl RangeBounds) -> &[u8] { - &buf[(match range.start_bound() { - Bound::Included(&i) => Bound::Included(i), - Bound::Excluded(&i) => Bound::Excluded(i), - Bound::Unbounded => Bound::Unbounded, - }, match range.end_bound() { - Bound::Included(&i) => Bound::Included(i), - Bound::Excluded(&i) => Bound::Excluded(i), - Bound::Unbounded => Bound::Unbounded, - })] + &buf[( + match range.start_bound() { + Bound::Included(&i) => Bound::Included(i), + Bound::Excluded(&i) => Bound::Excluded(i), + Bound::Unbounded => Bound::Unbounded, + }, + match range.end_bound() { + Bound::Included(&i) => Bound::Included(i), + Bound::Excluded(&i) => Bound::Excluded(i), + Bound::Unbounded => Bound::Unbounded, + }, + )] } -} -pub mod bounds_indexer_with_range_bounds_manually_mapped { - #[no_mangle] - pub fn bounds_indexer_with_range_boundS_manually_mapped(buf: &[u8]) -> Option<&[u8]> { - if buf.len() < 4 { None } else { Some(manually_index(buf, 4..)) } - } + if buf.len() < 4 { None } else { Some(index(buf, 4..)) } +} +#[no_mangle] +pub fn bounds_indexer_with_range_bounds_manually_mapped(buf: &[u8]) -> Option<&[u8]> { + // CHECK-LABEL: @bounds_indexer_with_range_bounds_manually_mapped( + // CHECK-NOT: slice_index_fail + // CHECK-NOT: br {{.*}} + // CHECK: ret fn index(buf: &[u8], range: impl RangeBounds) -> &[u8] { &buf[match range.start_bound() { Bound::Included(&i) => i, @@ -71,5 +75,6 @@ pub mod bounds_indexer_with_range_bounds_manually_mapped { Bound::Unbounded => buf.len(), }] } + + if buf.len() < 4 { None } else { Some(index(buf, 4..)) } } -*/