diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index c5de1d6d78a..2bcb47cc383 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1580,7 +1580,7 @@ impl<'tcx> InferCtxt<'tcx> { span: Option, ) -> Result, ErrorHandled> { match self.const_eval_resolve(param_env, unevaluated, span) { - Ok(Some(val)) => Ok(ty::Const::from_value(self.tcx, val, ty)), + Ok(Some(val)) => Ok(self.tcx.mk_const(val, ty)), Ok(None) => { let tcx = self.tcx; let def_id = unevaluated.def.did; diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index cd0b280ce4e..eaeb08c7aed 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -140,12 +140,6 @@ impl<'tcx> Const<'tcx> { } } - /// Interns the given value as a constant. - #[inline] - pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Self { - tcx.mk_const(val, ty) - } - /// Panics if self.kind != ty::ConstKind::Value pub fn to_valtree(self) -> ty::ValTree<'tcx> { match self.kind() { @@ -156,7 +150,7 @@ impl<'tcx> Const<'tcx> { pub fn from_scalar_int(tcx: TyCtxt<'tcx>, i: ScalarInt, ty: Ty<'tcx>) -> Self { let valtree = ty::ValTree::from_scalar_int(i); - Self::from_value(tcx, valtree, ty) + tcx.mk_const(valtree, ty) } #[inline] @@ -172,8 +166,7 @@ impl<'tcx> Const<'tcx> { #[inline] /// Creates an interned zst constant. pub fn zero_sized(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self { - let valtree = ty::ValTree::zst(); - Self::from_value(tcx, valtree, ty) + tcx.mk_const(ty::ValTree::zst(), ty) } #[inline] @@ -220,7 +213,7 @@ impl<'tcx> Const<'tcx> { pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> { if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) { match val { - Ok(val) => Const::from_value(tcx, val, self.ty()), + Ok(val) => tcx.mk_const(val, self.ty()), Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar), } } else { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index bd17f7d34ad..5303341ba44 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1468,8 +1468,7 @@ pub trait PrettyPrinter<'tcx>: } // Aggregates, printed as array/tuple/struct/variant construction syntax. (ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => { - let contents = - self.tcx().destructure_const(ty::Const::from_value(self.tcx(), valtree, ty)); + let contents = self.tcx().destructure_const(self.tcx().mk_const(valtree, ty)); let fields = contents.fields.iter().copied(); match *ty.kind() { ty::Array(..) => { diff --git a/compiler/rustc_mir_build/src/thir/constant.rs b/compiler/rustc_mir_build/src/thir/constant.rs index 85e8801bda3..a9ed945d4a1 100644 --- a/compiler/rustc_mir_build/src/thir/constant.rs +++ b/compiler/rustc_mir_build/src/thir/constant.rs @@ -61,5 +61,5 @@ pub(crate) fn lit_to_const<'tcx>( _ => return Err(LitToConstError::TypeError), }; - Ok(ty::Const::from_value(tcx, valtree, ty)) + Ok(tcx.mk_const(valtree, ty)) } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 88a13f75c7e..8e04da4f9be 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -799,9 +799,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { unevaluated, Some(obligation.cause.span), ) { - Ok(Some(valtree)) => { - Ok(ty::Const::from_value(selcx.tcx(), valtree, c.ty())) - } + Ok(Some(valtree)) => Ok(selcx.tcx().mk_const(valtree, c.ty())), Ok(None) => { let tcx = self.tcx; let def_id = unevaluated.def.did; diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 77cb2243482..f8ff31f971b 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -125,11 +125,11 @@ fn recurse_build<'tcx>( } &ExprKind::NonHirLiteral { lit, user_ty: _ } => { let val = ty::ValTree::from_scalar_int(lit); - ty::Const::from_value(tcx, val, node.ty) + tcx.mk_const(val, node.ty) } &ExprKind::ZstLiteral { user_ty: _ } => { let val = ty::ValTree::zst(); - ty::Const::from_value(tcx, val, node.ty) + tcx.mk_const(val, node.ty) } &ExprKind::NamedConst { def_id, substs, user_ty: _ } => { let uneval = ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs);