diff options
| author | Trevor Gross <t.gross35@gmail.com> | 2025-04-29 12:28:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-29 12:28:22 -0400 |
| commit | a20fe8ff236c54cb32189761fd1db8f8db82053e (patch) | |
| tree | e8b4ab3249b8dcd9503b2688e3c9ae2e6c2add21 /compiler/rustc_const_eval/src/interpret/intrinsics.rs | |
| parent | 4f20444ad54afb014de86554b089256c75ac2825 (diff) | |
| parent | b023856f29743a288727d13d0d1044b8e0d3f9f3 (diff) | |
| download | rust-a20fe8ff236c54cb32189761fd1db8f8db82053e.tar.gz rust-a20fe8ff236c54cb32189761fd1db8f8db82053e.zip | |
Rollup merge of #139909 - oli-obk:or-patterns, r=BoxyUwU
implement or-patterns for pattern types These are necessary to represent `NonZeroI32`, as the range for that is `..0 | 1..`. The `rustc_scalar_layout_range_*` attributes avoided this by just implementing wraparound and having a single `1..=-1` range effectively. See https://rust-lang.zulipchat.com/#narrow/channel/481660-t-lang.2Fpattern-types/topic/.60or.20pattern.60.20representation.20in.20type.20system/with/504217694 for some background discussion cc https://github.com/rust-lang/rust/issues/123646 r? `@BoxyUwU`
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret/intrinsics.rs')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intrinsics.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 40c63f2b250..97d066ffe3f 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -61,16 +61,21 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( ensure_monomorphic_enough(tcx, tp_ty)?; ConstValue::from_u128(tcx.type_id_hash(tp_ty).as_u128()) } - sym::variant_count => match tp_ty.kind() { + sym::variant_count => match match tp_ty.kind() { + // Pattern types have the same number of variants as their base type. + // Even if we restrict e.g. which variants are valid, the variants are essentially just uninhabited. + // And `Result<(), !>` still has two variants according to `variant_count`. + ty::Pat(base, _) => *base, + _ => tp_ty, + } + .kind() + { // Correctly handles non-monomorphic calls, so there is no need for ensure_monomorphic_enough. ty::Adt(adt, _) => ConstValue::from_target_usize(adt.variants().len() as u64, &tcx), ty::Alias(..) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => { throw_inval!(TooGeneric) } - ty::Pat(_, pat) => match **pat { - ty::PatternKind::Range { .. } => ConstValue::from_target_usize(0u64, &tcx), - // Future pattern kinds may have more variants - }, + ty::Pat(..) => unreachable!(), ty::Bound(_, _) => bug!("bound ty during ctfe"), ty::Bool | ty::Char |
