Skip to content

Commit 7f8c8e9

Browse files
authored
Rollup merge of rust-lang#152729 - Enselic:single_use_consts-not-required, r=cjgillot
compiler: Don't mark `SingleUseConsts` MIR pass as "required for soundness" I don't think this MIR pass is required for soundness. The reasons are: * Something like it was not enabled by default before PR rust-lang#107404 which was the precursor to `SingleUseConsts` (see rust-lang#125910 for the switch). * By following the advice from rust-lang#128657 (comment) we can conclude it is not required for soundness since it has only ever run on MIR opt level > 0. * Its [`MirPass::can_be_overridden()`](https://github.com/rust-lang/rust/blob/0ee7d96253f92b15115c94a530db8b79cb341b15/compiler/rustc_mir_transform/src/pass_manager.rs#L98-L102) is unchanged and thus returns `true`, indicating that it is not a required MIR pass. * PR CI pass in rust-lang#151426 which stops enabling it by default in non-optimized builds. As shown in the updated test `tests/mir-opt/optimize_none.rs`, `#[optimize(none)]` functions become even less optimized, as expected and desired. Unblocks rust-lang#151426.
2 parents 9ba2d45 + 52b19f7 commit 7f8c8e9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

compiler/rustc_mir_transform/src/single_use_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
8585
}
8686

8787
fn is_required(&self) -> bool {
88-
true
88+
false
8989
}
9090
}
9191

tests/mir-opt/optimize_none.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ pub fn add_noopt() -> i32 {
1515
#[optimize(none)]
1616
pub fn const_branch() -> i32 {
1717
// CHECK-LABEL: fn const_branch(
18-
// CHECK: switchInt(const true) -> [0: [[FALSE:bb[0-9]+]], otherwise: [[TRUE:bb[0-9]+]]];
18+
// CHECK: [[BOOL:_[0-9]+]] = const true;
19+
// CHECK: switchInt(move [[BOOL]]) -> [0: [[BB_FALSE:bb[0-9]+]], otherwise: [[BB_TRUE:bb[0-9]+]]];
1920
// CHECK-NEXT: }
20-
// CHECK: [[FALSE]]: {
21+
// CHECK: [[BB_FALSE]]: {
2122
// CHECK-NEXT: _0 = const 0
2223
// CHECK-NEXT: goto
2324
// CHECK-NEXT: }
24-
// CHECK: [[TRUE]]: {
25+
// CHECK: [[BB_TRUE]]: {
2526
// CHECK-NEXT: _0 = const 1
2627
// CHECK-NEXT: goto
2728
// CHECK-NEXT: }

0 commit comments

Comments
 (0)