diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-11-28 12:28:32 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-11-28 17:27:20 +0000 |
| commit | 26b87bf8ff8406e80e70559b71cf0095475cc64a (patch) | |
| tree | 57fd97d536d1d9513df63ab20b8c98816e7174c8 /compiler/rustc_ty_utils/src | |
| parent | 7087d9b2a08385eaf7eb035e5ed420a84ef0902c (diff) | |
| download | rust-26b87bf8ff8406e80e70559b71cf0095475cc64a.tar.gz rust-26b87bf8ff8406e80e70559b71cf0095475cc64a.zip | |
Simplify calls to `tcx.mk_const`
`mk_const(ty::ConstKind::X(...), ty)` can now be simplified to
`mk_cosnt(..., ty)`.
I searched with the following regex: \mk_const\([\n\s]*(ty::)?ConstKind\
I've left `ty::ConstKind::{Bound, Error}` as-is, they seem clearer this
way.
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/consts.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 2b7018bc9c3..77cb2243482 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -5,7 +5,7 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::thir::visit; use rustc_middle::thir::visit::Visitor; use rustc_middle::ty::abstract_const::CastKind; -use rustc_middle::ty::{self, ConstKind, Expr, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, Expr, TyCtxt, TypeVisitable}; use rustc_middle::{mir, thir}; use rustc_span::Span; use rustc_target::abi::VariantIdx; @@ -32,10 +32,8 @@ pub(crate) fn destructure_const<'tcx>( let (fields, variant) = match const_.ty().kind() { ty::Array(inner_ty, _) | ty::Slice(inner_ty) => { // construct the consts for the elements of the array/slice - let field_consts = branches - .iter() - .map(|b| tcx.mk_const(ty::ConstKind::Value(*b), *inner_ty)) - .collect::<Vec<_>>(); + let field_consts = + branches.iter().map(|b| tcx.mk_const(*b, *inner_ty)).collect::<Vec<_>>(); debug!(?field_consts); (field_consts, None) @@ -53,7 +51,7 @@ pub(crate) fn destructure_const<'tcx>( for (field, field_valtree) in iter::zip(fields, branches) { let field_ty = field.ty(tcx, substs); - let field_const = tcx.mk_const(ty::ConstKind::Value(*field_valtree), field_ty); + let field_const = tcx.mk_const(*field_valtree, field_ty); field_consts.push(field_const); } debug!(?field_consts); @@ -62,9 +60,7 @@ pub(crate) fn destructure_const<'tcx>( } ty::Tuple(elem_tys) => { let fields = iter::zip(*elem_tys, branches) - .map(|(elem_ty, elem_valtree)| { - tcx.mk_const(ty::ConstKind::Value(*elem_valtree), elem_ty) - }) + .map(|(elem_ty, elem_valtree)| tcx.mk_const(*elem_valtree, elem_ty)) .collect::<Vec<_>>(); (fields, None) @@ -137,9 +133,9 @@ fn recurse_build<'tcx>( } &ExprKind::NamedConst { def_id, substs, user_ty: _ } => { let uneval = ty::UnevaluatedConst::new(ty::WithOptConstParam::unknown(def_id), substs); - tcx.mk_const(ty::ConstKind::Unevaluated(uneval), node.ty) + tcx.mk_const(uneval, node.ty) } - ExprKind::ConstParam { param, .. } => tcx.mk_const(ty::ConstKind::Param(*param), node.ty), + ExprKind::ConstParam { param, .. } => tcx.mk_const(*param, node.ty), ExprKind::Call { fun, args, .. } => { let fun = recurse_build(tcx, body, *fun, root_span)?; @@ -149,16 +145,16 @@ fn recurse_build<'tcx>( new_args.push(recurse_build(tcx, body, id, root_span)?); } let new_args = tcx.mk_const_list(new_args.iter()); - tcx.mk_const(ConstKind::Expr(Expr::FunctionCall(fun, new_args)), node.ty) + tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty) } &ExprKind::Binary { op, lhs, rhs } if check_binop(op) => { let lhs = recurse_build(tcx, body, lhs, root_span)?; let rhs = recurse_build(tcx, body, rhs, root_span)?; - tcx.mk_const(ConstKind::Expr(Expr::Binop(op, lhs, rhs)), node.ty) + tcx.mk_const(Expr::Binop(op, lhs, rhs), node.ty) } &ExprKind::Unary { op, arg } if check_unop(op) => { let arg = recurse_build(tcx, body, arg, root_span)?; - tcx.mk_const(ConstKind::Expr(Expr::UnOp(op, arg)), node.ty) + tcx.mk_const(Expr::UnOp(op, arg), node.ty) } // This is necessary so that the following compiles: // @@ -179,11 +175,11 @@ fn recurse_build<'tcx>( // This is important so that `N as usize as usize` doesnt unify with `N as usize`. (untested) &ExprKind::Use { source } => { let arg = recurse_build(tcx, body, source, root_span)?; - tcx.mk_const(ConstKind::Expr(Expr::Cast(CastKind::Use, arg, node.ty)), node.ty) + tcx.mk_const(Expr::Cast(CastKind::Use, arg, node.ty), node.ty) } &ExprKind::Cast { source } => { let arg = recurse_build(tcx, body, source, root_span)?; - tcx.mk_const(ConstKind::Expr(Expr::Cast(CastKind::As, arg, node.ty)), node.ty) + tcx.mk_const(Expr::Cast(CastKind::As, arg, node.ty), node.ty) } ExprKind::Borrow { arg, .. } => { let arg_node = &body.exprs[*arg]; |
