Skip to content

Commit b2ed2dc

Browse files
compiler-errorseholk
authored andcommitted
Rename some variants
1 parent 12ec2f0 commit b2ed2dc

File tree

16 files changed

+38
-56
lines changed

16 files changed

+38
-56
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use rustc_middle::ty::subst::{GenericArgKind, SubstsRef, UserSubsts};
3131
use rustc_middle::ty::visit::TypeVisitable;
3232
use rustc_middle::ty::{
3333
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
34-
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, TraitObjectRepresentation, Ty, TyCtxt,
35-
UserType, UserTypeAnnotationIndex,
34+
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, Ty, TyCtxt, UserType,
35+
UserTypeAnnotationIndex,
3636
};
3737
use rustc_span::def_id::CRATE_DEF_ID;
3838
use rustc_span::{Span, DUMMY_SP};
@@ -2015,9 +2015,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20152015
//
20162016
// apply them to prove that the source type `Foo` implements `Clone` etc
20172017
let (existential_predicates, region) = match ty.kind() {
2018-
Dynamic(predicates, region, TraitObjectRepresentation::Sized) => {
2019-
(predicates, region)
2020-
}
2018+
Dynamic(predicates, region, ty::DynStar) => (predicates, region),
20212019
_ => panic!("Invalid dyn* cast_ty"),
20222020
};
20232021

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_index::vec::Idx;
1616
use rustc_middle::mir::{self, AssertKind, SwitchTargets};
1717
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
1818
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
19-
use rustc_middle::ty::{self, Instance, TraitObjectRepresentation, Ty, TypeVisitable};
19+
use rustc_middle::ty::{self, Instance, Ty, TypeVisitable};
2020
use rustc_span::source_map::Span;
2121
use rustc_span::{sym, Symbol};
2222
use rustc_symbol_mangling::typeid::typeid_for_fnabi;
@@ -398,7 +398,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
398398
let (drop_fn, fn_abi) = match ty.kind() {
399399
// FIXME(eddyb) perhaps move some of this logic into
400400
// `Instance::resolve_drop_in_place`?
401-
ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) => {
401+
ty::Dynamic(_, _, ty::Dyn) => {
402402
// IN THIS ARM, WE HAVE:
403403
// ty = *mut (dyn Trait)
404404
// which is: exists<T> ( *mut T, Vtable<T: Trait> )
@@ -428,7 +428,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
428428
fn_abi,
429429
)
430430
}
431-
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
431+
ty::Dynamic(_, _, ty::DynStar) => {
432432
// IN THIS ARM, WE HAVE:
433433
// ty = *mut (dyn* Trait)
434434
// which is: *mut exists<T: sizeof(T) == sizeof(usize)> (T, Vtable<T: Trait>)

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
279279
OperandValue::Pair(_, _) => todo!(),
280280
};
281281
let trait_ref =
282-
if let ty::Dynamic(data, _, ty::TraitObjectRepresentation::Sized) = cast.ty.kind() {
282+
if let ty::Dynamic(data, _, ty::DynStar) = cast.ty.kind() {
283283
data.principal()
284284
} else {
285285
bug!("Only valid to do a DynStar cast into a DynStar type")

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
110110
}
111111

112112
DynStar => {
113-
if let ty::Dynamic(data, _, ty::TraitObjectRepresentation::Sized) = cast_ty.kind() {
113+
if let ty::Dynamic(data, _, ty::DynStar) = cast_ty.kind() {
114114
// Initial cast from sized to dyn trait
115115
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
116116
let ptr = self.read_immediate(src)?.to_scalar();

compiler/rustc_middle/src/ty/cast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use crate::ty::{self, Ty};
55

66
use rustc_macros::HashStable;
7-
use rustc_type_ir::TraitObjectRepresentation;
87

98
/// Types that are represented as ints.
109
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -71,7 +70,7 @@ impl<'tcx> CastTy<'tcx> {
7170
ty::Adt(d, _) if d.is_enum() && d.is_payloadfree() => Some(CastTy::Int(IntTy::CEnum)),
7271
ty::RawPtr(mt) => Some(CastTy::Ptr(mt)),
7372
ty::FnPtr(..) => Some(CastTy::FnPtr),
74-
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => Some(CastTy::DynStar),
73+
ty::Dynamic(_, _, ty::DynStar) => Some(CastTy::DynStar),
7574
_ => None,
7675
}
7776
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ use rustc_span::{Span, DUMMY_SP};
6363
use rustc_target::abi::{Layout, LayoutS, TargetDataLayout, VariantIdx};
6464
use rustc_target::spec::abi;
6565
use rustc_type_ir::sty::TyKind::*;
66-
use rustc_type_ir::{
67-
InternAs, InternIteratorElement, Interner, TraitObjectRepresentation, TypeFlags,
68-
};
66+
use rustc_type_ir::{DynKind, InternAs, InternIteratorElement, Interner, TypeFlags};
6967

7068
use std::any::Any;
7169
use std::borrow::Borrow;
@@ -2547,7 +2545,7 @@ impl<'tcx> TyCtxt<'tcx> {
25472545
self,
25482546
obj: &'tcx List<ty::Binder<'tcx, ExistentialPredicate<'tcx>>>,
25492547
reg: ty::Region<'tcx>,
2550-
repr: TraitObjectRepresentation,
2548+
repr: DynKind,
25512549
) -> Ty<'tcx> {
25522550
self.mk_ty(Dynamic(obj, reg, repr))
25532551
}

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_target::abi::call::{
2121
};
2222
use rustc_target::abi::*;
2323
use rustc_target::spec::{abi::Abi as SpecAbi, HasTargetSpec, PanicStrategy, Target};
24-
use rustc_type_ir::TraitObjectRepresentation;
2524

2625
use std::cmp::{self, Ordering};
2726
use std::fmt;
@@ -626,7 +625,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
626625
tcx.intern_layout(self.scalar_pair(data_ptr, metadata))
627626
}
628627

629-
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
628+
ty::Dynamic(_, _, ty::DynStar) => {
630629
let mut pointer = scalar_unit(Pointer);
631630
pointer.valid_range_mut().start = 1;
632631
let mut vtable = scalar_unit(Pointer);
@@ -688,7 +687,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
688687

689688
// Odd unit types.
690689
ty::FnDef(..) => univariant(&[], &ReprOptions::default(), StructKind::AlwaysSized)?,
691-
ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) | ty::Foreign(..) => {
690+
ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => {
692691
let mut unit = self.univariant_uninterned(
693692
ty,
694693
&[],
@@ -2444,7 +2443,7 @@ where
24442443
| ty::FnDef(..)
24452444
| ty::GeneratorWitness(..)
24462445
| ty::Foreign(..)
2447-
| ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) => {
2446+
| ty::Dynamic(_, _, ty::Dyn) => {
24482447
bug!("TyAndLayout::field({:?}): not applicable", this)
24492448
}
24502449

@@ -2546,9 +2545,7 @@ where
25462545
}
25472546

25482547
// dyn* (both fields are usize-sized)
2549-
ty::Dynamic(_, _, TraitObjectRepresentation::Sized) => {
2550-
TyMaybeWithLayout::Ty(tcx.types.usize)
2551-
}
2548+
ty::Dynamic(_, _, ty::DynStar) => TyMaybeWithLayout::Ty(tcx.types.usize),
25522549

25532550
ty::Projection(_)
25542551
| ty::Bound(..)

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use std::ops::ControlFlow;
5858
use std::{fmt, str};
5959

6060
pub use crate::ty::diagnostics::*;
61+
pub use rustc_type_ir::DynKind::*;
6162
pub use rustc_type_ir::InferTy::*;
6263
pub use rustc_type_ir::RegionKind::*;
6364
pub use rustc_type_ir::TyKind::*;

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_session::cstore::{ExternCrate, ExternCrateSource};
1616
use rustc_span::symbol::{kw, Ident, Symbol};
1717
use rustc_target::abi::Size;
1818
use rustc_target::spec::abi::Abi;
19-
use rustc_type_ir::TraitObjectRepresentation;
2019

2120
use std::cell::Cell;
2221
use std::char;
@@ -626,8 +625,8 @@ pub trait PrettyPrinter<'tcx>:
626625
p!("(");
627626
}
628627
match repr {
629-
TraitObjectRepresentation::Unsized => p!("dyn "),
630-
TraitObjectRepresentation::Sized => p!("dyn* "),
628+
ty::Dyn => p!("dyn "),
629+
ty::DynStar => p!("dyn* "),
631630
}
632631
p!(print(data));
633632
if print_r {

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use ty::util::IntTypeExt;
3131

3232
use rustc_type_ir::sty::TyKind::*;
3333
use rustc_type_ir::RegionKind as IrRegionKind;
34-
use rustc_type_ir::{TraitObjectRepresentation, TyKind as IrTyKind};
34+
use rustc_type_ir::TyKind as IrTyKind;
3535

3636
// Re-export the `TyKind` from `rustc_type_ir` here for convenience
3737
#[rustc_diagnostic_item = "TyKind"]
@@ -1852,12 +1852,12 @@ impl<'tcx> Ty<'tcx> {
18521852

18531853
#[inline]
18541854
pub fn is_trait(self) -> bool {
1855-
matches!(self.kind(), Dynamic(_, _, TraitObjectRepresentation::Unsized))
1855+
matches!(self.kind(), Dynamic(_, _, ty::Dyn))
18561856
}
18571857

18581858
#[inline]
18591859
pub fn is_dyn_star(self) -> bool {
1860-
matches!(self.kind(), Dynamic(_, _, TraitObjectRepresentation::Sized))
1860+
matches!(self.kind(), Dynamic(_, _, ty::DynStar))
18611861
}
18621862

18631863
#[inline]

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,7 @@ use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCast};
189189
use rustc_middle::ty::print::with_no_trimmed_paths;
190190
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
191191
use rustc_middle::ty::{
192-
self, GenericParamDefKind, Instance, TraitObjectRepresentation, Ty, TyCtxt, TypeFoldable,
193-
TypeVisitable, VtblEntry,
192+
self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitable, VtblEntry,
194193
};
195194
use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, mir::visit::TyContext};
196195
use rustc_session::config::EntryFnType;
@@ -1115,9 +1114,7 @@ fn find_vtable_types_for_unsizing<'tcx>(
11151114
}
11161115

11171116
// T as dyn* Trait
1118-
(_, &ty::Dynamic(_, _, TraitObjectRepresentation::Sized)) => {
1119-
ptr_vtable(source_ty, target_ty)
1120-
}
1117+
(_, &ty::Dynamic(_, _, ty::DynStar)) => ptr_vtable(source_ty, target_ty),
11211118

11221119
(&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => {
11231120
assert_eq!(source_adt_def, target_adt_def);

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use rustc_hir::def_id::DefId;
2020
use rustc_middle::ty::abstract_const::{walk_abstract_const, AbstractConst};
2121
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst};
2222
use rustc_middle::ty::{
23-
self, EarlyBinder, TraitObjectRepresentation, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
24-
TypeVisitor,
23+
self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor,
2524
};
2625
use rustc_middle::ty::{Predicate, ToPredicate};
2726
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
@@ -601,8 +600,7 @@ fn object_ty_for_trait<'tcx>(
601600
let existential_predicates = tcx
602601
.mk_poly_existential_predicates(iter::once(trait_predicate).chain(projection_predicates));
603602

604-
let object_ty =
605-
tcx.mk_dynamic(existential_predicates, lifetime, TraitObjectRepresentation::Unsized);
603+
let object_ty = tcx.mk_dynamic(existential_predicates, lifetime, ty::Dyn);
606604

607605
debug!("object_ty_for_trait: object_ty=`{}`", object_ty);
608606

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use rustc_middle::ty::fold::BottomUpFolder;
3838
use rustc_middle::ty::print::with_no_trimmed_paths;
3939
use rustc_middle::ty::relate::TypeRelation;
4040
use rustc_middle::ty::subst::{Subst, SubstsRef};
41-
use rustc_middle::ty::TraitObjectRepresentation;
4241
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
4342
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitable};
4443
use rustc_span::symbol::sym;
@@ -1866,7 +1865,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18661865
| ty::Array(..)
18671866
| ty::Closure(..)
18681867
| ty::Never
1869-
| ty::Dynamic(_, _, TraitObjectRepresentation::Sized)
1868+
| ty::Dynamic(_, _, ty::DynStar)
18701869
| ty::Error(_) => {
18711870
// safe for everything
18721871
Where(ty::Binder::dummy(Vec::new()))

compiler/rustc_type_ir/src/sty.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ use rustc_serialize::{Decodable, Decoder, Encodable};
2020

2121
/// Specifies how a trait object is represented.
2222
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Encodable, Decodable)]
23-
pub enum TraitObjectRepresentation {
23+
pub enum DynKind {
2424
/// An unsized `dyn Trait` object
25-
Unsized,
25+
Dyn,
2626
/// A sized `dyn* Trait` object
27-
Sized,
27+
DynStar,
2828
}
2929

3030
// Manually implemented because deriving HashStable requires rustc_query_system, which would
3131
// create a cyclic dependency.
32-
impl<CTX> HashStable<CTX> for TraitObjectRepresentation {
32+
impl<CTX> HashStable<CTX> for DynKind {
3333
fn hash_stable(
3434
&self,
3535
hcx: &mut CTX,
@@ -116,7 +116,7 @@ pub enum TyKind<I: Interner> {
116116
FnPtr(I::PolyFnSig),
117117

118118
/// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`.
119-
Dynamic(I::ListBinderExistentialPredicate, I::Region, TraitObjectRepresentation),
119+
Dynamic(I::ListBinderExistentialPredicate, I::Region, DynKind),
120120

121121
/// The anonymous type of a closure. Used to represent the type of `|a| a`.
122122
///

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use rustc_hir::lang_items::LangItem;
2727
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
2828
use rustc_middle::middle::stability::AllowUnstable;
2929
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, Subst, SubstsRef};
30+
use rustc_middle::ty::DynKind;
3031
use rustc_middle::ty::GenericParamDefKind;
31-
use rustc_middle::ty::TraitObjectRepresentation;
3232
use rustc_middle::ty::{
3333
self, Const, DefIdTree, EarlyBinder, IsSuggestable, Ty, TyCtxt, TypeVisitable,
3434
};
@@ -1253,7 +1253,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12531253
trait_bounds: &[hir::PolyTraitRef<'_>],
12541254
lifetime: &hir::Lifetime,
12551255
borrowed: bool,
1256-
representation: TraitObjectRepresentation,
1256+
representation: DynKind,
12571257
) -> Ty<'tcx> {
12581258
let tcx = self.tcx();
12591259

@@ -2623,10 +2623,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26232623
hir::TyKind::TraitObject(bounds, ref lifetime, repr) => {
26242624
self.maybe_lint_bare_trait(ast_ty, in_path);
26252625
let repr = match repr {
2626-
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => {
2627-
TraitObjectRepresentation::Unsized
2628-
}
2629-
TraitObjectSyntax::DynStar => TraitObjectRepresentation::Sized,
2626+
TraitObjectSyntax::Dyn | TraitObjectSyntax::None => ty::Dyn,
2627+
TraitObjectSyntax::DynStar => ty::DynStar,
26302628
};
26312629
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr)
26322630
}

compiler/rustc_typeck/src/check/cast.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
4141
use rustc_middle::ty::cast::{CastKind, CastTy};
4242
use rustc_middle::ty::error::TypeError;
4343
use rustc_middle::ty::subst::SubstsRef;
44-
use rustc_middle::ty::{
45-
self, Binder, TraitObjectRepresentation, Ty, TypeAndMut, TypeVisitable, VariantDef,
46-
};
44+
use rustc_middle::ty::{self, Binder, Ty, TypeAndMut, TypeVisitable, VariantDef};
4745
use rustc_session::lint;
4846
use rustc_session::Session;
4947
use rustc_span::symbol::sym;
@@ -241,7 +239,7 @@ fn check_dyn_star_cast<'tcx>(
241239
//
242240
// this would return `existential_predicates = [?Self: Clone, ?Self: Debug]` and `region = 'static`.
243241
let (existential_predicates, region) = match cast_ty.kind() {
244-
ty::Dynamic(predicates, region, TraitObjectRepresentation::Sized) => (predicates, region),
242+
ty::Dynamic(predicates, region, ty::DynStar) => (predicates, region),
245243
_ => panic!("Invalid dyn* cast_ty"),
246244
};
247245

@@ -289,7 +287,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
289287
// cases now. We do a more thorough check at the end, once
290288
// inference is more completely known.
291289
match cast_ty.kind() {
292-
ty::Dynamic(_, _, TraitObjectRepresentation::Unsized) | ty::Slice(..) => {
290+
ty::Dynamic(_, _, ty::Dyn) | ty::Slice(..) => {
293291
let reported = check.report_cast_to_unsized_type(fcx);
294292
Err(reported)
295293
}

0 commit comments

Comments
 (0)