Skip to content

Commit b8157cc

Browse files
eddybpetrochenkov
authored andcommitted
Implement type ascription.
1 parent ce7bc51 commit b8157cc

File tree

20 files changed

+112
-12
lines changed

20 files changed

+112
-12
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
352352
hir::ExprBox(ref e) |
353353
hir::ExprAddrOf(_, ref e) |
354354
hir::ExprCast(ref e, _) |
355+
hir::ExprType(ref e, _) |
355356
hir::ExprUnary(_, ref e) |
356357
hir::ExprField(ref e, _) |
357358
hir::ExprTupField(ref e, _) => {

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
784784
hir::ExprField(..) |
785785
hir::ExprTupField(..) |
786786
hir::ExprVec(_) |
787+
hir::ExprType(..) |
787788
hir::ExprTup(..) => {}
788789

789790
// Conditional control flow (possible to implement).

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +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)),
11291130
hir::ExprTup(_) => Tuple(e.id),
11301131
hir::ExprStruct(..) => Struct(e.id),
11311132
hir::ExprIndex(ref arr, ref idx) => {

src/librustc/middle/expr_use_visitor.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> {
373373
match expr.node {
374374
hir::ExprPath(..) => { }
375375

376+
hir::ExprType(ref subexpr, _) => {
377+
self.walk_expr(&**subexpr)
378+
}
379+
376380
hir::ExprUnary(hir::UnDeref, ref base) => { // *base
377381
if !self.walk_overloaded_operator(expr, &**base, Vec::new(), PassArgs::ByRef) {
378382
self.select_from_expr(&**base);

src/librustc/middle/liveness.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
496496
hir::ExprBlock(..) | hir::ExprAssign(..) | hir::ExprAssignOp(..) |
497497
hir::ExprStruct(..) | hir::ExprRepeat(..) |
498498
hir::ExprInlineAsm(..) | hir::ExprBox(..) |
499-
hir::ExprRange(..) => {
499+
hir::ExprRange(..) | hir::ExprType(..) => {
500500
intravisit::walk_expr(ir, expr);
501501
}
502502
}
@@ -1160,6 +1160,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11601160
hir::ExprBox(ref e) |
11611161
hir::ExprAddrOf(_, ref e) |
11621162
hir::ExprCast(ref e, _) |
1163+
hir::ExprType(ref e, _) |
11631164
hir::ExprUnary(_, ref e) => {
11641165
self.propagate_through_expr(&**e, succ)
11651166
}
@@ -1443,7 +1444,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14431444
hir::ExprBlock(..) | hir::ExprAddrOf(..) |
14441445
hir::ExprStruct(..) | hir::ExprRepeat(..) |
14451446
hir::ExprClosure(..) | hir::ExprPath(..) | hir::ExprBox(..) |
1446-
hir::ExprRange(..) => {
1447+
hir::ExprRange(..) | hir::ExprType(..) => {
14471448
intravisit::walk_expr(this, expr);
14481449
}
14491450
}

src/librustc/middle/mem_categorization.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> {
518518
self.cat_def(expr.id, expr.span, expr_ty, def)
519519
}
520520

521+
hir::ExprType(ref e, _) => {
522+
self.cat_expr(&**e)
523+
}
524+
521525
hir::ExprAddrOf(..) | hir::ExprCall(..) |
522526
hir::ExprAssign(..) | hir::ExprAssignOp(..) |
523527
hir::ExprClosure(..) | hir::ExprRet(..) |

src/librustc_back/svh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ mod svh_visitor {
234234
SawExprUnary(hir::UnOp),
235235
SawExprLit(ast::Lit_),
236236
SawExprCast,
237+
SawExprType,
237238
SawExprIf,
238239
SawExprWhile,
239240
SawExprMatch,
@@ -262,6 +263,7 @@ mod svh_visitor {
262263
ExprUnary(op, _) => SawExprUnary(op),
263264
ExprLit(ref lit) => SawExprLit(lit.node.clone()),
264265
ExprCast(..) => SawExprCast,
266+
ExprType(..) => SawExprType,
265267
ExprIf(..) => SawExprIf,
266268
ExprWhile(..) => SawExprWhile,
267269
ExprLoop(_, id) => SawExprLoop(id.map(|id| id.name.as_str())),

src/librustc_trans/trans/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +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,
10071008
hir::ExprBlock(ref block) => {
10081009
match block.expr {
10091010
Some(ref expr) => try!(const_expr(

src/librustc_trans/trans/expr.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
656656
let _icx = push_ctxt("trans_datum_unadjusted");
657657

658658
match expr.node {
659+
hir::ExprType(ref e, _) => {
660+
trans(bcx, &**e)
661+
}
659662
hir::ExprPath(..) => {
660663
trans_def(bcx, expr, bcx.def(expr.id))
661664
}
@@ -941,6 +944,9 @@ fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
941944
hir::ExprBreak(label_opt) => {
942945
controlflow::trans_break(bcx, expr, label_opt.map(|l| l.node.name))
943946
}
947+
hir::ExprType(ref e, _) => {
948+
trans_into(bcx, &**e, Ignore)
949+
}
944950
hir::ExprAgain(label_opt) => {
945951
controlflow::trans_cont(bcx, expr, label_opt.map(|l| l.node.name))
946952
}
@@ -1064,6 +1070,9 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
10641070
debuginfo::set_source_location(bcx.fcx, expr.id, expr.span);
10651071

10661072
match expr.node {
1073+
hir::ExprType(ref e, _) => {
1074+
trans_into(bcx, &**e, dest)
1075+
}
10671076
hir::ExprPath(..) => {
10681077
trans_def_dps_unadjusted(bcx, expr, bcx.def(expr.id), dest)
10691078
}

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,6 +3525,11 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
35253525
deferred_cast_checks.push(cast_check);
35263526
}
35273527
}
3528+
hir::ExprType(ref e, ref t) => {
3529+
let typ = fcx.to_ty(&**t);
3530+
check_expr_coercable_to_type(fcx, &**e, typ);
3531+
fcx.write_ty(id, typ);
3532+
}
35283533
hir::ExprVec(ref args) => {
35293534
let uty = expected.to_option(fcx).and_then(|uty| {
35303535
match uty.sty {

0 commit comments

Comments
 (0)