Implement type ascription.

This commit is contained in:
Eduard Burtescu
2015-02-01 09:59:46 +02:00
committed by Vadim Petrochenkov
parent ce7bc51933
commit b8157cc67f
20 changed files with 112 additions and 12 deletions

View File

@@ -445,7 +445,7 @@ fn needs_parentheses(expr: &ast::Expr) -> bool {
ast::ExprAssign(..) | ast::ExprBinary(..) |
ast::ExprClosure(..) |
ast::ExprAssignOp(..) | ast::ExprCast(..) |
ast::ExprInPlace(..) => true,
ast::ExprInPlace(..) | ast::ExprType(..) => true,
_ => false,
}
}
@@ -2036,6 +2036,11 @@ impl<'a> State<'a> {
try!(self.word_space("as"));
try!(self.print_type(&**ty));
}
ast::ExprType(ref expr, ref ty) => {
try!(self.print_expr(&**expr));
try!(self.word_space(":"));
try!(self.print_type(&**ty));
}
ast::ExprIf(ref test, ref blk, ref elseopt) => {
try!(self.print_if(&**test, &**blk, elseopt.as_ref().map(|e| &**e)));
}