From 52b19f7dda198e0e9df00efabd02cb2937d4fc85 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Mon, 16 Feb 2026 20:56:23 +0100 Subject: [PATCH] compiler: Don't mark `SingleUseConsts` MIR pass as "required for soundness" Because: * Something like it did not exist before PR 107404 * That it is not run our mir-opt-level 0 indicates that it is not required for soundness * Its `MirPass::can_be_overridden()` is unchanged and thus returns true, indicating that it is not a required MIR pass. * No test fails in PR 151426 that stops enabling by default in non-optimized builds As can be seen from the updated test `tests/mir-opt/optimize_none.rs`, this means that `#[optimize(none)]` functions become even less optimized. As expected and as desired. --- compiler/rustc_mir_transform/src/single_use_consts.rs | 2 +- tests/mir-opt/optimize_none.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_mir_transform/src/single_use_consts.rs b/compiler/rustc_mir_transform/src/single_use_consts.rs index 02caa92ad3fc8..6d33736d64ecb 100644 --- a/compiler/rustc_mir_transform/src/single_use_consts.rs +++ b/compiler/rustc_mir_transform/src/single_use_consts.rs @@ -85,7 +85,7 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts { } fn is_required(&self) -> bool { - true + false } } diff --git a/tests/mir-opt/optimize_none.rs b/tests/mir-opt/optimize_none.rs index a5b541bd2b628..99efcc35e5955 100644 --- a/tests/mir-opt/optimize_none.rs +++ b/tests/mir-opt/optimize_none.rs @@ -15,13 +15,14 @@ pub fn add_noopt() -> i32 { #[optimize(none)] pub fn const_branch() -> i32 { // CHECK-LABEL: fn const_branch( - // CHECK: switchInt(const true) -> [0: [[FALSE:bb[0-9]+]], otherwise: [[TRUE:bb[0-9]+]]]; + // CHECK: [[BOOL:_[0-9]+]] = const true; + // CHECK: switchInt(move [[BOOL]]) -> [0: [[BB_FALSE:bb[0-9]+]], otherwise: [[BB_TRUE:bb[0-9]+]]]; // CHECK-NEXT: } - // CHECK: [[FALSE]]: { + // CHECK: [[BB_FALSE]]: { // CHECK-NEXT: _0 = const 0 // CHECK-NEXT: goto // CHECK-NEXT: } - // CHECK: [[TRUE]]: { + // CHECK: [[BB_TRUE]]: { // CHECK-NEXT: _0 = const 1 // CHECK-NEXT: goto // CHECK-NEXT: }