Skip to content

Commit d7fffab

Browse files
committed
compiler: Require mir_opt_level > 1 for SingleUseConsts
To make `tests/debuginfo/basic-stepping.rs` pass. Note that we must keep `SingleUseConsts` enabled for `tests/ui-fulldeps/rustc_public/check_allocation.rs` since its `fn collect_consts()` assumes that: VarDebugInfo { name: "_false", [...] value: Place( _5, ), } is transformed into which is what `SingleUseConsts` does: VarDebugInfo { name: "_false", [...] value: Const( [...] ), }
1 parent 004d710 commit d7fffab

4 files changed

Lines changed: 9 additions & 15 deletions

File tree

compiler/rustc_mir_transform/src/single_use_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(super) struct SingleUseConsts;
2323

2424
impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
2525
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
26-
sess.mir_opt_level() > 0
26+
sess.mir_opt_level() > 1
2727
}
2828

2929
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

tests/debuginfo/basic-stepping.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,19 @@
1010
// Debugger tests need debuginfo
1111
//@ compile-flags: -g
1212

13-
// FIXME(#128945): SingleUseConsts shouldn't need to be disabled.
14-
//@ revisions: default-mir-passes no-SingleUseConsts-mir-pass
15-
//@ [no-SingleUseConsts-mir-pass] compile-flags: -Zmir-enable-passes=-SingleUseConsts
16-
1713
//@ gdb-command: run
1814
// FIXME(#97083): Should we be able to break on initialization of zero-sized types?
1915
// FIXME(#97083): Right now the first breakable line is:
2016
//@ gdb-check: let mut c = 27;
2117
//@ gdb-command: next
2218
//@ gdb-check: let d = c = 99;
2319
//@ gdb-command: next
24-
//@ [no-SingleUseConsts-mir-pass] gdb-check: let e = "hi bob";
25-
//@ [no-SingleUseConsts-mir-pass] gdb-command: next
26-
//@ [no-SingleUseConsts-mir-pass] gdb-check: let f = b"hi bob";
27-
//@ [no-SingleUseConsts-mir-pass] gdb-command: next
28-
//@ [no-SingleUseConsts-mir-pass] gdb-check: let g = b'9';
29-
//@ [no-SingleUseConsts-mir-pass] gdb-command: next
20+
//@ gdb-check: let e = "hi bob";
21+
//@ gdb-command: next
22+
//@ gdb-check: let f = b"hi bob";
23+
//@ gdb-command: next
24+
//@ gdb-check: let g = b'9';
25+
//@ gdb-command: next
3026
//@ gdb-check: let h = ["whatever"; 8];
3127
//@ gdb-command: next
3228
//@ gdb-check: let i = [1,2,3,4];

tests/debuginfo/macro-stepping.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
extern crate macro_stepping; // exports new_scope!()
1616

1717
//@ compile-flags: -g
18-
// FIXME(#128945): SingleUseConsts shouldn't need to be disabled.
19-
//@ revisions: default-mir-passes no-SingleUseConsts-mir-pass
20-
//@ [no-SingleUseConsts-mir-pass] compile-flags: -Zmir-enable-passes=-SingleUseConsts
2118

2219
// === GDB TESTS ===================================================================================
2320

@@ -50,7 +47,7 @@ extern crate macro_stepping; // exports new_scope!()
5047
//@ gdb-check:[...]#inc-loc2[...]
5148
//@ gdb-command:next
5249
//@ gdb-command:frame
53-
//@ [no-SingleUseConsts-mir-pass] gdb-check:[...]#inc-loc3[...]
50+
//@ gdb-check:[...]#inc-loc3[...]
5451

5552
// === LLDB TESTS ==================================================================================
5653

tests/ui-fulldeps/rustc_public/check_allocation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ fn main() {
209209
generate_input(&path).unwrap();
210210
let args = &[
211211
"rustc".to_string(),
212+
"-Zmir-enable-passes=+SingleUseConsts".to_string(), // Needed for `fn collect_consts()`
212213
"--edition=2021".to_string(),
213214
"--crate-name".to_string(),
214215
CRATE_NAME.to_string(),

0 commit comments

Comments
 (0)