Skip to content

Commit ddbc774

Browse files
committed
Replace mk_const with Const::new_x methods
1 parent cd68ead commit ddbc774

File tree

32 files changed

+219
-134
lines changed

32 files changed

+219
-134
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,10 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
386386
.type_of(param.def_id)
387387
.no_bound_vars()
388388
.expect("ct params cannot have early bound vars");
389-
tcx.mk_const(
390-
ty::ConstKind::Bound(
391-
ty::INNERMOST,
392-
ty::BoundVar::from_usize(num_bound_vars),
393-
),
389+
ty::Const::new_bound(
390+
tcx,
391+
ty::INNERMOST,
392+
ty::BoundVar::from_usize(num_bound_vars),
394393
ty,
395394
)
396395
.into()

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19701970
assert!(!ct.ty().has_escaping_bound_vars());
19711971

19721972
match ct.kind() {
1973-
ty::ConstKind::Bound(_, bv) => self.tcx.mk_const(
1973+
ty::ConstKind::Bound(_, bv) => ty::Const::new_placeholder(
1974+
self.tcx,
19741975
ty::PlaceholderConst { universe: self.universe, bound: bv },
19751976
ct.ty(),
19761977
),

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,11 +2047,10 @@ pub(super) fn check_type_bounds<'tcx>(
20472047
GenericParamDefKind::Const { .. } => {
20482048
let bound_var = ty::BoundVariableKind::Const;
20492049
bound_vars.push(bound_var);
2050-
tcx.mk_const(
2051-
ty::ConstKind::Bound(
2052-
ty::INNERMOST,
2053-
ty::BoundVar::from_usize(bound_vars.len() - 1),
2054-
),
2050+
ty::Const::new_bound(
2051+
tcx,
2052+
ty::INNERMOST,
2053+
ty::BoundVar::from_usize(bound_vars.len() - 1),
20552054
tcx.type_of(param.def_id)
20562055
.no_bound_vars()
20572056
.expect("const parameter types cannot be generic"),

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
243243
let name = param.name.ident().name;
244244
let param_const = ty::ParamConst::new(index, name);
245245

246-
let ct_ty = tcx.type_of(param.def_id.to_def_id()).subst_identity();
246+
let ct_ty = tcx
247+
.type_of(param.def_id.to_def_id())
248+
.no_bound_vars()
249+
.expect("const parameters cannot be generic");
247250

248-
let ct = tcx.mk_const(param_const, ct_ty);
251+
let ct = ty::Const::new_param(tcx, param_const, ct_ty);
249252

250253
predicates.insert((
251254
ty::ClauseKind::ConstArgHasType(ct, ct_ty).to_predicate(tcx),

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
497497
// any equated inference vars correctly!
498498
let root_vid = self.infcx.root_const_var(vid);
499499
if root_vid != vid {
500-
ct = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), ct.ty());
500+
ct = ty::Const::new_var(self.infcx.tcx, root_vid, ct.ty());
501501
vid = root_vid;
502502
}
503503

@@ -804,10 +804,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
804804
self.fold_const(bound_to)
805805
} else {
806806
let var = self.canonical_var(info, const_var.into());
807-
self.interner().mk_const(
808-
ty::ConstKind::Bound(self.binder_index, var),
809-
self.fold_ty(const_var.ty()),
810-
)
807+
ty::Const::new_bound(self.tcx, self.binder_index, var, self.fold_ty(const_var.ty()))
811808
}
812809
}
813810
}

compiler/rustc_infer/src/infer/canonical/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'tcx> InferCtxt<'tcx> {
155155
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }, ty) => {
156156
let universe_mapped = universe_map(universe);
157157
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
158-
self.tcx.mk_const(placeholder_mapped, ty).into()
158+
ty::Const::new_placeholder(self.tcx, placeholder_mapped, ty).into()
159159
}
160160
}
161161
}

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
9595
Entry::Vacant(entry) => {
9696
let index = self.const_freshen_count;
9797
self.const_freshen_count += 1;
98-
let ct = self.infcx.tcx.mk_const(freshener(index), ty);
98+
let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index), ty);
9999
entry.insert(ct);
100100
ct
101101
}

compiler/rustc_infer/src/infer/generalize.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ where
398398
origin: var_value.origin,
399399
val: ConstVariableValue::Unknown { universe: self.for_universe },
400400
});
401-
Ok(self.tcx().mk_const(new_var_id, c.ty()))
401+
Ok(ty::Const::new_var(self.tcx(), new_var_id, c.ty()))
402402
}
403403
}
404404
}
@@ -412,7 +412,11 @@ where
412412
substs,
413413
substs,
414414
)?;
415-
Ok(self.tcx().mk_const(ty::UnevaluatedConst { def, substs }, c.ty()))
415+
Ok(ty::Const::new_unevaluated(
416+
self.tcx(),
417+
ty::UnevaluatedConst { def, substs },
418+
c.ty(),
419+
))
416420
}
417421
ty::ConstKind::Placeholder(placeholder) => {
418422
if self.for_universe.can_name(placeholder.universe) {

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ impl<'tcx> InferCtxt<'tcx> {
9494
})
9595
},
9696
consts: &mut |bound_var: ty::BoundVar, ty| {
97-
self.tcx.mk_const(
97+
ty::Const::new_placeholder(
98+
self.tcx,
9899
ty::PlaceholderConst { universe: next_universe, bound: bound_var },
99100
ty,
100101
)

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ impl<'tcx> InferCtxt<'tcx> {
999999
}
10001000

10011001
pub fn next_const_var(&self, ty: Ty<'tcx>, origin: ConstVariableOrigin) -> ty::Const<'tcx> {
1002-
self.tcx.mk_const(self.next_const_var_id(origin), ty)
1002+
ty::Const::new_var(self.tcx, self.next_const_var_id(origin), ty)
10031003
}
10041004

10051005
pub fn next_const_var_in_universe(
@@ -1013,7 +1013,7 @@ impl<'tcx> InferCtxt<'tcx> {
10131013
.borrow_mut()
10141014
.const_unification_table()
10151015
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } });
1016-
self.tcx.mk_const(vid, ty)
1016+
ty::Const::new_var(self.tcx, vid, ty)
10171017
}
10181018

10191019
pub fn next_const_var_id(&self, origin: ConstVariableOrigin) -> ConstVid<'tcx> {
@@ -1131,15 +1131,15 @@ impl<'tcx> InferCtxt<'tcx> {
11311131
origin,
11321132
val: ConstVariableValue::Unknown { universe: self.universe() },
11331133
});
1134-
self.tcx
1135-
.mk_const(
1136-
const_var_id,
1137-
self.tcx
1138-
.type_of(param.def_id)
1139-
.no_bound_vars()
1140-
.expect("const parameter types cannot be generic"),
1141-
)
1142-
.into()
1134+
ty::Const::new_var(
1135+
self.tcx,
1136+
const_var_id,
1137+
self.tcx
1138+
.type_of(param.def_id)
1139+
.no_bound_vars()
1140+
.expect("const parameter types cannot be generic"),
1141+
)
1142+
.into()
11431143
}
11441144
}
11451145
}
@@ -1472,7 +1472,7 @@ impl<'tcx> InferCtxt<'tcx> {
14721472
span: Option<Span>,
14731473
) -> Result<ty::Const<'tcx>, ErrorHandled> {
14741474
match self.const_eval_resolve(param_env, unevaluated, span) {
1475-
Ok(Some(val)) => Ok(self.tcx.mk_const(val, ty)),
1475+
Ok(Some(val)) => Ok(ty::Const::new_value(self.tcx, val, ty)),
14761476
Ok(None) => {
14771477
let tcx = self.tcx;
14781478
let def_id = unevaluated.def;
@@ -1964,7 +1964,8 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
19641964
if ty.has_non_region_param() || ty.has_non_region_infer() {
19651965
bug!("const `{c}`'s type should not reference params or types");
19661966
}
1967-
self.tcx.mk_const(
1967+
ty::Const::new_placeholder(
1968+
self.tcx,
19681969
ty::PlaceholderConst {
19691970
universe: ty::UniverseIndex::ROOT,
19701971
bound: ty::BoundVar::from_u32({

0 commit comments

Comments
 (0)