Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 11 additions & 12 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()
@@ -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

Lines changed: 5 additions & 4 deletions
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

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.rs

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 1 addition & 1 deletion
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

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

Lines changed: 2 additions & 2 deletions
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

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
}

0 commit comments

Comments
 (0)