Skip to content

Commit f63847d

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 c09ebf9 commit f63847d

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_with_guaranteed(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.
@@ -1686,7 +1686,7 @@ impl<'tcx> TyCtxt<'tcx> {
16861686
// Avoid this in favour of more specific `mk_*` methods, where possible.
16871687
#[allow(rustc::usage_of_ty_tykind)]
16881688
#[inline]
1689-
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
1689+
pub fn mk_ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> {
16901690
self.interners.intern_ty(
16911691
st,
16921692
self.sess,
@@ -1751,12 +1751,12 @@ impl<'tcx> TyCtxt<'tcx> {
17511751
#[inline]
17521752
pub fn mk_adt(self, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
17531753
// Take a copy of substs so that we own the vectors inside.
1754-
self.mk_ty(Adt(def, substs))
1754+
self.mk_ty_from_kind(Adt(def, substs))
17551755
}
17561756

17571757
#[inline]
17581758
pub fn mk_foreign(self, def_id: DefId) -> Ty<'tcx> {
1759-
self.mk_ty(Foreign(def_id))
1759+
self.mk_ty_from_kind(Foreign(def_id))
17601760
}
17611761

17621762
fn mk_generic_adt(self, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> {
@@ -1773,7 +1773,7 @@ impl<'tcx> TyCtxt<'tcx> {
17731773
}
17741774
}
17751775
});
1776-
self.mk_ty(Adt(adt_def, substs))
1776+
self.mk_ty_from_kind(Adt(adt_def, substs))
17771777
}
17781778

17791779
#[inline]
@@ -1802,12 +1802,12 @@ impl<'tcx> TyCtxt<'tcx> {
18021802

18031803
#[inline]
18041804
pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
1805-
self.mk_ty(RawPtr(tm))
1805+
self.mk_ty_from_kind(RawPtr(tm))
18061806
}
18071807

18081808
#[inline]
18091809
pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> {
1810-
self.mk_ty(Ref(r, tm.ty, tm.mutbl))
1810+
self.mk_ty_from_kind(Ref(r, tm.ty, tm.mutbl))
18111811
}
18121812

18131813
#[inline]
@@ -1832,22 +1832,26 @@ impl<'tcx> TyCtxt<'tcx> {
18321832

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

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

18431843
#[inline]
18441844
pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> {
1845-
self.mk_ty(Slice(ty))
1845+
self.mk_ty_from_kind(Slice(ty))
18461846
}
18471847

18481848
#[inline]
18491849
pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> {
1850-
if ts.is_empty() { self.types.unit } else { self.mk_ty(Tuple(self.mk_type_list(&ts))) }
1850+
if ts.is_empty() {
1851+
self.types.unit
1852+
} else {
1853+
self.mk_ty_from_kind(Tuple(self.mk_type_list(&ts)))
1854+
}
18511855
}
18521856

18531857
pub fn mk_tup_from_iter<I, T>(self, iter: I) -> T::Output
@@ -1875,7 +1879,7 @@ impl<'tcx> TyCtxt<'tcx> {
18751879
substs: impl IntoIterator<Item = impl Into<GenericArg<'tcx>>>,
18761880
) -> Ty<'tcx> {
18771881
let substs = self.check_and_mk_substs(def_id, substs);
1878-
self.mk_ty(FnDef(def_id, substs))
1882+
self.mk_ty_from_kind(FnDef(def_id, substs))
18791883
}
18801884

18811885
#[inline(always)]
@@ -1900,7 +1904,7 @@ impl<'tcx> TyCtxt<'tcx> {
19001904

19011905
#[inline]
19021906
pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> {
1903-
self.mk_ty(FnPtr(fty))
1907+
self.mk_ty_from_kind(FnPtr(fty))
19041908
}
19051909

19061910
#[inline]
@@ -1910,7 +1914,7 @@ impl<'tcx> TyCtxt<'tcx> {
19101914
reg: ty::Region<'tcx>,
19111915
repr: DynKind,
19121916
) -> Ty<'tcx> {
1913-
self.mk_ty(Dynamic(obj, reg, repr))
1917+
self.mk_ty_from_kind(Dynamic(obj, reg, repr))
19141918
}
19151919

19161920
#[inline]
@@ -1924,7 +1928,7 @@ impl<'tcx> TyCtxt<'tcx> {
19241928

19251929
#[inline]
19261930
pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> {
1927-
self.mk_ty(Closure(closure_id, closure_substs))
1931+
self.mk_ty_from_kind(Closure(closure_id, closure_substs))
19281932
}
19291933

19301934
#[inline]
@@ -1934,12 +1938,12 @@ impl<'tcx> TyCtxt<'tcx> {
19341938
generator_substs: SubstsRef<'tcx>,
19351939
movability: hir::Movability,
19361940
) -> Ty<'tcx> {
1937-
self.mk_ty(Generator(id, generator_substs, movability))
1941+
self.mk_ty_from_kind(Generator(id, generator_substs, movability))
19381942
}
19391943

19401944
#[inline]
19411945
pub fn mk_generator_witness(self, types: ty::Binder<'tcx, &'tcx List<Ty<'tcx>>>) -> Ty<'tcx> {
1942-
self.mk_ty(GeneratorWitness(types))
1946+
self.mk_ty_from_kind(GeneratorWitness(types))
19431947
}
19441948

19451949
/// Creates a `&mut Context<'_>` [`Ty`] with erased lifetimes.
@@ -1953,7 +1957,7 @@ impl<'tcx> TyCtxt<'tcx> {
19531957

19541958
#[inline]
19551959
pub fn mk_generator_witness_mir(self, id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> {
1956-
self.mk_ty(GeneratorWitnessMIR(id, substs))
1960+
self.mk_ty_from_kind(GeneratorWitnessMIR(id, substs))
19571961
}
19581962

19591963
#[inline]
@@ -1964,17 +1968,21 @@ impl<'tcx> TyCtxt<'tcx> {
19641968
#[inline]
19651969
pub fn mk_ty_var(self, v: TyVid) -> Ty<'tcx> {
19661970
// Use a pre-interned one when possible.
1967-
self.types.ty_vars.get(v.as_usize()).copied().unwrap_or_else(|| self.mk_ty(Infer(TyVar(v))))
1971+
self.types
1972+
.ty_vars
1973+
.get(v.as_usize())
1974+
.copied()
1975+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(TyVar(v))))
19681976
}
19691977

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

19751983
#[inline]
19761984
pub fn mk_float_var(self, v: FloatVid) -> Ty<'tcx> {
1977-
self.mk_ty(Infer(FloatVar(v)))
1985+
self.mk_ty_from_kind(Infer(FloatVar(v)))
19781986
}
19791987

19801988
#[inline]
@@ -1984,7 +1992,7 @@ impl<'tcx> TyCtxt<'tcx> {
19841992
.fresh_tys
19851993
.get(n as usize)
19861994
.copied()
1987-
.unwrap_or_else(|| self.mk_ty(Infer(ty::FreshTy(n))))
1995+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshTy(n))))
19881996
}
19891997

19901998
#[inline]
@@ -1994,7 +2002,7 @@ impl<'tcx> TyCtxt<'tcx> {
19942002
.fresh_int_tys
19952003
.get(n as usize)
19962004
.copied()
1997-
.unwrap_or_else(|| self.mk_ty(Infer(ty::FreshIntTy(n))))
2005+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshIntTy(n))))
19982006
}
19992007

20002008
#[inline]
@@ -2004,12 +2012,12 @@ impl<'tcx> TyCtxt<'tcx> {
20042012
.fresh_float_tys
20052013
.get(n as usize)
20062014
.copied()
2007-
.unwrap_or_else(|| self.mk_ty(Infer(ty::FreshFloatTy(n))))
2015+
.unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshFloatTy(n))))
20082016
}
20092017

20102018
#[inline]
20112019
pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> {
2012-
self.mk_ty(Param(ParamTy { index, name }))
2020+
self.mk_ty_from_kind(Param(ParamTy { index, name }))
20132021
}
20142022

20152023
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> {
@@ -2031,17 +2039,17 @@ impl<'tcx> TyCtxt<'tcx> {
20312039

20322040
#[inline]
20332041
pub fn mk_bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> {
2034-
self.mk_ty(Bound(index, bound_ty))
2042+
self.mk_ty_from_kind(Bound(index, bound_ty))
20352043
}
20362044

20372045
#[inline]
20382046
pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> {
2039-
self.mk_ty(Placeholder(placeholder))
2047+
self.mk_ty_from_kind(Placeholder(placeholder))
20402048
}
20412049

20422050
#[inline]
20432051
pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> {
2044-
self.mk_ty(Alias(kind, alias_ty))
2052+
self.mk_ty_from_kind(Alias(kind, alias_ty))
20452053
}
20462054

20472055
#[inline]
@@ -2094,7 +2102,7 @@ impl<'tcx> TyCtxt<'tcx> {
20942102

20952103
// Avoid this in favour of more specific `mk_re_*` methods, where possible,
20962104
// to avoid the cost of the `match`.
2097-
pub fn mk_region(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> {
2105+
pub fn mk_region_from_kind(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> {
20982106
match kind {
20992107
ty::ReEarlyBound(region) => self.mk_re_early_bound(region),
21002108
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
@@ -487,7 +487,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
487487
| ty::Foreign(..) => return Ok(self),
488488
};
489489

490-
Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty(kind) })
490+
Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty_from_kind(kind) })
491491
}
492492
}
493493

compiler/rustc_traits/src/chalk/lowering.rs

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

0 commit comments

Comments
 (0)