about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorJakub Bukaj <jakub@jakub.cc>2014-11-09 16:14:15 +0100
committerJakub Bukaj <jakub@jakub.cc>2014-11-16 14:23:15 +0100
commiteb01b17b06eb35542bb80ff7456043b0ed5572ba (patch)
tree75ee1c7184f8f3ea00966c91186c844ca268b3c7 /src/libsyntax/parse
parent08d6774f39743b69c199d79a5c64dbcef58c03d3 (diff)
downloadrust-eb01b17b06eb35542bb80ff7456043b0ed5572ba.tar.gz
rust-eb01b17b06eb35542bb80ff7456043b0ed5572ba.zip
Complete the removal of ty_nil, ast::LitNil, ast::TyBot and ast::TyUniq
[breaking-change]

This will break any uses of macros that assumed () being a valid literal.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs7
-rw-r--r--src/libsyntax/parse/obsolete.rs6
-rw-r--r--src/libsyntax/parse/parser.rs156
3 files changed, 66 insertions, 103 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 51738ece80f..2810db4eadd 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -1037,10 +1037,9 @@ mod test {
                                     }),
                                         id: ast::DUMMY_NODE_ID
                                     }),
-                                output: P(ast::Ty{id: ast::DUMMY_NODE_ID,
-                                                  node: ast::TyNil,
-                                                  span:sp(15,15)}), // not sure
-                                cf: ast::Return,
+                                output: ast::Return(P(ast::Ty{id: ast::DUMMY_NODE_ID,
+                                                  node: ast::TyTup(vec![]),
+                                                  span:sp(15,15)})), // not sure
                                 variadic: false
                             }),
                                     ast::NormalFn,
diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs
index 73787763c8b..1b2ab3c235d 100644
--- a/src/libsyntax/parse/obsolete.rs
+++ b/src/libsyntax/parse/obsolete.rs
@@ -17,8 +17,8 @@ Obsolete syntax that becomes too hard to parse can be
 removed.
 */
 
-use ast::{Expr, ExprLit, LitNil};
-use codemap::{Span, respan};
+use ast::{Expr, ExprTup};
+use codemap::Span;
 use parse::parser;
 use parse::token;
 use ptr::P;
@@ -96,7 +96,7 @@ impl<'a> ParserObsoleteMethods for parser::Parser<'a> {
     /// a placeholder expression
     fn obsolete_expr(&mut self, sp: Span, kind: ObsoleteSyntax) -> P<Expr> {
         self.obsolete(sp, kind);
-        self.mk_expr(sp.lo, sp.hi, ExprLit(P(respan(sp, LitNil))))
+        self.mk_expr(sp.lo, sp.hi, ExprTup(vec![]))
     }
 
     fn report(&mut self,
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index db10dc1bc90..4f487a10e98 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -30,13 +30,13 @@ use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field, FnDecl};
 use ast::{Once, Many};
 use ast::{FnUnboxedClosureKind, FnMutUnboxedClosureKind};
 use ast::{FnOnceUnboxedClosureKind};
-use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod};
+use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, ForeignMod, FunctionRetTy};
 use ast::{Ident, NormalFn, Inherited, ImplItem, Item, Item_, ItemStatic};
 use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst};
 use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy};
 use ast::{LifetimeDef, Lit, Lit_};
 use ast::{LitBool, LitChar, LitByte, LitBinary};
-use ast::{LitNil, LitStr, LitInt, Local, LocalLet};
+use ast::{LitStr, LitInt, Local, LocalLet};
 use ast::{MutImmutable, MutMutable, Mac_, MacInvocTT, MatchNormal};
 use ast::{Method, MutTy, BiMul, Mutability};
 use ast::{MethodImplItem, NamedField, UnNeg, NoReturn, UnNot};
@@ -44,18 +44,18 @@ use ast::{Pat, PatEnum, PatIdent, PatLit, PatRange, PatRegion, PatStruct};
 use ast::{PatTup, PatBox, PatWild, PatWildMulti, PatWildSingle};
 use ast::{PolyTraitRef};
 use ast::{QPath, RequiredMethod};
-use ast::{RetStyle, Return, BiShl, BiShr, Stmt, StmtDecl};
+use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
 use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField};
 use ast::{StructVariantKind, BiSub};
 use ast::StrStyle;
 use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
 use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
 use ast::{TtDelimited, TtSequence, TtToken};
-use ast::{TupleVariantKind, Ty, Ty_, TyBot};
+use ast::{TupleVariantKind, Ty, Ty_};
 use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
 use ast::{TyTypeof, TyInfer, TypeMethod};
-use ast::{TyNil, TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath};
-use ast::{TyRptr, TyTup, TyU32, TyUniq, TyVec, UnUniq};
+use ast::{TyParam, TyParamBound, TyParen, TyPath, TyPolyTraitRef, TyPtr, TyQPath};
+use ast::{TyRptr, TyTup, TyU32, TyVec, UnUniq};
 use ast::{TypeImplItem, TypeTraitItem, Typedef, UnboxedClosureKind};
 use ast::{UnnamedField, UnsafeBlock};
 use ast::{UnsafeFn, ViewItem, ViewItem_, ViewItemExternCrate, ViewItemUse};
@@ -1066,11 +1066,10 @@ impl<'a> Parser<'a> {
         self.expect_keyword(keywords::Fn);
         let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
         let (inputs, variadic) = self.parse_fn_args(false, true);
-        let (ret_style, ret_ty) = self.parse_ret_ty();
+        let ret_ty = self.parse_ret_ty();
         let decl = P(FnDecl {
             inputs: inputs,
             output: ret_ty,
-            cf: ret_style,
             variadic: variadic
         });
         TyBareFn(P(BareFnTy {
@@ -1100,11 +1099,10 @@ impl<'a> Parser<'a> {
         let lifetime_defs = self.parse_legacy_lifetime_defs(lifetime_defs);
         let (inputs, variadic) = self.parse_fn_args(false, false);
         let bounds = self.parse_colon_then_ty_param_bounds();
-        let (ret_style, ret_ty) = self.parse_ret_ty();
+        let ret_ty = self.parse_ret_ty();
         let decl = P(FnDecl {
             inputs: inputs,
             output: ret_ty,
-            cf: ret_style,
             variadic: variadic
         });
         TyProc(P(ClosureTy {
@@ -1200,11 +1198,10 @@ impl<'a> Parser<'a> {
 
         let bounds = self.parse_colon_then_ty_param_bounds();
 
-        let (return_style, output) = self.parse_ret_ty();
+        let output = self.parse_ret_ty();
         let decl = P(FnDecl {
             inputs: inputs,
             output: output,
-            cf: return_style,
             variadic: false
         });
 
@@ -1384,31 +1381,20 @@ impl<'a> Parser<'a> {
     }
 
     /// Parse optional return type [ -> TY ] in function decl
-    pub fn parse_ret_ty(&mut self) -> (RetStyle, P<Ty>) {
-        return if self.eat(&token::RArrow) {
-            let lo = self.span.lo;
+    pub fn parse_ret_ty(&mut self) -> FunctionRetTy {
+        if self.eat(&token::RArrow) {
             if self.eat(&token::Not) {
-                (
-                    NoReturn,
-                    P(Ty {
-                        id: ast::DUMMY_NODE_ID,
-                        node: TyBot,
-                        span: mk_sp(lo, self.last_span.hi)
-                    })
-                )
+                NoReturn(self.span)
             } else {
-                (Return, self.parse_ty(true))
+                Return(self.parse_ty(true))
             }
         } else {
             let pos = self.span.lo;
-            (
-                Return,
-                P(Ty {
-                    id: ast::DUMMY_NODE_ID,
-                    node: TyNil,
-                    span: mk_sp(pos, pos),
-                })
-            )
+            Return(P(Ty {
+                id: ast::DUMMY_NODE_ID,
+                node: TyTup(vec![]),
+                span: mk_sp(pos, pos),
+            }))
         }
     }
 
@@ -1423,34 +1409,29 @@ impl<'a> Parser<'a> {
 
         let t = if self.token == token::OpenDelim(token::Paren) {
             self.bump();
-            if self.token == token::CloseDelim(token::Paren) {
-                self.bump();
-                TyNil
-            } else {
-                // (t) is a parenthesized ty
-                // (t,) is the type of a tuple with only one field,
-                // of type t
-                let mut ts = vec!(self.parse_ty(true));
-                let mut one_tuple = false;
-                while self.token == token::Comma {
-                    self.bump();
-                    if self.token != token::CloseDelim(token::Paren) {
-                        ts.push(self.parse_ty(true));
-                    }
-                    else {
-                        one_tuple = true;
-                    }
-                }
 
-                if ts.len() == 1 && !one_tuple {
-                    self.expect(&token::CloseDelim(token::Paren));
-                    TyParen(ts.into_iter().nth(0).unwrap())
+            // (t) is a parenthesized ty
+            // (t,) is the type of a tuple with only one field,
+            // of type t
+            let mut ts = vec![];
+            let mut last_comma = false;
+            while self.token != token::CloseDelim(token::Paren) {
+                ts.push(self.parse_ty(true));
+                if self.token == token::Comma {
+                    last_comma = true;
+                    self.bump();
                 } else {
-                    let t = TyTup(ts);
-                    self.expect(&token::CloseDelim(token::Paren));
-                    t
+                    last_comma = false;
+                    break;
                 }
             }
+
+            self.expect(&token::CloseDelim(token::Paren));
+            if ts.len() == 1 && !last_comma {
+                TyParen(ts.into_iter().nth(0).unwrap())
+            } else {
+                TyTup(ts)
+            }
         } else if self.token == token::Tilde {
             // OWNED POINTER
             self.bump();
@@ -1459,7 +1440,7 @@ impl<'a> Parser<'a> {
                 token::OpenDelim(token::Bracket) => self.obsolete(last_span, ObsoleteOwnedVector),
                 _ => self.obsolete(last_span, ObsoleteOwnedType)
             }
-            TyUniq(self.parse_ty(false))
+            TyTup(vec![self.parse_ty(false)])
         } else if self.token == token::BinOp(token::Star) {
             // STAR POINTER (bare pointer?)
             self.bump();
@@ -1662,10 +1643,6 @@ impl<'a> Parser<'a> {
                 LitBinary(parse::binary_lit(i.as_str())),
             token::LitBinaryRaw(i, _) =>
                 LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect())),
-            token::OpenDelim(token::Paren) => {
-                self.expect(&token::CloseDelim(token::Paren));
-                LitNil
-            },
             _ => { self.unexpected_last(tok); }
         }
     }
@@ -2126,33 +2103,29 @@ impl<'a> Parser<'a> {
         match self.token {
             token::OpenDelim(token::Paren) => {
                 self.bump();
+
                 // (e) is parenthesized e
                 // (e,) is a tuple with only one field, e
+                let mut es = vec![];
                 let mut trailing_comma = false;
-                if self.token == token::CloseDelim(token::Paren) {
-                    hi = self.span.hi;
-                    self.bump();
-                    let lit = P(spanned(lo, hi, LitNil));
-                    return self.mk_expr(lo, hi, ExprLit(lit));
-                }
-                let mut es = vec!(self.parse_expr());
-                self.commit_expr(&**es.last().unwrap(), &[],
-                                 &[token::Comma, token::CloseDelim(token::Paren)]);
-                while self.token == token::Comma {
-                    self.bump();
-                    if self.token != token::CloseDelim(token::Paren) {
-                        es.push(self.parse_expr());
-                        self.commit_expr(&**es.last().unwrap(), &[],
-                                         &[token::Comma, token::CloseDelim(token::Paren)]);
-                    } else {
+                while self.token != token::CloseDelim(token::Paren) {
+                    es.push(self.parse_expr());
+                    self.commit_expr(&**es.last().unwrap(), &[],
+                                     &[token::Comma, token::CloseDelim(token::Paren)]);
+                    if self.token == token::Comma {
                         trailing_comma = true;
+
+                        self.bump();
+                    } else {
+                        trailing_comma = false;
+                        break;
                     }
                 }
-                hi = self.span.hi;
-                self.commit_expr_expecting(&**es.last().unwrap(), token::CloseDelim(token::Paren));
+                self.bump();
 
+                hi = self.span.hi;
                 return if es.len() == 1 && !trailing_comma {
-                   self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap()))
+                    self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap()))
                 } else {
                     self.mk_expr(lo, hi, ExprTup(es))
                 }
@@ -3293,13 +3266,8 @@ impl<'a> Parser<'a> {
             // parse (pat,pat,pat,...) as tuple
             self.bump();
             if self.token == token::CloseDelim(token::Paren) {
-                hi = self.span.hi;
                 self.bump();
-                let lit = P(codemap::Spanned {
-                    node: LitNil,
-                    span: mk_sp(lo, hi)});
-                let expr = self.mk_expr(lo, hi, ExprLit(lit));
-                pat = PatLit(expr);
+                pat = PatTup(vec![]);
             } else {
                 let mut fields = vec!(self.parse_pat());
                 if self.look_ahead(1, |t| *t != token::CloseDelim(token::Paren)) {
@@ -4137,12 +4105,11 @@ impl<'a> Parser<'a> {
     pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> P<FnDecl> {
 
         let (args, variadic) = self.parse_fn_args(true, allow_variadic);
-        let (ret_style, ret_ty) = self.parse_ret_ty();
+        let ret_ty = self.parse_ret_ty();
 
         P(FnDecl {
             inputs: args,
             output: ret_ty,
-            cf: ret_style,
             variadic: variadic
         })
     }
@@ -4337,12 +4304,11 @@ impl<'a> Parser<'a> {
 
         let hi = self.span.hi;
 
-        let (ret_style, ret_ty) = self.parse_ret_ty();
+        let ret_ty = self.parse_ret_ty();
 
         let fn_decl = P(FnDecl {
             inputs: fn_inputs,
             output: ret_ty,
-            cf: ret_style,
             variadic: false
         });
 
@@ -4368,10 +4334,10 @@ impl<'a> Parser<'a> {
                 (optional_unboxed_closure_kind, args)
             }
         };
-        let (style, output) = if self.token == token::RArrow {
+        let output = if self.token == token::RArrow {
             self.parse_ret_ty()
         } else {
-            (Return, P(Ty {
+            Return(P(Ty {
                 id: ast::DUMMY_NODE_ID,
                 node: TyInfer,
                 span: self.span,
@@ -4381,7 +4347,6 @@ impl<'a> Parser<'a> {
         (P(FnDecl {
             inputs: inputs_captures,
             output: output,
-            cf: style,
             variadic: false
         }), optional_unboxed_closure_kind)
     }
@@ -4394,10 +4359,10 @@ impl<'a> Parser<'a> {
                                      seq_sep_trailing_allowed(token::Comma),
                                      |p| p.parse_fn_block_arg());
 
-        let (style, output) = if self.token == token::RArrow {
+        let output = if self.token == token::RArrow {
             self.parse_ret_ty()
         } else {
-            (Return, P(Ty {
+            Return(P(Ty {
                 id: ast::DUMMY_NODE_ID,
                 node: TyInfer,
                 span: self.span,
@@ -4407,7 +4372,6 @@ impl<'a> Parser<'a> {
         P(FnDecl {
             inputs: inputs,
             output: output,
-            cf: style,
             variadic: false
         })
     }