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; +}