X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_type_ir%2Fsrc%2Fsty.rs;h=f30ae82d7cdd2b4fd4d596c0e207f016efa4aada;hb=39b2a41b39b445bf7efab02f6eade16135d7df85;hp=9aa2be124e294871f24d11a82d2d168755d5fc00;hpb=d53962896075507ba88e489bd401f80b4fb71d83;p=rust.git diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 9aa2be124e2..f30ae82d7cd 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -19,19 +19,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable}; /// Specifies how a trait object is represented. -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Debug, - Encodable, - Decodable, - HashStable_Generic -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum DynKind { /// An unsized `dyn Trait` object Dyn, @@ -46,6 +35,13 @@ pub enum DynKind { DynStar, } +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] +pub enum AliasKind { + Projection, + Opaque, +} + /// Defines the kinds of types used by the type system. /// /// Types written by the user start out as `hir::TyKind` and get @@ -170,21 +166,8 @@ pub enum TyKind { /// A tuple type. For example, `(i32, bool)`. Tuple(I::ListTy), - /// The projection of an associated type. For example, - /// `>::N`. - Projection(I::ProjectionTy), - - /// Opaque (`impl Trait`) type found in a return type. - /// - /// The `DefId` comes either from - /// * the `impl Trait` ast::Ty node, - /// * or the `type Foo = impl Trait` declaration - /// - /// For RPIT the substitutions are for the generics of the function, - /// while for TAIT it is used for the generic parameters of the alias. - /// - /// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type. - Opaque(I::DefId, I::SubstsRef), + /// A projection or opaque type. Both of these types + Alias(AliasKind, I::AliasTy), /// A type parameter; for example, `T` in `fn f(x: T) {}`. Param(I::ParamTy), @@ -252,13 +235,12 @@ const fn tykind_discriminant(value: &TyKind) -> usize { GeneratorWitness(_) => 17, Never => 18, Tuple(_) => 19, - Projection(_) => 20, - Opaque(_, _) => 21, - Param(_) => 22, - Bound(_, _) => 23, - Placeholder(_) => 24, - Infer(_) => 25, - Error(_) => 26, + Alias(_, _) => 20, + Param(_) => 21, + Bound(_, _) => 22, + Placeholder(_) => 23, + Infer(_) => 24, + Error(_) => 25, } } @@ -268,9 +250,9 @@ fn clone(&self) -> Self { match self { Bool => Bool, Char => Char, - Int(i) => Int(i.clone()), - Uint(u) => Uint(u.clone()), - Float(f) => Float(f.clone()), + Int(i) => Int(*i), + Uint(u) => Uint(*u), + Float(f) => Float(*f), Adt(d, s) => Adt(d.clone(), s.clone()), Foreign(d) => Foreign(d.clone()), Str => Str, @@ -280,16 +262,15 @@ fn clone(&self) -> Self { Ref(r, t, m) => Ref(r.clone(), t.clone(), m.clone()), FnDef(d, s) => FnDef(d.clone(), s.clone()), FnPtr(s) => FnPtr(s.clone()), - Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), repr.clone()), + Dynamic(p, r, repr) => Dynamic(p.clone(), r.clone(), *repr), Closure(d, s) => Closure(d.clone(), s.clone()), Generator(d, s, m) => Generator(d.clone(), s.clone(), m.clone()), GeneratorWitness(g) => GeneratorWitness(g.clone()), Never => Never, Tuple(t) => Tuple(t.clone()), - Projection(p) => Projection(p.clone()), - Opaque(d, s) => Opaque(d.clone(), s.clone()), + Alias(k, p) => Alias(*k, p.clone()), Param(p) => Param(p.clone()), - Bound(d, b) => Bound(d.clone(), b.clone()), + Bound(d, b) => Bound(*d, b.clone()), Placeholder(p) => Placeholder(p.clone()), Infer(t) => Infer(t.clone()), Error(e) => Error(e.clone()), @@ -323,8 +304,7 @@ fn eq(&self, other: &TyKind) -> bool { } (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g, (Tuple(a_t), Tuple(b_t)) => a_t == b_t, - (Projection(a_p), Projection(b_p)) => a_p == b_p, - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d == b_d && a_s == b_s, + (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p, (Param(a_p), Param(b_p)) => a_p == b_p, (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b, (Placeholder(a_p), Placeholder(b_p)) => a_p == b_p, @@ -381,8 +361,7 @@ fn cmp(&self, other: &TyKind) -> Ordering { } (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g), (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), - (Projection(a_p), Projection(b_p)) => a_p.cmp(b_p), - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), + (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)), (Param(a_p), Param(b_p)) => a_p.cmp(b_p), (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), @@ -443,10 +422,9 @@ fn hash<__H: hash::Hasher>(&self, state: &mut __H) -> () { } GeneratorWitness(g) => g.hash(state), Tuple(t) => t.hash(state), - Projection(p) => p.hash(state), - Opaque(d, s) => { - d.hash(state); - s.hash(state) + Alias(i, p) => { + i.hash(state); + p.hash(state); } Param(p) => p.hash(state), Bound(d, b) => { @@ -485,8 +463,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g), Never => f.write_str("Never"), Tuple(t) => f.debug_tuple_field1_finish("Tuple", t), - Projection(p) => f.debug_tuple_field1_finish("Projection", p), - Opaque(d, s) => f.debug_tuple_field2_finish("Opaque", d, s), + Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a), Param(p) => f.debug_tuple_field1_finish("Param", p), Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b), Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p), @@ -513,7 +490,7 @@ impl Encodable for TyKind I::ListBinderExistentialPredicate: Encodable, I::BinderListTy: Encodable, I::ListTy: Encodable, - I::ProjectionTy: Encodable, + I::AliasTy: Encodable, I::ParamTy: Encodable, I::BoundTy: Encodable, I::PlaceholderType: Encodable, @@ -586,13 +563,10 @@ fn encode(&self, e: &mut E) { Tuple(substs) => e.emit_enum_variant(disc, |e| { substs.encode(e); }), - Projection(p) => e.emit_enum_variant(disc, |e| { + Alias(k, p) => e.emit_enum_variant(disc, |e| { + k.encode(e); p.encode(e); }), - Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| { - def_id.encode(e); - substs.encode(e); - }), Param(p) => e.emit_enum_variant(disc, |e| { p.encode(e); }), @@ -630,8 +604,9 @@ impl> Decodable for TyKind I::ListBinderExistentialPredicate: Decodable, I::BinderListTy: Decodable, I::ListTy: Decodable, - I::ProjectionTy: Decodable, + I::AliasTy: Decodable, I::ParamTy: Decodable, + I::AliasTy: Decodable, I::BoundTy: Decodable, I::PlaceholderType: Decodable, I::InferTy: Decodable, @@ -660,13 +635,12 @@ fn decode(d: &mut D) -> Self { 17 => GeneratorWitness(Decodable::decode(d)), 18 => Never, 19 => Tuple(Decodable::decode(d)), - 20 => Projection(Decodable::decode(d)), - 21 => Opaque(Decodable::decode(d), Decodable::decode(d)), - 22 => Param(Decodable::decode(d)), - 23 => Bound(Decodable::decode(d), Decodable::decode(d)), - 24 => Placeholder(Decodable::decode(d)), - 25 => Infer(Decodable::decode(d)), - 26 => Error(Decodable::decode(d)), + 20 => Alias(Decodable::decode(d), Decodable::decode(d)), + 21 => Param(Decodable::decode(d)), + 22 => Bound(Decodable::decode(d), Decodable::decode(d)), + 23 => Placeholder(Decodable::decode(d)), + 24 => Infer(Decodable::decode(d)), + 25 => Error(Decodable::decode(d)), _ => panic!( "{}", format!( @@ -695,7 +669,7 @@ impl HashStable for TyKind I::Mutability: HashStable, I::BinderListTy: HashStable, I::ListTy: HashStable, - I::ProjectionTy: HashStable, + I::AliasTy: HashStable, I::BoundTy: HashStable, I::ParamTy: HashStable, I::PlaceholderType: HashStable, @@ -772,13 +746,10 @@ fn hash_stable( Tuple(substs) => { substs.hash_stable(__hcx, __hasher); } - Projection(p) => { + Alias(k, p) => { + k.hash_stable(__hcx, __hasher); p.hash_stable(__hcx, __hasher); } - Opaque(def_id, substs) => { - def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); - } Param(p) => { p.hash_stable(__hcx, __hasher); } @@ -965,7 +936,7 @@ impl Clone for RegionKind { fn clone(&self) -> Self { match self { ReEarlyBound(r) => ReEarlyBound(r.clone()), - ReLateBound(d, r) => ReLateBound(d.clone(), r.clone()), + ReLateBound(d, r) => ReLateBound(*d, r.clone()), ReFree(r) => ReFree(r.clone()), ReStatic => ReStatic, ReVar(r) => ReVar(r.clone()),