From ed8f5039115308ca9d5591126e4d8a77864d4730 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 18 Dec 2014 17:55:04 +1300 Subject: Add hypothetical support for ranges with only an upper bound Note that this doesn't add the surface syntax. --- src/libsyntax/ast.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 4 +++- src/libsyntax/visit.rs | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d4932fbb5f1..e53e2cea1cc 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -724,7 +724,7 @@ pub enum Expr_ { ExprTupField(P, Spanned), ExprIndex(P, P), ExprSlice(P, Option>, Option>, Mutability), - ExprRange(P, Option>), + ExprRange(Option>, Option>), /// Variable reference, possibly containing `::` and/or /// type parameters, e.g. foo::bar:: diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index c58901701f5..ede023c4e8b 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1391,7 +1391,7 @@ pub fn noop_fold_expr(Expr {id, node, span}: Expr, folder: &mut T) -> m) } ExprRange(e1, e2) => { - ExprRange(folder.fold_expr(e1), + ExprRange(e1.map(|x| folder.fold_expr(x)), e2.map(|x| folder.fold_expr(x))) } ExprPath(pth) => ExprPath(folder.fold_path(pth)), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a2e2abab03e..ec1e966926a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2144,7 +2144,7 @@ impl<'a> Parser<'a> { start: P, end: Option>) -> ast::Expr_ { - ExprRange(start, end) + ExprRange(Some(start), end) } pub fn mk_field(&mut self, expr: P, ident: ast::SpannedIdent) -> ast::Expr_ { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 623f20bccd2..a4b349c5f23 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1760,7 +1760,9 @@ impl<'a> State<'a> { try!(word(&mut self.s, "]")); } ast::ExprRange(ref start, ref end) => { - try!(self.print_expr(&**start)); + if let &Some(ref e) = start { + try!(self.print_expr(&**e)); + } try!(word(&mut self.s, "..")); if let &Some(ref e) = end { try!(self.print_expr(&**e)); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 714339d0f0a..cde9ba932be 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -872,7 +872,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { walk_expr_opt(visitor, end) } ExprRange(ref start, ref end) => { - visitor.visit_expr(&**start); + walk_expr_opt(visitor, start); walk_expr_opt(visitor, end) } ExprPath(ref path) => { -- cgit 1.4.1-3-g733a5