Skip to content

Commit e0ceef5

Browse files
committed
Add ExprType to HIR and make everything compile
+ Apply parser changes manually + Add feature gate
1 parent b8157cc commit e0ceef5

File tree

19 files changed

+83
-31
lines changed

19 files changed

+83
-31
lines changed

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
11261126
None => unreachable!(),
11271127
}
11281128
}
1129-
hir::ExprType(ref e, _) => try!(eval_const_expr_partial(tcx, &**e, ety)),
1129+
hir::ExprType(ref e, _) => try!(eval_const_expr_partial(tcx, &**e, ty_hint, fn_args)),
11301130
hir::ExprTup(_) => Tuple(e.id),
11311131
hir::ExprStruct(..) => Struct(e.id),
11321132
hir::ExprIndex(ref arr, ref idx) => {

src/librustc/middle/ty/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,10 @@ impl<'tcx> ctxt<'tcx> {
21082108
}
21092109
}
21102110

2111+
hir::ExprType(ref e, _) => {
2112+
self.expr_is_lval(e)
2113+
}
2114+
21112115
hir::ExprUnary(hir::UnDeref, _) |
21122116
hir::ExprField(..) |
21132117
hir::ExprTupField(..) |

src/librustc_front/fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,9 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: &
10421042
ExprCast(expr, ty) => {
10431043
ExprCast(folder.fold_expr(expr), folder.fold_ty(ty))
10441044
}
1045+
ExprType(expr, ty) => {
1046+
ExprType(folder.fold_expr(expr), folder.fold_ty(ty))
1047+
}
10451048
ExprAddrOf(m, ohs) => ExprAddrOf(m, folder.fold_expr(ohs)),
10461049
ExprIf(cond, tr, fl) => {
10471050
ExprIf(folder.fold_expr(cond),

src/librustc_front/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ pub enum Expr_ {
720720
ExprLit(P<Lit>),
721721
/// A cast (`foo as f64`)
722722
ExprCast(P<Expr>, P<Ty>),
723+
ExprType(P<Expr>, P<Ty>),
723724
/// An `if` block, with an optional else block
724725
///
725726
/// `if expr { block } else { expr }`

src/librustc_front/intravisit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
732732
visitor.visit_expr(subexpression)
733733
}
734734
ExprLit(_) => {}
735-
ExprCast(ref subexpression, ref typ) => {
735+
ExprCast(ref subexpression, ref typ) | ExprType(ref subexpression, ref typ) => {
736736
visitor.visit_expr(subexpression);
737737
visitor.visit_ty(typ)
738738
}

src/librustc_front/lowering.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,10 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
11251125
let expr = lower_expr(lctx, expr);
11261126
hir::ExprCast(expr, lower_ty(lctx, ty))
11271127
}
1128+
ExprType(ref expr, ref ty) => {
1129+
let expr = lower_expr(lctx, expr);
1130+
hir::ExprType(expr, lower_ty(lctx, ty))
1131+
}
11281132
ExprAddrOf(m, ref ohs) => {
11291133
let m = lower_mutability(lctx, m);
11301134
let ohs = lower_expr(lctx, ohs);

src/librustc_front/print/pprust.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ fn needs_parentheses(expr: &hir::Expr) -> bool {
336336
hir::ExprBinary(..) |
337337
hir::ExprClosure(..) |
338338
hir::ExprAssignOp(..) |
339-
hir::ExprCast(..) => true,
339+
hir::ExprCast(..) |
340+
hir::ExprType(..) => true,
340341
_ => false,
341342
}
342343
}
@@ -1354,6 +1355,11 @@ impl<'a> State<'a> {
13541355
try!(self.word_space("as"));
13551356
try!(self.print_type(&**ty));
13561357
}
1358+
hir::ExprType(ref expr, ref ty) => {
1359+
try!(self.print_expr(&**expr));
1360+
try!(self.word_space(":"));
1361+
try!(self.print_type(&**ty));
1362+
}
13571363
hir::ExprIf(ref test, ref blk, ref elseopt) => {
13581364
try!(self.print_if(&**test, &**blk, elseopt.as_ref().map(|e| &**e)));
13591365
}

src/librustc_lint/unused.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ impl UnusedParens {
319319
}
320320
ast::ExprUnary(_, ref x) |
321321
ast::ExprCast(ref x, _) |
322+
ast::ExprType(ref x, _) |
322323
ast::ExprField(ref x, _) |
323324
ast::ExprTupField(ref x, _) |
324325
ast::ExprIndex(ref x, _) => {

src/librustc_mir/hair/cx/expr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
320320
name: Field::new(index.node as usize) },
321321
hir::ExprCast(ref source, _) =>
322322
ExprKind::Cast { source: source.to_ref() },
323+
hir::ExprType(ref source, _) =>
324+
return source.make_mirror(cx),
323325
hir::ExprBox(ref value) =>
324326
ExprKind::Box { value: value.to_ref() },
325327
hir::ExprVec(ref fields) =>

src/librustc_trans/trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
10041004
try!(const_fn_call(cx, MethodCallKey(method_call),
10051005
method_did, &arg_vals, param_substs, trueconst))
10061006
},
1007-
hir::ExprType(ref e, _) => const_expr(cx, &**e, param_substs).0,
1007+
hir::ExprType(ref e, _) => try!(const_expr(cx, &**e, param_substs, fn_args, trueconst)).0,
10081008
hir::ExprBlock(ref block) => {
10091009
match block.expr {
10101010
Some(ref expr) => try!(const_expr(

0 commit comments

Comments
 (0)