Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for #122301 to cover behavior that's on stable #122572

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions tests/ui/consts/control-flow/dead_branches_dont_eval.rs
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
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;
}
Loading