Skip to content

Commit

Permalink
Unrolled build for rust-lang#122572
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#122572 - the8472:test-const-deadness, r=RalfJung

add test for rust-lang#122301 to cover behavior that's on stable

If this ought to be broken it should at least happen intentionally

See rust-lang#122301
  • Loading branch information
rust-timer committed Mar 17, 2024
2 parents 35dfc67 + fefd06d commit 95c1961
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/ui/consts/control-flow/dead_branches_dont_eval.rs
Original file line number Diff line number Diff line change
@@ -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, const N: usize>(T);

impl<T, const N: usize> Foo<T, N> {
const BAR: () = if N == 0 {
panic!()
};
}

struct Invoke<T, const N: usize>(T);

impl<T, const N: usize> Invoke<T, N> {
const FUN: fn() = if N != 0 {
|| Foo::<T, N>::BAR
} else {
|| {}
};
}

// without closures

struct S<T>(T);
impl<T> S<T> {
const C: () = panic!();
}

const fn bar<T>() { S::<T>::C }

struct ConstIf<T, const N: usize>(T);

impl<T, const N: usize> ConstIf<T, N> {
const VAL: () = if N != 0 {
bar::<T>() // not called for N == 0, and hence not monomorphized
} else {
()
};
}

fn main() {
let _val = Invoke::<(), 0>::FUN();
let _val = ConstIf::<(), 0>::VAL;
}

0 comments on commit 95c1961

Please sign in to comment.