Remove `Const::from_value`

...it's just `mk_const` but without the sparcles
This commit is contained in:
Maybe Waffle 2022-11-28 12:38:15 +00:00
parent 26b87bf8ff
commit f4d00fe785
6 changed files with 9 additions and 19 deletions

View File

@ -1580,7 +1580,7 @@ impl<'tcx> InferCtxt<'tcx> {
span: Option<Span>,
) -> Result<ty::Const<'tcx>, 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;

View File

@ -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 {

View File

@ -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(..) => {

View File

@ -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))
}

View File

@ -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;

View File

@ -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);