Const-eval array element repetition count
This commit is contained in:
parent
db89a75a80
commit
e4e880df37
@ -17,7 +17,6 @@ use hair::cx::block;
|
||||
use hair::cx::pattern::PatNode;
|
||||
use hair::cx::to_ref::ToRef;
|
||||
use rustc::front::map;
|
||||
use rustc::middle::const_eval;
|
||||
use rustc::middle::def;
|
||||
use rustc::middle::region::CodeExtent;
|
||||
use rustc::middle::pat_util;
|
||||
@ -81,10 +80,9 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
|
||||
}
|
||||
}
|
||||
|
||||
hir::ExprLit(..) => {
|
||||
let value = const_eval::eval_const_expr(cx.tcx, self);
|
||||
ExprKind::Literal { literal: Literal::Value { value: value } }
|
||||
}
|
||||
hir::ExprLit(..) => ExprKind::Literal {
|
||||
literal: cx.const_eval_literal(self)
|
||||
},
|
||||
|
||||
hir::ExprBinary(op, ref lhs, ref rhs) => {
|
||||
if cx.tcx.is_method_call(self.id) {
|
||||
@ -273,8 +271,17 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
|
||||
|
||||
// Now comes the rote stuff:
|
||||
|
||||
hir::ExprRepeat(ref v, ref c) =>
|
||||
ExprKind::Repeat { value: v.to_ref(), count: c.to_ref() },
|
||||
hir::ExprRepeat(ref v, ref c) => ExprKind::Repeat {
|
||||
value: v.to_ref(),
|
||||
count: Expr {
|
||||
ty: cx.tcx.expr_ty(c),
|
||||
temp_lifetime: None,
|
||||
span: c.span,
|
||||
kind: ExprKind::Literal {
|
||||
literal: cx.const_eval_literal(c)
|
||||
}
|
||||
}.to_ref()
|
||||
},
|
||||
hir::ExprRet(ref v) =>
|
||||
ExprKind::Return { value: v.to_ref() },
|
||||
hir::ExprBreak(label) =>
|
||||
|
@ -18,13 +18,14 @@
|
||||
use hair::*;
|
||||
use repr::*;
|
||||
|
||||
use rustc::middle::const_eval::ConstVal;
|
||||
use rustc::middle::const_eval::{self, ConstVal};
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::infer::InferCtxt;
|
||||
use rustc::middle::subst::{Subst, Substs};
|
||||
use rustc::middle::ty::{self, Ty};
|
||||
use syntax::codemap::Span;
|
||||
use syntax::parse::token;
|
||||
use rustc_front::hir;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Cx<'a, 'tcx: 'a> {
|
||||
@ -73,6 +74,10 @@ impl<'a,'tcx:'a> Cx<'a, 'tcx> {
|
||||
Literal::Value { value: ConstVal::Bool(false) }
|
||||
}
|
||||
|
||||
pub fn const_eval_literal(&mut self, e: &hir::Expr) -> Literal<'tcx> {
|
||||
Literal::Value { value: const_eval::eval_const_expr(self.tcx, e) }
|
||||
}
|
||||
|
||||
pub fn partial_eq(&mut self, ty: Ty<'tcx>) -> ItemRef<'tcx> {
|
||||
let eq_def_id = self.tcx.lang_items.eq_trait().unwrap();
|
||||
self.cmp_method_ref(eq_def_id, "eq", ty)
|
||||
|
@ -210,6 +210,9 @@ pub enum ExprKind<'tcx> {
|
||||
},
|
||||
Repeat {
|
||||
value: ExprRef<'tcx>,
|
||||
// FIXME(#29789): Add a separate hair::Constant<'tcx> so this could be more explicit about
|
||||
// its contained data. Currently this should only contain expression of ExprKind::Literal
|
||||
// kind.
|
||||
count: ExprRef<'tcx>,
|
||||
},
|
||||
Vec {
|
||||
|
Loading…
x
Reference in New Issue
Block a user