Basic removal of Ty
from places (boring)
This commit is contained in:
parent
7ebd2bdbf6
commit
58feec9b85
71 changed files with 331 additions and 581 deletions
|
@ -32,7 +32,10 @@ fn destructure_const<'tcx>(
|
|||
_ => bug!("cannot destructure constant {:?}", const_),
|
||||
};
|
||||
|
||||
let (fields, variant) = match const_.ty().kind() {
|
||||
// THISPR
|
||||
let ct_ty: Ty<'tcx> = todo!();
|
||||
|
||||
let (fields, variant) = match ct_ty.kind() {
|
||||
ty::Array(inner_ty, _) | ty::Slice(inner_ty) => {
|
||||
// construct the consts for the elements of the array/slice
|
||||
let field_consts = branches
|
||||
|
@ -121,7 +124,7 @@ fn recurse_build<'tcx>(
|
|||
let sp = node.span;
|
||||
match tcx.at(sp).lit_to_const(LitToConstInput { lit: &lit.node, ty: node.ty, neg }) {
|
||||
Ok(c) => c,
|
||||
Err(LitToConstError::Reported(guar)) => ty::Const::new_error(tcx, guar, node.ty),
|
||||
Err(LitToConstError::Reported(guar)) => ty::Const::new_error(tcx, guar),
|
||||
Err(LitToConstError::TypeError) => {
|
||||
bug!("encountered type error in lit_to_const")
|
||||
}
|
||||
|
@ -137,35 +140,31 @@ fn recurse_build<'tcx>(
|
|||
}
|
||||
&ExprKind::NamedConst { def_id, args, user_ty: _ } => {
|
||||
let uneval = ty::UnevaluatedConst::new(def_id, args);
|
||||
ty::Const::new_unevaluated(tcx, uneval, node.ty)
|
||||
ty::Const::new_unevaluated(tcx, uneval)
|
||||
}
|
||||
ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param, node.ty),
|
||||
ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param),
|
||||
|
||||
ExprKind::Call { fun, args, .. } => {
|
||||
let fun_ty = body.exprs[*fun].ty;
|
||||
let fun = recurse_build(tcx, body, *fun, root_span)?;
|
||||
|
||||
let mut new_args = Vec::<ty::Const<'tcx>>::with_capacity(args.len());
|
||||
for &id in args.iter() {
|
||||
new_args.push(recurse_build(tcx, body, id, root_span)?);
|
||||
}
|
||||
ty::Const::new_expr(
|
||||
tcx,
|
||||
Expr::new_call(tcx, fun.ty(), fun, new_args.into_iter()),
|
||||
node.ty,
|
||||
)
|
||||
ty::Const::new_expr(tcx, Expr::new_call(tcx, fun_ty, fun, new_args.into_iter()))
|
||||
}
|
||||
&ExprKind::Binary { op, lhs, rhs } if check_binop(op) => {
|
||||
let lhs_ty = body.exprs[lhs].ty;
|
||||
let lhs = recurse_build(tcx, body, lhs, root_span)?;
|
||||
let rhs_ty = body.exprs[rhs].ty;
|
||||
let rhs = recurse_build(tcx, body, rhs, root_span)?;
|
||||
ty::Const::new_expr(
|
||||
tcx,
|
||||
Expr::new_binop(tcx, op, lhs.ty(), rhs.ty(), lhs, rhs),
|
||||
node.ty,
|
||||
)
|
||||
ty::Const::new_expr(tcx, Expr::new_binop(tcx, op, lhs_ty, rhs_ty, lhs, rhs))
|
||||
}
|
||||
&ExprKind::Unary { op, arg } if check_unop(op) => {
|
||||
let arg_ty = body.exprs[arg].ty;
|
||||
let arg = recurse_build(tcx, body, arg, root_span)?;
|
||||
ty::Const::new_expr(tcx, Expr::new_unop(tcx, op, arg.ty(), arg), node.ty)
|
||||
ty::Const::new_expr(tcx, Expr::new_unop(tcx, op, arg_ty, arg))
|
||||
}
|
||||
// This is necessary so that the following compiles:
|
||||
//
|
||||
|
@ -187,20 +186,12 @@ fn recurse_build<'tcx>(
|
|||
&ExprKind::Use { source } => {
|
||||
let value_ty = body.exprs[source].ty;
|
||||
let value = recurse_build(tcx, body, source, root_span)?;
|
||||
ty::Const::new_expr(
|
||||
tcx,
|
||||
Expr::new_cast(tcx, CastKind::Use, value_ty, value, node.ty),
|
||||
node.ty,
|
||||
)
|
||||
ty::Const::new_expr(tcx, Expr::new_cast(tcx, CastKind::Use, value_ty, value, node.ty))
|
||||
}
|
||||
&ExprKind::Cast { source } => {
|
||||
let value_ty = body.exprs[source].ty;
|
||||
let value = recurse_build(tcx, body, source, root_span)?;
|
||||
ty::Const::new_expr(
|
||||
tcx,
|
||||
Expr::new_cast(tcx, CastKind::As, value_ty, value, node.ty),
|
||||
node.ty,
|
||||
)
|
||||
ty::Const::new_expr(tcx, Expr::new_cast(tcx, CastKind::As, value_ty, value, node.ty))
|
||||
}
|
||||
ExprKind::Borrow { arg, .. } => {
|
||||
let arg_node = &body.exprs[*arg];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue