interpret: refactor projection code to work on a common trait, and use that for visitors
This commit is contained in:
parent
a593de4fab
commit
a2bcafa500
44 changed files with 863 additions and 1210 deletions
|
@ -12,7 +12,8 @@ use rustc_errors::{
|
|||
use rustc_macros::HashStable;
|
||||
use rustc_session::CtfeBacktrace;
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_target::abi::{call, Align, Size, WrappingRange};
|
||||
use rustc_target::abi::{call, Align, Size, VariantIdx, WrappingRange};
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::{any::Any, backtrace::Backtrace, fmt};
|
||||
|
||||
|
@ -323,7 +324,9 @@ pub enum UndefinedBehaviorInfo<'a> {
|
|||
/// Data size is not equal to target size.
|
||||
ScalarSizeMismatch(ScalarSizeMismatch),
|
||||
/// A discriminant of an uninhabited enum variant is written.
|
||||
UninhabitedEnumVariantWritten,
|
||||
UninhabitedEnumVariantWritten(VariantIdx),
|
||||
/// An uninhabited enum variant is projected.
|
||||
UninhabitedEnumVariantRead(VariantIdx),
|
||||
/// Validation error.
|
||||
Validation(ValidationErrorInfo<'a>),
|
||||
// FIXME(fee1-dead) these should all be actual variants of the enum instead of dynamically
|
||||
|
@ -393,6 +396,7 @@ pub enum ValidationErrorKind<'tcx> {
|
|||
UnsafeCell,
|
||||
UninhabitedVal { ty: Ty<'tcx> },
|
||||
InvalidEnumTag { value: String },
|
||||
UninhabitedEnumTag,
|
||||
UninitEnumTag,
|
||||
UninitStr,
|
||||
Uninit { expected: ExpectedKind },
|
||||
|
|
|
@ -741,9 +741,9 @@ where
|
|||
|
||||
let fields = match this.ty.kind() {
|
||||
ty::Adt(def, _) if def.variants().is_empty() =>
|
||||
bug!("for_variant called on zero-variant enum"),
|
||||
bug!("for_variant called on zero-variant enum {}", this.ty),
|
||||
ty::Adt(def, _) => def.variant(variant_index).fields.len(),
|
||||
_ => bug!(),
|
||||
_ => bug!("`ty_and_layout_for_variant` on unexpected type {}", this.ty),
|
||||
};
|
||||
tcx.mk_layout(LayoutS {
|
||||
variants: Variants::Single { index: variant_index },
|
||||
|
|
|
@ -2670,11 +2670,6 @@ impl<'tcx> Ty<'tcx> {
|
|||
variant_index: VariantIdx,
|
||||
) -> Option<Discr<'tcx>> {
|
||||
match self.kind() {
|
||||
TyKind::Adt(adt, _) if adt.variants().is_empty() => {
|
||||
// This can actually happen during CTFE, see
|
||||
// https://github.com/rust-lang/rust/issues/89765.
|
||||
None
|
||||
}
|
||||
TyKind::Adt(adt, _) if adt.is_enum() => {
|
||||
Some(adt.discriminant_for_variant(tcx, variant_index))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue