Skip to content

Commit f20afcc

Browse files
committed
Auto merge of rust-lang#113325 - BoxyUwU:move_mk_methods_to_const, r=lcnr
Replace `mk_const` with `Const::new_x` methods Part of rust-lang/compiler-team#616. Instead of just havign `Const::new(` and nothing else I did it like this since this is more like how the `mk_x` works for `Ty`, and also another PR of mine will require changing from `Const::new(` to `Const::new_x(` anyway. r? `@oli-bok`
2 parents 9e4e584 + d3cd406 commit f20afcc

File tree

40 files changed

+284
-191
lines changed

40 files changed

+284
-191
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+11-12
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()
@@ -529,13 +528,13 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
529528
let reported = err.emit();
530529
term = match def_kind {
531530
hir::def::DefKind::AssocTy => tcx.ty_error(reported).into(),
532-
hir::def::DefKind::AssocConst => tcx
533-
.const_error(
534-
tcx.type_of(assoc_item_def_id)
535-
.subst(tcx, projection_ty.skip_binder().substs),
536-
reported,
537-
)
538-
.into(),
531+
hir::def::DefKind::AssocConst => ty::Const::new_error(
532+
tcx,
533+
reported,
534+
tcx.type_of(assoc_item_def_id)
535+
.subst(tcx, projection_ty.skip_binder().substs),
536+
)
537+
.into(),
539538
_ => unreachable!(),
540539
};
541540
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
482482
self.astconv.ct_infer(ty, Some(param), inf.span).into()
483483
} else {
484484
self.inferred_params.push(inf.span);
485-
tcx.const_error_misc(ty).into()
485+
ty::Const::new_misc_error(tcx, ty).into()
486486
}
487487
}
488488
_ => unreachable!(),
@@ -537,7 +537,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
537537
.no_bound_vars()
538538
.expect("const parameter types cannot be generic");
539539
if let Err(guar) = ty.error_reported() {
540-
return tcx.const_error(ty, guar).into();
540+
return ty::Const::new_error(tcx, guar, ty).into();
541541
}
542542
if !infer_args && has_default {
543543
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
@@ -546,7 +546,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
546546
self.astconv.ct_infer(ty, Some(param), self.span).into()
547547
} else {
548548
// We've already errored above about the mismatch.
549-
tcx.const_error_misc(ty).into()
549+
ty::Const::new_misc_error(tcx, ty).into()
550550
}
551551
}
552552
}
@@ -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

+4-5
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.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
390390
// left alone.
391391
r => bug!("unexpected region: {r:?}"),
392392
});
393-
self.tcx().const_error_with_message(ty, span, "bad placeholder constant")
393+
ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant")
394394
}
395395

396396
fn projected_ty_from_poly_trait_ref(

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+5-2
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_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
840840
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
841841
let e = self.report_error(ct);
842842
self.replaced_with_error = Some(e);
843-
self.fcx.tcx.const_error(ct.ty(), e)
843+
ty::Const::new_error(self.fcx.tcx, e, ct.ty())
844844
}
845845
}
846846
}

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

+2-5
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

+1-1
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/combine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ impl<'tcx> InferCtxt<'tcx> {
189189
// HACK: equating both sides with `[const error]` eagerly prevents us
190190
// from leaving unconstrained inference vars during things like impl
191191
// matching in the solver.
192-
let a_error = self.tcx.const_error(a.ty(), guar);
192+
let a_error = ty::Const::new_error(self.tcx, guar, a.ty());
193193
if let ty::ConstKind::Infer(InferConst::Var(vid)) = a.kind() {
194194
return self.unify_const_variable(vid, a_error, relation.param_env());
195195
}
196-
let b_error = self.tcx.const_error(b.ty(), guar);
196+
let b_error = ty::Const::new_error(self.tcx, guar, b.ty());
197197
if let ty::ConstKind::Infer(InferConst::Var(vid)) = b.kind() {
198198
return self.unify_const_variable(vid, b_error, relation.param_env());
199199
}

compiler/rustc_infer/src/infer/freshen.rs

+1-1
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

+6-2
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

+2-1
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

+14-13
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({

compiler/rustc_middle/src/infer/canonical.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,13 @@ impl<'tcx> CanonicalVarValues<'tcx> {
443443
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
444444
}
445445
CanonicalVarKind::Const(_, ty)
446-
| CanonicalVarKind::PlaceholderConst(_, ty) => tcx
447-
.mk_const(
448-
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(i)),
449-
ty,
450-
)
451-
.into(),
446+
| CanonicalVarKind::PlaceholderConst(_, ty) => ty::Const::new_bound(
447+
tcx,
448+
ty::INNERMOST,
449+
ty::BoundVar::from_usize(i),
450+
ty,
451+
)
452+
.into(),
452453
}
453454
},
454455
)),

compiler/rustc_middle/src/mir/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2332,7 +2332,7 @@ impl<'tcx> ConstantKind<'tcx> {
23322332
if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) {
23332333
match val {
23342334
Ok(val) => Self::Val(val, c.ty()),
2335-
Err(guar) => Self::Ty(tcx.const_error(self.ty(), guar)),
2335+
Err(guar) => Self::Ty(ty::Const::new_error(tcx, guar, self.ty())),
23362336
}
23372337
} else {
23382338
self
@@ -2344,7 +2344,9 @@ impl<'tcx> ConstantKind<'tcx> {
23442344
match tcx.const_eval_resolve(param_env, uneval, None) {
23452345
Ok(val) => Self::Val(val, ty),
23462346
Err(ErrorHandled::TooGeneric) => self,
2347-
Err(ErrorHandled::Reported(guar)) => Self::Ty(tcx.const_error(ty, guar.into())),
2347+
Err(ErrorHandled::Reported(guar)) => {
2348+
Self::Ty(ty::Const::new_error(tcx, guar.into(), ty))
2349+
}
23482350
}
23492351
}
23502352
}
@@ -2510,7 +2512,7 @@ impl<'tcx> ConstantKind<'tcx> {
25102512
let generics = tcx.generics_of(item_def_id);
25112513
let index = generics.param_def_id_to_index[&def_id];
25122514
let name = tcx.item_name(def_id);
2513-
let ty_const = tcx.mk_const(ty::ParamConst::new(index, name), ty);
2515+
let ty_const = ty::Const::new_param(tcx, ty::ParamConst::new(index, name), ty);
25142516
debug!(?ty_const);
25152517

25162518
return Self::Ty(ty_const);

compiler/rustc_middle/src/ty/abstract_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> TyCtxt<'tcx> {
5353
fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
5454
let ct = match c.kind() {
5555
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
56-
Err(e) => self.tcx.const_error(c.ty(), e),
56+
Err(e) => ty::Const::new_error(self.tcx, e, c.ty()),
5757
Ok(Some(bac)) => {
5858
let substs = self.tcx.erase_regions(uv.substs);
5959
let bac = bac.subst(self.tcx, substs);

compiler/rustc_middle/src/ty/codec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
344344
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> {
345345
fn decode(decoder: &mut D) -> Self {
346346
let consts: ty::ConstData<'tcx> = Decodable::decode(decoder);
347-
decoder.interner().mk_const(consts.kind, consts.ty)
347+
decoder.interner().mk_ct_from_kind(consts.kind, consts.ty)
348348
}
349349
}
350350

0 commit comments

Comments
 (0)