diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 10dbb3437dcbf..c31d4721db1b9 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -194,7 +194,7 @@ declare_passes! { Final }; mod simplify_comparison_integral : SimplifyComparisonIntegral; - mod single_use_consts : SingleUseConsts; + mod single_use_consts : SingleUseConsts { TempOnly, Full }; mod sroa : ScalarReplacementOfAggregates; mod strip_debuginfo : StripDebugInfo; mod unreachable_enum_branching : UnreachableEnumBranching; @@ -710,7 +710,8 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &simplify::SimplifyLocals::AfterGVN, &match_branches::MatchBranchSimplification, &dataflow_const_prop::DataflowConstProp, - &single_use_consts::SingleUseConsts, + &single_use_consts::SingleUseConsts::TempOnly, + &single_use_consts::SingleUseConsts::Full, &o1(simplify_branches::SimplifyConstCondition::AfterConstProp), &jump_threading::JumpThreading, &early_otherwise_branch::EarlyOtherwiseBranch, diff --git a/compiler/rustc_mir_transform/src/single_use_consts.rs b/compiler/rustc_mir_transform/src/single_use_consts.rs index 02caa92ad3fc8..e95c0bafea00c 100644 --- a/compiler/rustc_mir_transform/src/single_use_consts.rs +++ b/compiler/rustc_mir_transform/src/single_use_consts.rs @@ -19,11 +19,24 @@ use rustc_middle::ty::TyCtxt; /// /// It also removes *never*-used constants, since it had all the information /// needed to do that too, including updating the debug info. -pub(super) struct SingleUseConsts; +pub(super) enum SingleUseConsts { + TempOnly, + Full, +} impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts { + fn name(&self) -> &'static str { + match self { + SingleUseConsts::TempOnly => "SingleUseConsts-temp-only", + SingleUseConsts::Full => "SingleUseConsts-full", + } + } + fn is_enabled(&self, sess: &rustc_session::Session) -> bool { - sess.mir_opt_level() > 0 + match self { + SingleUseConsts::TempOnly => sess.mir_opt_level() == 1, + SingleUseConsts::Full => sess.mir_opt_level() > 1, + } } fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { @@ -46,6 +59,11 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts { continue; }; + let local_has_debug_info = finder.locals_in_debug_info.contains(local); + if local_has_debug_info && matches!(self, SingleUseConsts::TempOnly) { + continue; + } + // We're only changing an operand, not the terminator kinds or successors let basic_blocks = body.basic_blocks.as_mut_preserves_cfg(); let init_statement_kind = std::mem::replace( @@ -61,7 +79,7 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts { let mut replacer = LocalReplacer { tcx, local, operand: Some(operand) }; - if finder.locals_in_debug_info.contains(local) { + if local_has_debug_info { for var_debug_info in &mut body.var_debug_info { replacer.visit_var_debug_info(var_debug_info); } diff --git a/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff b/tests/mir-opt/const_debuginfo.main.SingleUseConsts-full.diff similarity index 97% rename from tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff rename to tests/mir-opt/const_debuginfo.main.SingleUseConsts-full.diff index 8088984bc77ab..34e8eb1e75b57 100644 --- a/tests/mir-opt/const_debuginfo.main.SingleUseConsts.diff +++ b/tests/mir-opt/const_debuginfo.main.SingleUseConsts-full.diff @@ -1,5 +1,5 @@ -- // MIR for `main` before SingleUseConsts -+ // MIR for `main` after SingleUseConsts +- // MIR for `main` before SingleUseConsts-full ++ // MIR for `main` after SingleUseConsts-full fn main() -> () { let mut _0: (); diff --git a/tests/mir-opt/const_debuginfo.rs b/tests/mir-opt/const_debuginfo.rs index 3b2bc4559ced9..c3f431da6d46f 100644 --- a/tests/mir-opt/const_debuginfo.rs +++ b/tests/mir-opt/const_debuginfo.rs @@ -1,4 +1,4 @@ -//@ test-mir-pass: SingleUseConsts +//@ test-mir-pass: SingleUseConsts-full //@ compile-flags: -C overflow-checks=no -Zmir-enable-passes=+GVN -Zdump-mir-exclude-alloc-bytes #![allow(unused)] @@ -8,7 +8,7 @@ struct Point { y: u32, } -// EMIT_MIR const_debuginfo.main.SingleUseConsts.diff +// EMIT_MIR const_debuginfo.main.SingleUseConsts-full.diff fn main() { // CHECK-LABEL: fn main( // CHECK: debug x => const 1_u8; diff --git a/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.panic-abort.diff similarity index 53% rename from tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts.panic-abort.diff rename to tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.panic-abort.diff index 8818c891e94b1..20c17e3198d4a 100644 --- a/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `assign_const_to_return` before SingleUseConsts -+ // MIR for `assign_const_to_return` after SingleUseConsts +- // MIR for `assign_const_to_return` before SingleUseConsts-temp-only ++ // MIR for `assign_const_to_return` after SingleUseConsts-temp-only fn assign_const_to_return() -> bool { let mut _0: bool; diff --git a/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.panic-unwind.diff similarity index 53% rename from tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts.panic-unwind.diff rename to tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.panic-unwind.diff index 8818c891e94b1..20c17e3198d4a 100644 --- a/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `assign_const_to_return` before SingleUseConsts -+ // MIR for `assign_const_to_return` after SingleUseConsts +- // MIR for `assign_const_to_return` before SingleUseConsts-temp-only ++ // MIR for `assign_const_to_return` after SingleUseConsts-temp-only fn assign_const_to_return() -> bool { let mut _0: bool; diff --git a/tests/mir-opt/single_use_consts.if_const.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.if_const.SingleUseConsts-temp-only.panic-abort.diff similarity index 83% rename from tests/mir-opt/single_use_consts.if_const.SingleUseConsts.panic-unwind.diff rename to tests/mir-opt/single_use_consts.if_const.SingleUseConsts-temp-only.panic-abort.diff index 468076e5ee3ce..f99d76f1909e8 100644 --- a/tests/mir-opt/single_use_consts.if_const.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.if_const.SingleUseConsts-temp-only.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `if_const` before SingleUseConsts -+ // MIR for `if_const` after SingleUseConsts +- // MIR for `if_const` before SingleUseConsts-temp-only ++ // MIR for `if_const` after SingleUseConsts-temp-only fn if_const() -> i32 { let mut _0: i32; diff --git a/tests/mir-opt/single_use_consts.if_const.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.if_const.SingleUseConsts-temp-only.panic-unwind.diff similarity index 83% rename from tests/mir-opt/single_use_consts.if_const.SingleUseConsts.panic-abort.diff rename to tests/mir-opt/single_use_consts.if_const.SingleUseConsts-temp-only.panic-unwind.diff index 468076e5ee3ce..f99d76f1909e8 100644 --- a/tests/mir-opt/single_use_consts.if_const.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.if_const.SingleUseConsts-temp-only.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `if_const` before SingleUseConsts -+ // MIR for `if_const` after SingleUseConsts +- // MIR for `if_const` before SingleUseConsts-temp-only ++ // MIR for `if_const` after SingleUseConsts-temp-only fn if_const() -> i32 { let mut _0: i32; diff --git a/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts-temp-only.panic-abort.diff similarity index 66% rename from tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts.panic-abort.diff rename to tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts-temp-only.panic-abort.diff index 0269c2cba202d..68f1866bbd45e 100644 --- a/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts-temp-only.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `if_const_debug` before SingleUseConsts -+ // MIR for `if_const_debug` after SingleUseConsts +- // MIR for `if_const_debug` before SingleUseConsts-temp-only ++ // MIR for `if_const_debug` after SingleUseConsts-temp-only fn if_const_debug() -> i32 { let mut _0: i32; @@ -7,14 +7,12 @@ let _2: (); let mut _3: bool; scope 1 { -- debug my_bool => _1; -+ debug my_bool => const ::ASSOC_BOOL; + debug my_bool => _1; } bb0: { StorageLive(_1); -- _1 = const ::ASSOC_BOOL; -+ nop; + _1 = const ::ASSOC_BOOL; StorageLive(_2); _2 = do_whatever() -> [return: bb1, unwind unreachable]; } @@ -22,8 +20,7 @@ bb1: { StorageDead(_2); StorageLive(_3); -- _3 = copy _1; -+ _3 = const ::ASSOC_BOOL; + _3 = copy _1; switchInt(move _3) -> [0: bb3, otherwise: bb2]; } diff --git a/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts-temp-only.panic-unwind.diff similarity index 66% rename from tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts.panic-unwind.diff rename to tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts-temp-only.panic-unwind.diff index 1285b8b33ba2d..47309df8d0bcb 100644 --- a/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.if_const_debug.SingleUseConsts-temp-only.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `if_const_debug` before SingleUseConsts -+ // MIR for `if_const_debug` after SingleUseConsts +- // MIR for `if_const_debug` before SingleUseConsts-temp-only ++ // MIR for `if_const_debug` after SingleUseConsts-temp-only fn if_const_debug() -> i32 { let mut _0: i32; @@ -7,14 +7,12 @@ let _2: (); let mut _3: bool; scope 1 { -- debug my_bool => _1; -+ debug my_bool => const ::ASSOC_BOOL; + debug my_bool => _1; } bb0: { StorageLive(_1); -- _1 = const ::ASSOC_BOOL; -+ nop; + _1 = const ::ASSOC_BOOL; StorageLive(_2); _2 = do_whatever() -> [return: bb1, unwind continue]; } @@ -22,8 +20,7 @@ bb1: { StorageDead(_2); StorageLive(_3); -- _3 = copy _1; -+ _3 = const ::ASSOC_BOOL; + _3 = copy _1; switchInt(move _3) -> [0: bb3, otherwise: bb2]; } diff --git a/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts-temp-only.panic-abort.diff similarity index 62% rename from tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts.panic-abort.diff rename to tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts-temp-only.panic-abort.diff index f7d823af9e3d7..1bad98f3779f7 100644 --- a/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts-temp-only.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `keep_parameter` before SingleUseConsts -+ // MIR for `keep_parameter` after SingleUseConsts +- // MIR for `keep_parameter` before SingleUseConsts-temp-only ++ // MIR for `keep_parameter` after SingleUseConsts-temp-only fn keep_parameter(_1: i32) -> () { debug other => _1; diff --git a/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts-temp-only.panic-unwind.diff similarity index 62% rename from tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts.panic-unwind.diff rename to tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts-temp-only.panic-unwind.diff index f7d823af9e3d7..1bad98f3779f7 100644 --- a/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.keep_parameter.SingleUseConsts-temp-only.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `keep_parameter` before SingleUseConsts -+ // MIR for `keep_parameter` after SingleUseConsts +- // MIR for `keep_parameter` before SingleUseConsts-temp-only ++ // MIR for `keep_parameter` after SingleUseConsts-temp-only fn keep_parameter(_1: i32) -> () { debug other => _1; diff --git a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts-temp-only.panic-abort.diff similarity index 84% rename from tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff rename to tests/mir-opt/single_use_consts.match_const.SingleUseConsts-temp-only.panic-abort.diff index 354e0988a0060..82f8f7a17c67d 100644 --- a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts-temp-only.panic-abort.diff @@ -1,5 +1,5 @@ -- // MIR for `match_const` before SingleUseConsts -+ // MIR for `match_const` after SingleUseConsts +- // MIR for `match_const` before SingleUseConsts-temp-only ++ // MIR for `match_const` after SingleUseConsts-temp-only fn match_const() -> &str { let mut _0: &str; diff --git a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts-temp-only.panic-unwind.diff similarity index 84% rename from tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff rename to tests/mir-opt/single_use_consts.match_const.SingleUseConsts-temp-only.panic-unwind.diff index 354e0988a0060..82f8f7a17c67d 100644 --- a/tests/mir-opt/single_use_consts.match_const.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.match_const.SingleUseConsts-temp-only.panic-unwind.diff @@ -1,5 +1,5 @@ -- // MIR for `match_const` before SingleUseConsts -+ // MIR for `match_const` after SingleUseConsts +- // MIR for `match_const` before SingleUseConsts-temp-only ++ // MIR for `match_const` after SingleUseConsts-temp-only fn match_const() -> &str { let mut _0: &str; diff --git a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts-temp-only.panic-abort.diff similarity index 60% rename from tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff rename to tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts-temp-only.panic-abort.diff index 5cf37dc97cbff..6522d89770f3b 100644 --- a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-abort.diff +++ b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts-temp-only.panic-abort.diff @@ -1,27 +1,24 @@ -- // MIR for `match_const_debug` before SingleUseConsts -+ // MIR for `match_const_debug` after SingleUseConsts +- // MIR for `match_const_debug` before SingleUseConsts-temp-only ++ // MIR for `match_const_debug` after SingleUseConsts-temp-only fn match_const_debug() -> &str { let mut _0: &str; let _1: i32; let _2: (); scope 1 { -- debug my_int => _1; -+ debug my_int => const ::ASSOC_INT; + debug my_int => _1; } bb0: { StorageLive(_1); -- _1 = const ::ASSOC_INT; -+ nop; + _1 = const ::ASSOC_INT; StorageLive(_2); _2 = do_whatever() -> [return: bb1, unwind unreachable]; } bb1: { StorageDead(_2); -- switchInt(copy _1) -> [7: bb4, 42: bb3, otherwise: bb2]; -+ switchInt(const ::ASSOC_INT) -> [7: bb4, 42: bb3, otherwise: bb2]; + switchInt(copy _1) -> [7: bb4, 42: bb3, otherwise: bb2]; } bb2: { diff --git a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts-temp-only.panic-unwind.diff similarity index 59% rename from tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff rename to tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts-temp-only.panic-unwind.diff index bdcf086e8d962..25450750e8d38 100644 --- a/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts.panic-unwind.diff +++ b/tests/mir-opt/single_use_consts.match_const_debug.SingleUseConsts-temp-only.panic-unwind.diff @@ -1,27 +1,24 @@ -- // MIR for `match_const_debug` before SingleUseConsts -+ // MIR for `match_const_debug` after SingleUseConsts +- // MIR for `match_const_debug` before SingleUseConsts-temp-only ++ // MIR for `match_const_debug` after SingleUseConsts-temp-only fn match_const_debug() -> &str { let mut _0: &str; let _1: i32; let _2: (); scope 1 { -- debug my_int => _1; -+ debug my_int => const ::ASSOC_INT; + debug my_int => _1; } bb0: { StorageLive(_1); -- _1 = const ::ASSOC_INT; -+ nop; + _1 = const ::ASSOC_INT; StorageLive(_2); _2 = do_whatever() -> [return: bb1, unwind continue]; } bb1: { StorageDead(_2); -- switchInt(copy _1) -> [7: bb4, 42: bb3, otherwise: bb2]; -+ switchInt(const ::ASSOC_INT) -> [7: bb4, 42: bb3, otherwise: bb2]; + switchInt(copy _1) -> [7: bb4, 42: bb3, otherwise: bb2]; } bb2: { diff --git a/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts-temp-only.panic-abort.diff b/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts-temp-only.panic-abort.diff new file mode 100644 index 0000000000000..d3cd0b7147caa --- /dev/null +++ b/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts-temp-only.panic-abort.diff @@ -0,0 +1,19 @@ +- // MIR for `never_used_debug` before SingleUseConsts-temp-only ++ // MIR for `never_used_debug` after SingleUseConsts-temp-only + + fn never_used_debug() -> () { + let mut _0: (); + let _1: i32; + scope 1 { + debug my_int => _1; + } + + bb0: { + StorageLive(_1); + _1 = const ::ASSOC_INT; + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts-temp-only.panic-unwind.diff b/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts-temp-only.panic-unwind.diff new file mode 100644 index 0000000000000..d3cd0b7147caa --- /dev/null +++ b/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts-temp-only.panic-unwind.diff @@ -0,0 +1,19 @@ +- // MIR for `never_used_debug` before SingleUseConsts-temp-only ++ // MIR for `never_used_debug` after SingleUseConsts-temp-only + + fn never_used_debug() -> () { + let mut _0: (); + let _1: i32; + scope 1 { + debug my_int => _1; + } + + bb0: { + StorageLive(_1); + _1 = const ::ASSOC_INT; + _0 = const (); + StorageDead(_1); + return; + } + } + diff --git a/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts.panic-abort.diff b/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts.panic-abort.diff deleted file mode 100644 index 8ef94a790a343..0000000000000 --- a/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts.panic-abort.diff +++ /dev/null @@ -1,21 +0,0 @@ -- // MIR for `never_used_debug` before SingleUseConsts -+ // MIR for `never_used_debug` after SingleUseConsts - - fn never_used_debug() -> () { - let mut _0: (); - let _1: i32; - scope 1 { -- debug my_int => _1; -+ debug my_int => const ::ASSOC_INT; - } - - bb0: { - StorageLive(_1); -- _1 = const ::ASSOC_INT; -+ nop; - _0 = const (); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts.panic-unwind.diff b/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts.panic-unwind.diff deleted file mode 100644 index 8ef94a790a343..0000000000000 --- a/tests/mir-opt/single_use_consts.never_used_debug.SingleUseConsts.panic-unwind.diff +++ /dev/null @@ -1,21 +0,0 @@ -- // MIR for `never_used_debug` before SingleUseConsts -+ // MIR for `never_used_debug` after SingleUseConsts - - fn never_used_debug() -> () { - let mut _0: (); - let _1: i32; - scope 1 { -- debug my_int => _1; -+ debug my_int => const ::ASSOC_INT; - } - - bb0: { - StorageLive(_1); -- _1 = const ::ASSOC_INT; -+ nop; - _0 = const (); - StorageDead(_1); - return; - } - } - diff --git a/tests/mir-opt/single_use_consts.rs b/tests/mir-opt/single_use_consts.rs index ecb602c647a50..78ef8c90d8c1b 100644 --- a/tests/mir-opt/single_use_consts.rs +++ b/tests/mir-opt/single_use_consts.rs @@ -1,4 +1,4 @@ -//@ test-mir-pass: SingleUseConsts +//@ test-mir-pass: SingleUseConsts-temp-only //@ compile-flags: -C debuginfo=full // EMIT_MIR_FOR_EACH_PANIC_STRATEGY @@ -7,14 +7,14 @@ trait MyTrait { const ASSOC_INT: i32; } -// EMIT_MIR single_use_consts.if_const.SingleUseConsts.diff +// EMIT_MIR single_use_consts.if_const.SingleUseConsts-temp-only.diff fn if_const() -> i32 { // CHECK-LABEL: fn if_const( // CHECK: switchInt(const ::ASSOC_BOOL) if T::ASSOC_BOOL { 7 } else { 42 } } -// EMIT_MIR single_use_consts.match_const.SingleUseConsts.diff +// EMIT_MIR single_use_consts.match_const.SingleUseConsts-temp-only.diff fn match_const() -> &'static str { // CHECK-LABEL: fn match_const( // CHECK: switchInt(const ::ASSOC_INT) @@ -25,23 +25,23 @@ fn match_const() -> &'static str { } } -// EMIT_MIR single_use_consts.if_const_debug.SingleUseConsts.diff +// EMIT_MIR single_use_consts.if_const_debug.SingleUseConsts-temp-only.diff fn if_const_debug() -> i32 { // CHECK-LABEL: fn if_const_debug( - // CHECK: my_bool => const ::ASSOC_BOOL; - // FIXME: `if` forces a temporary (unlike `match`), so the const isn't direct - // CHECK: _3 = const ::ASSOC_BOOL; + // Note: we must not reorder assignments for vars with debuginfo + // CHECK: my_bool => _1; + // CHECK: _3 = copy _1; // CHECK: switchInt(move _3) let my_bool = T::ASSOC_BOOL; do_whatever(); if my_bool { 7 } else { 42 } } -// EMIT_MIR single_use_consts.match_const_debug.SingleUseConsts.diff +// EMIT_MIR single_use_consts.match_const_debug.SingleUseConsts-temp-only.diff fn match_const_debug() -> &'static str { // CHECK-LABEL: fn match_const_debug( - // CHECK: my_int => const ::ASSOC_INT; - // CHECK: switchInt(const ::ASSOC_INT) + // CHECK: my_int => _1; + // CHECK: switchInt(copy _1) let my_int = T::ASSOC_INT; do_whatever(); match my_int { @@ -51,25 +51,23 @@ fn match_const_debug() -> &'static str { } } -// EMIT_MIR single_use_consts.never_used_debug.SingleUseConsts.diff +// EMIT_MIR single_use_consts.never_used_debug.SingleUseConsts-temp-only.diff #[allow(unused_variables)] fn never_used_debug() { // CHECK-LABEL: fn never_used_debug( - // CHECK: my_int => const ::ASSOC_INT; - // CHECK-NOT: ASSOC_INT - // CHECK: nop - // CHECK-NOT: ASSOC_INT + // CHECK: my_int => _1; + // CHECK: _1 = const ::ASSOC_INT let my_int = T::ASSOC_INT; } -// EMIT_MIR single_use_consts.assign_const_to_return.SingleUseConsts.diff +// EMIT_MIR single_use_consts.assign_const_to_return.SingleUseConsts-temp-only.diff fn assign_const_to_return() -> bool { // CHECK-LABEL: fn assign_const_to_return( // CHECK: _0 = const ::ASSOC_BOOL; T::ASSOC_BOOL } -// EMIT_MIR single_use_consts.keep_parameter.SingleUseConsts.diff +// EMIT_MIR single_use_consts.keep_parameter.SingleUseConsts-temp-only.diff fn keep_parameter(mut other: i32) { // CHECK-LABEL: fn keep_parameter( // CHECK: _1 = const ::ASSOC_INT;