From 92da1107ffc2a34c41748e582926637bae84dbc1 Mon Sep 17 00:00:00 2001 From: The 8472 Date: Fri, 15 Mar 2024 22:25:00 +0100 Subject: [PATCH] add test for #122301 to cover behavior that's on stable if this ought to be broken it should at least happen intentionally --- .../control-flow/dead_branches_dont_eval.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/ui/consts/control-flow/dead_branches_dont_eval.rs diff --git a/tests/ui/consts/control-flow/dead_branches_dont_eval.rs b/tests/ui/consts/control-flow/dead_branches_dont_eval.rs new file mode 100644 index 0000000000000..49158ba85a963 --- /dev/null +++ b/tests/ui/consts/control-flow/dead_branches_dont_eval.rs @@ -0,0 +1,26 @@ +//@ check-pass + +// issue 122301 - currently the only way to supress +// const eval and codegen of code conditional on some other const + +struct Foo(T); + +impl Foo { + const BAR: () = if N == 0 { + panic!() + }; +} + +struct Invoke(T); + +impl Invoke { + const FUN: fn() = if N != 0 { + || Foo::::BAR + } else { + || {} + }; +} + +fn main() { + Invoke::<(), 0>::FUN(); +}