From fefd06dc02eea5c5bd96aedce17a5e58c8645f9a 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 | 46 +++++++++++++++++++ 1 file changed, 46 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..374349732f9ef --- /dev/null +++ b/tests/ui/consts/control-flow/dead_branches_dont_eval.rs @@ -0,0 +1,46 @@ +//@ build-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 { + || {} + }; +} + +// without closures + +struct S(T); +impl S { + const C: () = panic!(); +} + +const fn bar() { S::::C } + +struct ConstIf(T); + +impl ConstIf { + const VAL: () = if N != 0 { + bar::() // not called for N == 0, and hence not monomorphized + } else { + () + }; +} + +fn main() { + let _val = Invoke::<(), 0>::FUN(); + let _val = ConstIf::<(), 0>::VAL; +}