Closed
Description
For example:
#![feature(variant_count)]
fn a<T>() -> usize {
let v = [0u8; std::mem::variant_count::<T>()];
std::mem::size_of_val(&v)
}
fn b() -> usize {
let v = [0u8; std::mem::variant_count::<Result<(), ()>>()];
std::mem::size_of_val(&v)
}
fn main() {
println!("{}", a::<Result<(), ()>>());
println!("{}", b());
}
$ rustc a.rs
warning: cannot use constants which depend on generic parameters in types
--> a.rs:4:19
|
4 | let v = [0u8; std::mem::variant_count::<T>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(const_evaluatable_unchecked)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
warning: 1 warning emitted
$ ./a
0
2
Similar to #73976, but with a different intrinsic.
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.`#![feature(variant_count)]`Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessThis issue requires a nightly compiler in some way.