Change:
For example: Similar to , but with a different intrinsic. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
We can probably just put call in front of that if statement. A more precise way to implement this would be to exhaustively match on and forbid , , , , and here. This way we the intrinsic can still be evaluated for which is probably desirable.
claim
Hello, I'm interested in taking the desirable approach. How is the arm for variants like should be handled? Which macro is more appropriate for this situation?
I quickly grepped for and ended up with here. That only works once you know what to search for though.

Discussion:
ensure_monomorphic_enough(tcx, tp_ty)?; ConstValue::from_u64(tcx.type_id_hash(tp_ty)) } <del> sym::variant_count => { if let ty::Adt(ref adt, _) = tp_ty.kind() { ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx) } else { ConstValue::from_machine_usize(0u64, &tcx) } } </del> <ins> sym::variant_count => match tp_ty.kind() { ty::Adt(ref adt, _) => ConstValue::from_machine_usize(adt.variants.len() as u64, &tcx), ty::Projection(_) | ty::Opaque(_, _) | ty::Param(_) | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) => throw_inval!(TooGeneric), ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Foreign(_) | ty::Str | ty::Array(_, _) | ty::Slice(_) | ty::RawPtr(_) | ty::Ref(_, _, _) | ty::FnDef(_, _) | ty::FnPtr(_) | ty::Dynamic(_, _) | ty::Closure(_, _) | ty::Generator(_, _, _) | ty::GeneratorWitness(_) | ty::Never | ty::Tuple(_) | ty::Error(_) => ConstValue::from_machine_usize(0u64, &tcx), }, </ins> other => bug!("`{}` is not a zero arg intrinsic", other), }) }

<ins> // check-pass // Verify that variant count intrinsic can still evaluate for types like `Option<T>`. #![feature(variant_count)] pub struct GetVariantCount<T>(T); impl<T> GetVariantCount<T> { pub const VALUE: usize = std::mem::variant_count::<T>(); } const fn check_variant_count<T>() -> bool { matches!(GetVariantCount::<Option<T>>::VALUE, GetVariantCount::<Option<()>>::VALUE) } fn main() { assert!(check_variant_count::<()>()); } </ins>

<ins> // Test that `variant_count` only gets evaluated once the type is concrete enough. #![feature(variant_count)] pub struct GetVariantCount<T>(T); impl<T> GetVariantCount<T> { pub const VALUE: usize = std::mem::variant_count::<T>(); } const fn check_variant_count<T>() -> bool { matches!(GetVariantCount::<T>::VALUE, GetVariantCount::<T>::VALUE) //~^ ERROR constant pattern depends on a generic parameter //~| ERROR constant pattern depends on a generic parameter } fn main() { assert!(check_variant_count::<Option<()>>()); } </ins>

<ins> error: constant pattern depends on a generic parameter --> $DIR/issue-79137-toogeneric.rs:12:43 | LL |     matches!(GetVariantCount::<T>::VALUE, GetVariantCount::<T>::VALUE) |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: constant pattern depends on a generic parameter --> $DIR/issue-79137-toogeneric.rs:12:43 | LL |     matches!(GetVariantCount::<T>::VALUE, GetVariantCount::<T>::VALUE) |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors </ins>