Rename some variants

This commit is contained in:
Michael Goulet 2022-08-29 03:53:33 +00:00 committed by Eric Holk
parent 12ec2f0e34
commit b2ed2dcaae
16 changed files with 38 additions and 56 deletions

View File

@ -31,8 +31,8 @@ use rustc_middle::ty::subst::{GenericArgKind, SubstsRef, UserSubsts};
use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, TraitObjectRepresentation, Ty, TyCtxt,
UserType, UserTypeAnnotationIndex,
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, Ty, TyCtxt, UserType,
UserTypeAnnotationIndex,
};
use rustc_span::def_id::CRATE_DEF_ID;
use rustc_span::{Span, DUMMY_SP};
@ -2015,9 +2015,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
//
// apply them to prove that the source type `Foo` implements `Clone` etc
let (existential_predicates, region) = match ty.kind() {
Dynamic(predicates, region, TraitObjectRepresentation::Sized) => {
(predicates, region)
}
Dynamic(predicates, region, ty::DynStar) => (predicates, region),
_ => panic!("Invalid dyn* cast_ty"),
};

View File

@ -16,7 +16,7 @@ use rustc_index::vec::Idx;
use rustc_middle::mir::{self, AssertKind, SwitchTargets};
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_middle::ty::{self, Instance, TraitObjectRepresentation, Ty, TypeVisitable};
use rustc_middle::ty::{self, Instance, Ty, TypeVisitable};
use rustc_span::source_map::Span;
use rustc_span::{sym, Symbol};
use rustc_symbol_mangling::typeid::typeid_for_fnabi;
@ -398,7 +398,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let (drop_fn, fn_abi) = match ty.kind() {
// FIXME(eddyb) perhaps move some of this logic into
// `Instance::resolve_drop_in_place`?
ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) => {
ty::Dynamic(_, _, ty::Dyn) => {
// IN THIS ARM, WE HAVE:
// ty = *mut (dyn Trait)
// which is: exists<T> ( *mut T, Vtable<T: Trait> )
@ -428,7 +428,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
fn_abi,
)
}
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
ty::Dynamic(_, _, ty::DynStar) => {
// IN THIS ARM, WE HAVE:
// ty = *mut (dyn* Trait)
// which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)

View File

@ -279,7 +279,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
OperandValue::Pair(_, _) => todo!(),
};
let trait_ref =
if let ty::Dynamic(data, _, ty::TraitObjectRepresentation::Sized) = cast.ty.kind() {
if let ty::Dynamic(data, _, ty::DynStar) = cast.ty.kind() {
data.principal()
} else {
bug!("Only valid to do a DynStar cast into a DynStar type")

View File

@ -110,7 +110,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
}
DynStar => {
if let ty::Dynamic(data, _, ty::TraitObjectRepresentation::Sized) = cast_ty.kind() {
if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() {
// Initial cast from sized to dyn trait
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
let ptr = self.read_immediate(src)?.to_scalar();

View File

@ -4,7 +4,6 @@
use crate::ty::{self, Ty};
use rustc_macros::HashStable;
use rustc_type_ir::TraitObjectRepresentation;
/// Types that are represented as ints.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -71,7 +70,7 @@ impl<'tcx> CastTy<'tcx> {
ty::Adt(d, _) if d.is_enum() && d.is_payloadfree() => Some(CastTy::Int(IntTy::CEnum)),
ty::RawPtr(mt) => Some(CastTy::Ptr(mt)),
ty::FnPtr(..) => Some(CastTy::FnPtr),
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => Some(CastTy::DynStar),
ty::Dynamic(_, _, ty::DynStar) => Some(CastTy::DynStar),
_ => None,
}
}

View File

@ -63,9 +63,7 @@ use rustc_span::{Span, DUMMY_SP};
use rustc_target::abi::{Layout, LayoutS, TargetDataLayout, VariantIdx};
use rustc_target::spec::abi;
use rustc_type_ir::sty::TyKind::*;
use rustc_type_ir::{
InternAs, InternIteratorElement, Interner, TraitObjectRepresentation, TypeFlags,
};
use rustc_type_ir::{DynKind, InternAs, InternIteratorElement, Interner, TypeFlags};
use std::any::Any;
use std::borrow::Borrow;
@ -2547,7 +2545,7 @@ impl<'tcx> TyCtxt<'tcx> {
self,
obj: &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>>,
reg: ty::Region<'tcx>,
repr: TraitObjectRepresentation,
repr: DynKind,
) -> Ty<'tcx> {
self.mk_ty(Dynamic(obj, reg, repr))
}

View File

@ -21,7 +21,6 @@ use rustc_target::abi::call::{
};
use rustc_target::abi::*;
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
use rustc_type_ir::TraitObjectRepresentation;
use std::cmp::{self, Ordering};
use std::fmt;
@ -626,7 +625,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
tcx.intern_layout(self.scalar_pair(data_ptr, metadata))
}
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
ty::Dynamic(_, _, ty::DynStar) => {
let mut pointer = scalar_unit(Pointer);
pointer.valid_range_mut().start = 1;
let mut vtable = scalar_unit(Pointer);
@ -688,7 +687,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
// Odd unit types.
ty::FnDef(..) => univariant(&[], &ReprOptions::default(), StructKind::AlwaysSized)?,
ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) | ty::Foreign(..) => {
ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => {
let mut unit = self.univariant_uninterned(
ty,
&[],
@ -2444,7 +2443,7 @@ where
| ty::FnDef(..)
| ty::GeneratorWitness(..)
| ty::Foreign(..)
| ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) => {
| ty::Dynamic(_, _, ty::Dyn) => {
bug!("TyAndLayout::field({:?}): not applicable", this)
}
@ -2546,9 +2545,7 @@ where
}
// dyn* (both fields are usize-sized)
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
TyMaybeWithLayout::Ty(tcx.types.usize)
}
ty::Dynamic(_, _, ty::DynStar) => TyMaybeWithLayout::Ty(tcx.types.usize),
ty::Projection(_)
| ty::Bound(..)

View File

@ -58,6 +58,7 @@ use std::ops::ControlFlow;
use std::{fmt, str};
pub use crate::ty::diagnostics::*;
pub use rustc_type_ir::DynKind::*;
pub use rustc_type_ir::InferTy::*;
pub use rustc_type_ir::RegionKind::*;
pub use rustc_type_ir::TyKind::*;

View File

@ -16,7 +16,6 @@ use rustc_session::cstore::{ExternCrate, ExternCrateSource};
use rustc_span::symbol::{kw, Ident, Symbol};
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use rustc_type_ir::TraitObjectRepresentation;
use std::cell::Cell;
use std::char;
@ -626,8 +625,8 @@ pub trait PrettyPrinter<'tcx>:
p!("(");
}
match repr {
TraitObjectRepresentation::Unsized => p!("dyn "),
TraitObjectRepresentation::Sized => p!("dyn* "),
ty::Dyn => p!("dyn "),
ty::DynStar => p!("dyn* "),
}
p!(print(data));
if print_r {

View File

@ -31,7 +31,7 @@ use ty::util::IntTypeExt;
use rustc_type_ir::sty::TyKind::*;
use rustc_type_ir::RegionKind as IrRegionKind;
use rustc_type_ir::{TraitObjectRepresentation, TyKind as IrTyKind};
use rustc_type_ir::TyKind as IrTyKind;
// Re-export the `TyKind` from `rustc_type_ir` here for convenience
#[rustc_diagnostic_item = "TyKind"]
@ -1852,12 +1852,12 @@ impl<'tcx> Ty<'tcx> {
#[inline]
pub fn is_trait(self) -> bool {
matches!(self.kind(), Dynamic(_, _, TraitObjectRepresentation::Unsized))
matches!(self.kind(), Dynamic(_, _, ty::Dyn))
}
#[inline]
pub fn is_dyn_star(self) -> bool {
matches!(self.kind(), Dynamic(_, _, TraitObjectRepresentation::Sized))
matches!(self.kind(), Dynamic(_, _, ty::DynStar))
}
#[inline]

View File

@ -189,8 +189,7 @@ use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCast};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
use rustc_middle::ty::{
self, GenericParamDefKind, Instance, TraitObjectRepresentation, Ty, TyCtxt, TypeFoldable,
TypeVisitable, VtblEntry,
self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitable, VtblEntry,
};
use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, mir::visit::TyContext};
use rustc_session::config::EntryFnType;
@ -1115,9 +1114,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
}
// T as dyn* Trait
(_, &ty::Dynamic(_, _, TraitObjectRepresentation::Sized)) => {
ptr_vtable(source_ty, target_ty)
}
(_, &ty::Dynamic(_, _, ty::DynStar)) => ptr_vtable(source_ty, target_ty),
(&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => {
assert_eq!(source_adt_def, target_adt_def);

View File

@ -20,8 +20,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::ty::abstract_const::{walk_abstract_const, AbstractConst};
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst};
use rustc_middle::ty::{
self, EarlyBinder, TraitObjectRepresentation, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
TypeVisitor,
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
};
use rustc_middle::ty::{Predicate, ToPredicate};
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
@ -601,8 +600,7 @@ fn object_ty_for_trait<'tcx>(
let existential_predicates = tcx
.mk_poly_existential_predicates(iter::once(trait_predicate).chain(projection_predicates));
let object_ty =
tcx.mk_dynamic(existential_predicates, lifetime, TraitObjectRepresentation::Unsized);
let object_ty = tcx.mk_dynamic(existential_predicates, lifetime, ty::Dyn);
debug!("object_ty_for_trait: object_ty=`{}`", object_ty);

View File

@ -38,7 +38,6 @@ use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::subst::{Subst, SubstsRef};
use rustc_middle::ty::TraitObjectRepresentation;
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitable};
use rustc_span::symbol::sym;
@ -1866,7 +1865,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::Array(..)
| ty::Closure(..)
| ty::Never
| ty::Dynamic(_, _, TraitObjectRepresentation::Sized)
| ty::Dynamic(_, _, ty::DynStar)
| ty::Error(_) => {
// safe for everything
Where(ty::Binder::dummy(Vec::new()))

View File

@ -20,16 +20,16 @@ use rustc_serialize::{Decodable, Decoder, Encodable};
/// Specifies how a trait object is represented.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)]
pub enum TraitObjectRepresentation {
pub enum DynKind {
/// An unsized `dyn Trait` object
Unsized,
Dyn,
/// A sized `dyn* Trait` object
Sized,
DynStar,
}
// Manually implemented because deriving HashStable requires rustc_query_system, which would
// create a cyclic dependency.
impl<CTX> HashStable<CTX> for TraitObjectRepresentation {
impl<CTX> HashStable<CTX> for DynKind {
fn hash_stable(
&self,
hcx: &mut CTX,
@ -116,7 +116,7 @@ pub enum TyKind<I: Interner> {
FnPtr(I::PolyFnSig),
/// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
Dynamic(I::ListBinderExistentialPredicate, I::Region, TraitObjectRepresentation),
Dynamic(I::ListBinderExistentialPredicate, I::Region, DynKind),
/// The anonymous type of a closure. Used to represent the type of `|a| a`.
///

View File

@ -27,8 +27,8 @@ use rustc_hir::lang_items::LangItem;
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
use rustc_middle::middle::stability::AllowUnstable;
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::DynKind;
use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::TraitObjectRepresentation;
use rustc_middle::ty::{
self, Const, DefIdTree, EarlyBinder, IsSuggestable, Ty, TyCtxt, TypeVisitable,
};
@ -1253,7 +1253,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
trait_bounds: &[hir::PolyTraitRef<'_>],
lifetime: &hir::Lifetime,
borrowed: bool,
representation: TraitObjectRepresentation,
representation: DynKind,
) -> Ty<'tcx> {
let tcx = self.tcx();
@ -2623,10 +2623,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
hir::TyKind::TraitObject(bounds, ref lifetime, repr) => {
self.maybe_lint_bare_trait(ast_ty, in_path);
let repr = match repr {
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => {
TraitObjectRepresentation::Unsized
}
TraitObjectSyntax::DynStar => TraitObjectRepresentation::Sized,
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn,
TraitObjectSyntax::DynStar => ty::DynStar,
};
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr)
}

View File

@ -41,9 +41,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::cast::{CastKind, CastTy};
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{
self, Binder, TraitObjectRepresentation, Ty, TypeAndMut, TypeVisitable, VariantDef,
};
use rustc_middle::ty::{self, Binder, Ty, TypeAndMut, TypeVisitable, VariantDef};
use rustc_session::lint;
use rustc_session::Session;
use rustc_span::symbol::sym;
@ -241,7 +239,7 @@ fn check_dyn_star_cast<'tcx>(
//
// this would return `existential_predicates = [?Self: Clone, ?Self: Debug]` and `region = 'static`.
let (existential_predicates, region) = match cast_ty.kind() {
ty::Dynamic(predicates, region, TraitObjectRepresentation::Sized) => (predicates, region),
ty::Dynamic(predicates, region, ty::DynStar) => (predicates, region),
_ => panic!("Invalid dyn* cast_ty"),
};
@ -289,7 +287,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
// cases now. We do a more thorough check at the end, once
// inference is more completely known.
match cast_ty.kind() {
ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) | ty::Slice(..) => {
ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => {
let reported = check.report_cast_to_unsized_type(fcx);
Err(reported)
}