Skip to content

Commit 11c2c59

Browse files
committed
Rename mk_{ty,region} as mk_{ty,region}_from_kind.
To discourage accidental use -- there are more specific `mk_*` functions for all `Ty` and `Region` kinds.
1 parent a980683 commit 11c2c59

File tree

4 files changed

+42
-34
lines changed

4 files changed

+42
-34
lines changed

compiler/rustc_middle/src/ty/codec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> {
207207
})
208208
} else {
209209
let tcx = decoder.interner();
210-
tcx.mk_ty(rustc_type_ir::TyKind::decode(decoder))
210+
tcx.mk_ty_from_kind(rustc_type_ir::TyKind::decode(decoder))
211211
}
212212
}
213213
}
@@ -263,7 +263,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for mir::Place<'tcx> {
263263

264264
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Region<'tcx> {
265265
fn decode(decoder: &mut D) -> Self {
266-
decoder.interner().mk_region(Decodable::decode(decoder))
266+
decoder.interner().mk_region_from_kind(Decodable::decode(decoder))
267267
}
268268
}
269269

compiler/rustc_middle/src/ty/context.rs

+38-30
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl<'tcx> TyCtxt<'tcx> {
720720
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
721721
#[track_caller]
722722
pub fn ty_error(self, reported: ErrorGuaranteed) -> Ty<'tcx> {
723-
self.mk_ty(Error(reported))
723+
self.mk_ty_from_kind(Error(reported))
724724
}
725725

726726
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
@@ -734,7 +734,7 @@ impl<'tcx> TyCtxt<'tcx> {
734734
#[track_caller]
735735
pub fn ty_error_with_message<S: Into<MultiSpan>>(self, span: S, msg: &str) -> Ty<'tcx> {
736736
let reported = self.sess.delay_span_bug(span, msg);
737-
self.mk_ty(Error(reported))
737+
self.mk_ty_from_kind(Error(reported))
738738
}
739739

740740
/// Constructs a `RegionKind::ReError` lifetime.
@@ -1681,7 +1681,7 @@ impl<'tcx> TyCtxt<'tcx> {
16811681
// Avoid this in favour of more specific `mk_*` methods, where possible.
16821682
#[allow(rustc::usage_of_ty_tykind)]
16831683
#[inline]
1684-
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
1684+
pub fn mk_ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> {
16851685
self.interners.intern_ty(
16861686
st,
16871687
self.sess,
@@ -1746,12 +1746,12 @@ impl<'tcx> TyCtxt<'tcx> {
17461746
#[inline]
17471747
pub fn mk_adt(self, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
17481748
// Take a copy of substs so that we own the vectors inside.
1749-
self.mk_ty(Adt(def, substs))
1749+
self.mk_ty_from_kind(Adt(def, substs))
17501750
}
17511751

17521752
#[inline]
17531753
pub fn mk_foreign(self, def_id: DefId) -> Ty<'tcx> {
1754-
self.mk_ty(Foreign(def_id))
1754+
self.mk_ty_from_kind(Foreign(def_id))
17551755
}
17561756

17571757
fn mk_generic_adt(self, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> {
@@ -1768,7 +1768,7 @@ impl<'tcx> TyCtxt<'tcx> {
17681768
}
17691769
}
17701770
});
1771-
self.mk_ty(Adt(adt_def, substs))
1771+
self.mk_ty_from_kind(Adt(adt_def, substs))
17721772
}
17731773

17741774
#[inline]
@@ -1797,12 +1797,12 @@ impl<'tcx> TyCtxt<'tcx> {
17971797

17981798
#[inline]
17991799
pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
1800-
self.mk_ty(RawPtr(tm))
1800+
self.mk_ty_from_kind(RawPtr(tm))
18011801
}
18021802

18031803
#[inline]
18041804
pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
1805-
self.mk_ty(Ref(r, tm.ty, tm.mutbl))
1805+
self.mk_ty_from_kind(Ref(r, tm.ty, tm.mutbl))
18061806
}
18071807

18081808
#[inline]
@@ -1827,22 +1827,26 @@ impl<'tcx> TyCtxt<'tcx> {
18271827

18281828
#[inline]
18291829
pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> {
1830-
self.mk_ty(Array(ty, ty::Const::from_target_usize(self, n)))
1830+
self.mk_ty_from_kind(Array(ty, ty::Const::from_target_usize(self, n)))
18311831
}
18321832

18331833
#[inline]
18341834
pub fn mk_array_with_const_len(self, ty: Ty<'tcx>, ct: Const<'tcx>) -> Ty<'tcx> {
1835-
self.mk_ty(Array(ty, ct))
1835+
self.mk_ty_from_kind(Array(ty, ct))
18361836
}
18371837

18381838
#[inline]
18391839
pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> {
1840-
self.mk_ty(Slice(ty))
1840+
self.mk_ty_from_kind(Slice(ty))
18411841
}
18421842

18431843
#[inline]
18441844
pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
1845-
if ts.is_empty() { self.types.unit } else { self.mk_ty(Tuple(self.mk_type_list(&ts))) }
1845+
if ts.is_empty() {
1846+
self.types.unit
1847+
} else {
1848+
self.mk_ty_from_kind(Tuple(self.mk_type_list(&ts)))
1849+
}
18461850
}
18471851

18481852
pub fn mk_tup_from_iter<I, T>(self, iter: I) -> T::Output
@@ -1870,7 +1874,7 @@ impl<'tcx> TyCtxt<'tcx> {
18701874
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
18711875
) -> Ty<'tcx> {
18721876
let substs = self.check_and_mk_substs(def_id, substs);
1873-
self.mk_ty(FnDef(def_id, substs))
1877+
self.mk_ty_from_kind(FnDef(def_id, substs))
18741878
}
18751879

18761880
#[inline(always)]
@@ -1895,7 +1899,7 @@ impl<'tcx> TyCtxt<'tcx> {
18951899

18961900
#[inline]
18971901
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
1898-
self.mk_ty(FnPtr(fty))
1902+
self.mk_ty_from_kind(FnPtr(fty))
18991903
}
19001904

19011905
#[inline]
@@ -1905,7 +1909,7 @@ impl<'tcx> TyCtxt<'tcx> {
19051909
reg: ty::Region<'tcx>,
19061910
repr: DynKind,
19071911
) -> Ty<'tcx> {
1908-
self.mk_ty(Dynamic(obj, reg, repr))
1912+
self.mk_ty_from_kind(Dynamic(obj, reg, repr))
19091913
}
19101914

19111915
#[inline]
@@ -1919,7 +1923,7 @@ impl<'tcx> TyCtxt<'tcx> {
19191923

19201924
#[inline]
19211925
pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> {
1922-
self.mk_ty(Closure(closure_id, closure_substs))
1926+
self.mk_ty_from_kind(Closure(closure_id, closure_substs))
19231927
}
19241928

19251929
#[inline]
@@ -1929,12 +1933,12 @@ impl<'tcx> TyCtxt<'tcx> {
19291933
generator_substs: SubstsRef<'tcx>,
19301934
movability: hir::Movability,
19311935
) -> Ty<'tcx> {
1932-
self.mk_ty(Generator(id, generator_substs, movability))
1936+
self.mk_ty_from_kind(Generator(id, generator_substs, movability))
19331937
}
19341938

19351939
#[inline]
19361940
pub fn mk_generator_witness(self, types: ty::Binder<'tcx, &'tcx List<Ty<'tcx>>>) -> Ty<'tcx> {
1937-
self.mk_ty(GeneratorWitness(types))
1941+
self.mk_ty_from_kind(GeneratorWitness(types))
19381942
}
19391943

19401944
/// Creates a `&mut Context<'_>` [`Ty`] with erased lifetimes.
@@ -1948,7 +1952,7 @@ impl<'tcx> TyCtxt<'tcx> {
19481952

19491953
#[inline]
19501954
pub fn mk_generator_witness_mir(self, id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
1951-
self.mk_ty(GeneratorWitnessMIR(id, substs))
1955+
self.mk_ty_from_kind(GeneratorWitnessMIR(id, substs))
19521956
}
19531957

19541958
#[inline]
@@ -1959,17 +1963,21 @@ impl<'tcx> TyCtxt<'tcx> {
19591963
#[inline]
19601964
pub fn mk_ty_var(self, v: TyVid) -> Ty<'tcx> {
19611965
// Use a pre-interned one when possible.
1962-
self.types.ty_vars.get(v.as_usize()).copied().unwrap_or_else(|| self.mk_ty(Infer(TyVar(v))))
1966+
self.types
1967+
.ty_vars
1968+
.get(v.as_usize())
1969+
.copied()
1970+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(TyVar(v))))
19631971
}
19641972

19651973
#[inline]
19661974
pub fn mk_int_var(self, v: IntVid) -> Ty<'tcx> {
1967-
self.mk_ty(Infer(IntVar(v)))
1975+
self.mk_ty_from_kind(Infer(IntVar(v)))
19681976
}
19691977

19701978
#[inline]
19711979
pub fn mk_float_var(self, v: FloatVid) -> Ty<'tcx> {
1972-
self.mk_ty(Infer(FloatVar(v)))
1980+
self.mk_ty_from_kind(Infer(FloatVar(v)))
19731981
}
19741982

19751983
#[inline]
@@ -1979,7 +1987,7 @@ impl<'tcx> TyCtxt<'tcx> {
19791987
.fresh_tys
19801988
.get(n as usize)
19811989
.copied()
1982-
.unwrap_or_else(|| self.mk_ty(Infer(ty::FreshTy(n))))
1990+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshTy(n))))
19831991
}
19841992

19851993
#[inline]
@@ -1989,7 +1997,7 @@ impl<'tcx> TyCtxt<'tcx> {
19891997
.fresh_int_tys
19901998
.get(n as usize)
19911999
.copied()
1992-
.unwrap_or_else(|| self.mk_ty(Infer(ty::FreshIntTy(n))))
2000+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshIntTy(n))))
19932001
}
19942002

19952003
#[inline]
@@ -1999,12 +2007,12 @@ impl<'tcx> TyCtxt<'tcx> {
19992007
.fresh_float_tys
20002008
.get(n as usize)
20012009
.copied()
2002-
.unwrap_or_else(|| self.mk_ty(Infer(ty::FreshFloatTy(n))))
2010+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshFloatTy(n))))
20032011
}
20042012

20052013
#[inline]
20062014
pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> {
2007-
self.mk_ty(Param(ParamTy { index, name }))
2015+
self.mk_ty_from_kind(Param(ParamTy { index, name }))
20082016
}
20092017

20102018
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
@@ -2026,17 +2034,17 @@ impl<'tcx> TyCtxt<'tcx> {
20262034

20272035
#[inline]
20282036
pub fn mk_bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> {
2029-
self.mk_ty(Bound(index, bound_ty))
2037+
self.mk_ty_from_kind(Bound(index, bound_ty))
20302038
}
20312039

20322040
#[inline]
20332041
pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> {
2034-
self.mk_ty(Placeholder(placeholder))
2042+
self.mk_ty_from_kind(Placeholder(placeholder))
20352043
}
20362044

20372045
#[inline]
20382046
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
2039-
self.mk_ty(Alias(kind, alias_ty))
2047+
self.mk_ty_from_kind(Alias(kind, alias_ty))
20402048
}
20412049

20422050
#[inline]
@@ -2089,7 +2097,7 @@ impl<'tcx> TyCtxt<'tcx> {
20892097

20902098
// Avoid this in favour of more specific `mk_re_*` methods, where possible,
20912099
// to avoid the cost of the `match`.
2092-
pub fn mk_region(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> {
2100+
pub fn mk_region_from_kind(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> {
20932101
match kind {
20942102
ty::ReEarlyBound(region) => self.mk_re_early_bound(region),
20952103
ty::ReLateBound(debruijn, region) => self.mk_re_late_bound(debruijn, region),

compiler/rustc_middle/src/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
513513
| ty::Foreign(..) => return Ok(self),
514514
};
515515

516-
Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty(kind) })
516+
Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty_from_kind(kind) })
517517
}
518518
}
519519

compiler/rustc_traits/src/chalk/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
489489
TyKind::InferenceVar(_, _) => unimplemented!(),
490490
TyKind::Dyn(_) => unimplemented!(),
491491
};
492-
interner.tcx.mk_ty(kind)
492+
interner.tcx.mk_ty_from_kind(kind)
493493
}
494494
}
495495

0 commit comments

Comments
 (0)