Skip to content

Commit 85a7105

Browse files
committed
Implement type ascription.
1 parent a2aee62 commit 85a7105

File tree

23 files changed

+131
-34
lines changed

23 files changed

+131
-34
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ impl UnusedParens {
11541154
}
11551155
ast::ExprUnary(_, ref x) |
11561156
ast::ExprCast(ref x, _) |
1157+
ast::ExprType(ref x, _) |
11571158
ast::ExprField(ref x, _) |
11581159
ast::ExprTupField(ref x, _) |
11591160
ast::ExprIndex(ref x, _) => {

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
434434
ast::ExprBox(None, ref e) |
435435
ast::ExprAddrOf(_, ref e) |
436436
ast::ExprCast(ref e, _) |
437+
ast::ExprType(ref e, _) |
437438
ast::ExprUnary(_, ref e) |
438439
ast::ExprParen(ref e) |
439440
ast::ExprField(ref e, _) |

src/librustc/middle/check_const.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) {
167167
ast::ExprTupField(..) |
168168
ast::ExprIndex(..) |
169169
ast::ExprTup(..) |
170+
ast::ExprType(..) |
170171
ast::ExprRepeat(..) |
171172
ast::ExprStruct(..) => {}
172173

src/librustc/middle/const_eval.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> {
232232
}
233233
}
234234

235-
ast::ExprField(ref base, _) => self.classify(&**base),
236-
235+
ast::ExprType(ref base, _) |
236+
ast::ExprField(ref base, _) |
237237
ast::ExprTupField(ref base, _) => self.classify(&**base),
238238

239239
ast::ExprIndex(ref base, ref idx) =>
@@ -556,7 +556,8 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result<const_val, St
556556
}
557557
}
558558
ast::ExprLit(ref lit) => Ok(lit_to_const(&**lit)),
559-
ast::ExprParen(ref e) => eval_const_expr_partial(tcx, &**e),
559+
ast::ExprParen(ref e) |
560+
ast::ExprType(ref e, _) => eval_const_expr_partial(tcx, &**e),
560561
ast::ExprBlock(ref block) => {
561562
match block.expr {
562563
Some(ref expr) => eval_const_expr_partial(tcx, &**expr),

src/librustc/middle/expr_use_visitor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
423423
self.walk_adjustment(expr);
424424

425425
match expr.node {
426-
ast::ExprParen(ref subexpr) => {
426+
ast::ExprParen(ref subexpr) |
427+
ast::ExprType(ref subexpr, _) => {
427428
self.walk_expr(&**subexpr)
428429
}
429430

src/librustc/middle/liveness.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) {
505505
ast::ExprBlock(..) | ast::ExprAssign(..) | ast::ExprAssignOp(..) |
506506
ast::ExprMac(..) | ast::ExprStruct(..) | ast::ExprRepeat(..) |
507507
ast::ExprParen(..) | ast::ExprInlineAsm(..) | ast::ExprBox(..) |
508-
ast::ExprRange(..) => {
508+
ast::ExprRange(..) | ast::ExprType(..) => {
509509
visit::walk_expr(ir, expr);
510510
}
511511
}
@@ -1188,6 +1188,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
11881188
ast::ExprBox(None, ref e) |
11891189
ast::ExprAddrOf(_, ref e) |
11901190
ast::ExprCast(ref e, _) |
1191+
ast::ExprType(ref e, _) |
11911192
ast::ExprUnary(_, ref e) |
11921193
ast::ExprParen(ref e) => {
11931194
self.propagate_through_expr(&**e, succ)
@@ -1468,7 +1469,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14681469
ast::ExprBlock(..) | ast::ExprMac(..) | ast::ExprAddrOf(..) |
14691470
ast::ExprStruct(..) | ast::ExprRepeat(..) | ast::ExprParen(..) |
14701471
ast::ExprClosure(..) | ast::ExprPath(..) | ast::ExprBox(..) |
1471-
ast::ExprRange(..) | ast::ExprQPath(..) => {
1472+
ast::ExprRange(..) | ast::ExprQPath(..) | ast::ExprType(..) => {
14721473
visit::walk_expr(this, expr);
14731474
}
14741475
ast::ExprIfLet(..) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
520520
self.cat_def(expr.id, expr.span, expr_ty, def)
521521
}
522522

523-
ast::ExprParen(ref e) => {
523+
ast::ExprParen(ref e) | ast::ExprType(ref e, _) => {
524524
self.cat_expr(&**e)
525525
}
526526

src/librustc/middle/ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4618,7 +4618,8 @@ pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
46184618
}
46194619
}
46204620

4621-
ast::ExprParen(ref e) => expr_kind(tcx, &**e),
4621+
ast::ExprParen(ref e) |
4622+
ast::ExprType(ref e, _) => expr_kind(tcx, &**e),
46224623

46234624
ast::ExprMac(..) => {
46244625
tcx.sess.span_bug(

src/librustc_back/svh.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ mod svh_visitor {
235235
SawExprUnary(ast::UnOp),
236236
SawExprLit(ast::Lit_),
237237
SawExprCast,
238+
SawExprType,
238239
SawExprIf,
239240
SawExprWhile,
240241
SawExprMatch,
@@ -265,6 +266,7 @@ mod svh_visitor {
265266
ExprUnary(op, _) => SawExprUnary(op),
266267
ExprLit(ref lit) => SawExprLit(lit.node.clone()),
267268
ExprCast(..) => SawExprCast,
269+
ExprType(..) => SawExprType,
268270
ExprIf(..) => SawExprIf,
269271
ExprWhile(..) => SawExprWhile,
270272
ExprLoop(_, id) => SawExprLoop(id.map(content)),

src/librustc_trans/trans/consts.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr) -> ValueRef {
663663
_ => cx.sess().span_bug(e.span, "expected a struct or variant def")
664664
}
665665
}
666-
ast::ExprParen(ref e) => const_expr(cx, &**e).0,
666+
ast::ExprParen(ref e) |
667+
ast::ExprType(ref e, _) => const_expr(cx, &**e).0,
667668
ast::ExprBlock(ref block) => {
668669
match block.expr {
669670
Some(ref expr) => const_expr(cx, &**expr).0,

0 commit comments

Comments
 (0)