Skip to content

Commit f4d00fe

Browse files
committed
Remove Const::from_value
...it's just `mk_const` but without the sparcles
1 parent 26b87bf commit f4d00fe

File tree

6 files changed

+9
-19
lines changed

6 files changed

+9
-19
lines changed

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ impl<'tcx> InferCtxt<'tcx> {
15801580
span: Option<Span>,
15811581
) -> Result<ty::Const<'tcx>, ErrorHandled> {
15821582
match self.const_eval_resolve(param_env, unevaluated, span) {
1583-
Ok(Some(val)) => Ok(ty::Const::from_value(self.tcx, val, ty)),
1583+
Ok(Some(val)) => Ok(self.tcx.mk_const(val, ty)),
15841584
Ok(None) => {
15851585
let tcx = self.tcx;
15861586
let def_id = unevaluated.def.did;

compiler/rustc_middle/src/ty/consts.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,6 @@ impl<'tcx> Const<'tcx> {
140140
}
141141
}
142142

143-
/// Interns the given value as a constant.
144-
#[inline]
145-
pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Self {
146-
tcx.mk_const(val, ty)
147-
}
148-
149143
/// Panics if self.kind != ty::ConstKind::Value
150144
pub fn to_valtree(self) -> ty::ValTree<'tcx> {
151145
match self.kind() {
@@ -156,7 +150,7 @@ impl<'tcx> Const<'tcx> {
156150

157151
pub fn from_scalar_int(tcx: TyCtxt<'tcx>, i: ScalarInt, ty: Ty<'tcx>) -> Self {
158152
let valtree = ty::ValTree::from_scalar_int(i);
159-
Self::from_value(tcx, valtree, ty)
153+
tcx.mk_const(valtree, ty)
160154
}
161155

162156
#[inline]
@@ -172,8 +166,7 @@ impl<'tcx> Const<'tcx> {
172166
#[inline]
173167
/// Creates an interned zst constant.
174168
pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
175-
let valtree = ty::ValTree::zst();
176-
Self::from_value(tcx, valtree, ty)
169+
tcx.mk_const(ty::ValTree::zst(), ty)
177170
}
178171

179172
#[inline]
@@ -220,7 +213,7 @@ impl<'tcx> Const<'tcx> {
220213
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> {
221214
if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) {
222215
match val {
223-
Ok(val) => Const::from_value(tcx, val, self.ty()),
216+
Ok(val) => tcx.mk_const(val, self.ty()),
224217
Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar),
225218
}
226219
} else {

compiler/rustc_middle/src/ty/print/pretty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1468,8 +1468,7 @@ pub trait PrettyPrinter<'tcx>:
14681468
}
14691469
// Aggregates, printed as array/tuple/struct/variant construction syntax.
14701470
(ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => {
1471-
let contents =
1472-
self.tcx().destructure_const(ty::Const::from_value(self.tcx(), valtree, ty));
1471+
let contents = self.tcx().destructure_const(self.tcx().mk_const(valtree, ty));
14731472
let fields = contents.fields.iter().copied();
14741473
match *ty.kind() {
14751474
ty::Array(..) => {

compiler/rustc_mir_build/src/thir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ pub(crate) fn lit_to_const<'tcx>(
6161
_ => return Err(LitToConstError::TypeError),
6262
};
6363

64-
Ok(ty::Const::from_value(tcx, valtree, ty))
64+
Ok(tcx.mk_const(valtree, ty))
6565
}

compiler/rustc_trait_selection/src/traits/auto_trait.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
799799
unevaluated,
800800
Some(obligation.cause.span),
801801
) {
802-
Ok(Some(valtree)) => {
803-
Ok(ty::Const::from_value(selcx.tcx(), valtree, c.ty()))
804-
}
802+
Ok(Some(valtree)) => Ok(selcx.tcx().mk_const(valtree, c.ty())),
805803
Ok(None) => {
806804
let tcx = self.tcx;
807805
let def_id = unevaluated.def.did;

compiler/rustc_ty_utils/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ fn recurse_build<'tcx>(
125125
}
126126
&ExprKind::NonHirLiteral { lit, user_ty: _ } => {
127127
let val = ty::ValTree::from_scalar_int(lit);
128-
ty::Const::from_value(tcx, val, node.ty)
128+
tcx.mk_const(val, node.ty)
129129
}
130130
&ExprKind::ZstLiteral { user_ty: _ } => {
131131
let val = ty::ValTree::zst();
132-
ty::Const::from_value(tcx, val, node.ty)
132+
tcx.mk_const(val, node.ty)
133133
}
134134
&ExprKind::NamedConst { def_id, substs, user_ty: _ } => {
135135
let uneval = ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);

0 commit comments

Comments
 (0)