Skip to content

Commit 07e0e75

Browse files
committed
Move ParamTerm to term.rs
1 parent e3de992 commit 07e0e75

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub use self::sty::{
158158
};
159159
pub use self::subst::*;
160160
pub use self::symbol_name::SymbolName;
161-
pub use self::term::{Term, TermKind};
161+
pub use self::term::{ParamTerm, Term, TermKind};
162162
pub use self::trait_def::TraitDef;
163163
pub use self::ty_::Ty;
164164
pub use self::typeck_results::{
@@ -221,20 +221,6 @@ const TAG_MASK: usize = 0b11;
221221
const TYPE_TAG: usize = 0b00;
222222
const CONST_TAG: usize = 0b01;
223223

224-
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
225-
pub enum ParamTerm {
226-
Ty(ParamTy),
227-
Const(ParamConst),
228-
}
229-
230-
impl ParamTerm {
231-
pub fn index(self) -> usize {
232-
match self {
233-
ParamTerm::Ty(ty) => ty.index as usize,
234-
ParamTerm::Const(ct) => ct.index as usize,
235-
}
236-
}
237-
}
238224
pub trait ToPolyTraitRef<'tcx> {
239225
fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>;
240226
}

compiler/rustc_middle/src/ty/term.rs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use rustc_query_system::ich::StableHashingContext;
99

1010
use crate::ty::{
1111
self, AliasKind, AliasTy, Const, ConstKind, Decodable, Encodable, FallibleTypeFolder,
12-
GenericArg, Interned, Ty, TyCtxt, TyDecoder, TyEncoder, TypeFoldable, TypeVisitable,
13-
TypeVisitor, WithCachedTypeInfo, CONST_TAG, TAG_MASK, TYPE_TAG,
12+
GenericArg, Interned, ParamConst, ParamTy, Ty, TyCtxt, TyDecoder, TyEncoder, TypeFoldable,
13+
TypeVisitable, TypeVisitor, WithCachedTypeInfo, CONST_TAG, TAG_MASK, TYPE_TAG,
1414
};
1515

1616
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -26,6 +26,12 @@ pub enum TermKind<'tcx> {
2626
Const(Const<'tcx>),
2727
}
2828

29+
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
30+
pub enum ParamTerm {
31+
Ty(ParamTy),
32+
Const(ParamConst),
33+
}
34+
2935
impl<'tcx> Term<'tcx> {
3036
#[inline]
3137
pub fn unpack(self) -> TermKind<'tcx> {
@@ -89,26 +95,6 @@ impl<'tcx> Term<'tcx> {
8995
}
9096
}
9197

92-
impl<'tcx> TermKind<'tcx> {
93-
#[inline]
94-
pub(super) fn pack(self) -> Term<'tcx> {
95-
let (tag, ptr) = match self {
96-
TermKind::Ty(ty) => {
97-
// Ensure we can use the tag bits.
98-
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
99-
(TYPE_TAG, ty.0.0 as *const WithCachedTypeInfo<ty::TyKind<'tcx>> as usize)
100-
}
101-
TermKind::Const(ct) => {
102-
// Ensure we can use the tag bits.
103-
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
104-
(CONST_TAG, ct.0.0 as *const ty::ConstData<'tcx> as usize)
105-
}
106-
};
107-
108-
Term { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData }
109-
}
110-
}
111-
11298
impl fmt::Debug for Term<'_> {
11399
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
114100
let data = if let Some(ty) = self.ty() {
@@ -167,3 +153,32 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Term<'tcx> {
167153
res.pack()
168154
}
169155
}
156+
157+
impl<'tcx> TermKind<'tcx> {
158+
#[inline]
159+
pub(super) fn pack(self) -> Term<'tcx> {
160+
let (tag, ptr) = match self {
161+
TermKind::Ty(ty) => {
162+
// Ensure we can use the tag bits.
163+
assert_eq!(mem::align_of_val(&*ty.0.0) & TAG_MASK, 0);
164+
(TYPE_TAG, ty.0.0 as *const WithCachedTypeInfo<ty::TyKind<'tcx>> as usize)
165+
}
166+
TermKind::Const(ct) => {
167+
// Ensure we can use the tag bits.
168+
assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0);
169+
(CONST_TAG, ct.0.0 as *const ty::ConstData<'tcx> as usize)
170+
}
171+
};
172+
173+
Term { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData }
174+
}
175+
}
176+
177+
impl ParamTerm {
178+
pub fn index(self) -> usize {
179+
match self {
180+
ParamTerm::Ty(ty) => ty.index as usize,
181+
ParamTerm::Const(ct) => ct.index as usize,
182+
}
183+
}
184+
}

0 commit comments

Comments
 (0)