diff options
| author | Jakub Bukaj <jakub@jakub.cc> | 2014-11-09 16:14:15 +0100 |
|---|---|---|
| committer | Jakub Bukaj <jakub@jakub.cc> | 2014-11-16 14:23:15 +0100 |
| commit | eb01b17b06eb35542bb80ff7456043b0ed5572ba (patch) | |
| tree | 75ee1c7184f8f3ea00966c91186c844ca268b3c7 /src/libsyntax | |
| parent | 08d6774f39743b69c199d79a5c64dbcef58c03d3 (diff) | |
| download | rust-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')
| -rw-r--r-- | src/libsyntax/ast.rs | 25 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/encodable.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/ty.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/format.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/obsolete.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 156 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 102 | ||||
| -rw-r--r-- | src/libsyntax/test.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 20 |
17 files changed, 184 insertions, 218 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7c5de627d08..0e1921a0773 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -893,7 +893,6 @@ pub enum Lit_ { LitInt(u64, LitIntType), LitFloat(InternedString, FloatTy), LitFloatUnsuffixed(InternedString), - LitNil, LitBool(bool), } @@ -1086,12 +1085,6 @@ pub struct BareFnTy { #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] /// The different kinds of types recognized by the compiler pub enum Ty_ { - /// The unit type (`()`) - TyNil, - /// The bottom type (`!`) - TyBot, - TyUniq(P<Ty>), - /// An array (`[T]`) TyVec(P<Ty>), /// A fixed length array (`[T, ..n]`) TyFixedLengthVec(P<Ty>, P<Expr>), @@ -1175,8 +1168,7 @@ impl Arg { #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub struct FnDecl { pub inputs: Vec<Arg>, - pub output: P<Ty>, - pub cf: RetStyle, + pub output: FunctionRetTy, pub variadic: bool } @@ -1198,12 +1190,21 @@ impl fmt::Show for FnStyle { } #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] -pub enum RetStyle { +pub enum FunctionRetTy { /// Functions with return type ! that always /// raise an error or exit (i.e. never return to the caller) - NoReturn, + NoReturn(Span), /// Everything else - Return, + Return(P<Ty>), +} + +impl FunctionRetTy { + pub fn span(&self) -> Span { + match *self { + NoReturn(span) => span, + Return(ref ty) => ty.span + } + } } /// Represents the kind of 'self' associated with a method diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 1e2d935af00..0c7a3cf4a6c 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -248,7 +248,7 @@ impl DummyResult { pub fn raw_expr(sp: Span) -> P<ast::Expr> { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprLit(P(codemap::respan(sp, ast::LitNil))), + node: ast::ExprLit(P(codemap::respan(sp, ast::LitBool(false)))), span: sp, }) } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 862cbf3d7ca..ffc42b67033 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -54,11 +54,9 @@ pub trait AstBuilder { fn ty_ptr(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty>; - fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty>; fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty>; fn ty_infer(&self, sp: Span) -> P<ast::Ty>; - fn ty_nil(&self) -> P<ast::Ty>; fn ty_vars(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ; fn ty_vars_global(&self, ty_params: &OwnedSlice<ast::TyParam>) -> Vec<P<ast::Ty>> ; @@ -377,9 +375,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.ty(span, ast::TyPtr(self.ty_mt(ty, mutbl))) } - fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> { - self.ty(span, ast::TyUniq(ty)) - } fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> { self.ty_path( @@ -406,14 +401,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.ty(span, ast::TyInfer) } - fn ty_nil(&self) -> P<ast::Ty> { - P(ast::Ty { - id: ast::DUMMY_NODE_ID, - node: ast::TyNil, - span: DUMMY_SP, - }) - } - fn typaram(&self, span: Span, id: ast::Ident, @@ -809,8 +796,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.pat(span, pat) } fn pat_tuple(&self, span: Span, pats: Vec<P<ast::Pat>>) -> P<ast::Pat> { - let pat = ast::PatTup(pats); - self.pat(span, pat) + self.pat(span, ast::PatTup(pats)) } fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> { @@ -931,11 +917,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } // FIXME unused self - fn fn_decl(&self, inputs: Vec<ast::Arg> , output: P<ast::Ty>) -> P<ast::FnDecl> { + fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> { P(ast::FnDecl { inputs: inputs, - output: output, - cf: ast::Return, + output: ast::Return(output), variadic: false }) } diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index af7cd4157ec..e2867c2fbab 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -46,7 +46,6 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => { accumulator.push_str(format!("-{}", i).as_slice()); } - ast::LitNil => {} ast::LitBool(b) => { accumulator.push_str(format!("{}", b).as_slice()); } diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 69eb260b8c4..62f3b5d01b4 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -88,7 +88,7 @@ //! } //! ``` -use ast::{MetaItem, Item, Expr, ExprRet, MutMutable, LitNil}; +use ast::{MetaItem, Item, Expr, ExprRet, MutMutable}; use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; @@ -186,7 +186,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, if stmts.is_empty() { let ret_ok = cx.expr(trait_span, ExprRet(Some(cx.expr_ok(trait_span, - cx.expr_lit(trait_span, LitNil))))); + cx.expr_tuple(trait_span, vec![]))))); stmts.push(cx.stmt_expr(ret_ok)); } @@ -231,7 +231,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, if stmts.len() == 0 { let ret_ok = cx.expr(trait_span, ExprRet(Some(cx.expr_ok(trait_span, - cx.expr_lit(trait_span, LitNil))))); + cx.expr_tuple(trait_span, vec![]))))); stmts.push(cx.stmt_expr(ret_ok)); } diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 7c32b845508..4be299994fd 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -922,7 +922,7 @@ impl<'a> MethodDef<'a> { } // Here is the pat = `(&VariantK, &VariantK, ...)` - let single_pat = cx.pat(sp, ast::PatTup(subpats)); + let single_pat = cx.pat_tuple(sp, subpats); // For the BodyK, we need to delegate to our caller, // passing it an EnumMatching to indicate which case diff --git a/src/libsyntax/ext/deriving/generic/ty.rs b/src/libsyntax/ext/deriving/generic/ty.rs index 1ec1e3b1224..8b46769d633 100644 --- a/src/libsyntax/ext/deriving/generic/ty.rs +++ b/src/libsyntax/ext/deriving/generic/ty.rs @@ -152,14 +152,9 @@ impl<'a> Ty<'a> { cx.ty_path(self.to_path(cx, span, self_ty, self_generics), None) } Tuple(ref fields) => { - let ty = if fields.is_empty() { - ast::TyNil - } else { - ast::TyTup(fields.iter() - .map(|f| f.to_ty(cx, span, self_ty, self_generics)) - .collect()) - }; - + let ty = ast::TyTup(fields.iter() + .map(|f| f.to_ty(cx, span, self_ty, self_generics)) + .collect()); cx.ty(span, ty) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 87406081aae..fa69495fa42 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -159,7 +159,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { // `_ => [<elseopt> | ()]` let else_arm = { let pat_under = fld.cx.pat_wild(span); - let else_expr = elseopt.unwrap_or_else(|| fld.cx.expr_lit(span, ast::LitNil)); + let else_expr = elseopt.unwrap_or_else(|| fld.cx.expr_tuple(span, vec![])); fld.cx.arm(span, vec![pat_under], else_expr) }; diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index a28f24e7663..a816b479630 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -654,7 +654,7 @@ impl<'a, 'b> Context<'a, 'b> { // // But the nested match expression is proved to perform not as well // as series of let's; the first approach does. - let pat = self.ecx.pat(self.fmtsp, ast::PatTup(pats)); + let pat = self.ecx.pat_tuple(self.fmtsp, pats); let arm = self.ecx.arm(self.fmtsp, vec!(pat), body); let head = self.ecx.expr(self.fmtsp, ast::ExprTup(heads)); self.ecx.expr_match(self.fmtsp, head, vec!(arm)) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d7c3ca8efc4..56d91282437 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -391,8 +391,7 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> { t.map(|Ty {id, node, span}| Ty { id: fld.new_id(id), node: match node { - TyNil | TyBot | TyInfer => node, - TyUniq(ty) => TyUniq(fld.fold_ty(ty)), + TyInfer => node, TyVec(ty) => TyVec(fld.fold_ty(ty)), TyPtr(mt) => TyPtr(fld.fold_mt(mt)), TyRptr(region, mt) => { @@ -706,10 +705,12 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T) } pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> { - decl.map(|FnDecl {inputs, output, cf, variadic}| FnDecl { + decl.map(|FnDecl {inputs, output, variadic}| FnDecl { inputs: inputs.move_map(|x| fld.fold_arg(x)), - output: fld.fold_ty(output), - cf: cf, + output: match output { + Return(ty) => Return(fld.fold_ty(ty)), + NoReturn(span) => NoReturn(span) + }, variadic: variadic }) } @@ -1146,10 +1147,12 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) -> attrs: attrs.move_map(|x| folder.fold_attribute(x)), node: match node { ForeignItemFn(fdec, generics) => { - ForeignItemFn(fdec.map(|FnDecl {inputs, output, cf, variadic}| FnDecl { + ForeignItemFn(fdec.map(|FnDecl {inputs, output, variadic}| FnDecl { inputs: inputs.move_map(|a| folder.fold_arg(a)), - output: folder.fold_ty(output), - cf: cf, + output: match output { + Return(ty) => Return(folder.fold_ty(ty)), + NoReturn(span) => NoReturn(span) + }, variadic: variadic }), folder.fold_generics(generics)) } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 4881be8996a..fa10cb90f83 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -24,7 +24,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![allow(unknown_features)] -#![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)] +#![feature(if_let, macro_rules, globs, default_type_params, phase, slicing_syntax)] #![feature(quote, struct_variant, unsafe_destructor, import_shadowing)] extern crate arena; 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 }) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index c1515a36bec..7025555ab40 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -645,12 +645,6 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(ty.span.lo)); try!(self.ibox(0u)); match ty.node { - ast::TyNil => try!(word(&mut self.s, "()")), - ast::TyBot => try!(word(&mut self.s, "!")), - ast::TyUniq(ref ty) => { - try!(word(&mut self.s, "~")); - try!(self.print_type(&**ty)); - } ast::TyVec(ref ty) => { try!(word(&mut self.s, "[")); try!(self.print_type(&**ty)); @@ -2307,15 +2301,7 @@ impl<'a> State<'a> { } try!(self.pclose()); - try!(self.maybe_print_comment(decl.output.span.lo)); - match decl.output.node { - ast::TyNil => Ok(()), - _ => { - try!(self.space_if_not_bol()); - try!(self.word_space("->")); - self.print_type(&*decl.output) - } - } + self.print_fn_output(decl) } pub fn print_fn_block_args( @@ -2333,16 +2319,24 @@ impl<'a> State<'a> { try!(self.print_fn_args(decl, None)); try!(word(&mut self.s, "|")); - match decl.output.node { - ast::TyInfer => {} - _ => { - try!(self.space_if_not_bol()); - try!(self.word_space("->")); - try!(self.print_type(&*decl.output)); + if let ast::Return(ref ty) = decl.output { + if ty.node == ast::TyInfer { + return self.maybe_print_comment(ty.span.lo); } } - self.maybe_print_comment(decl.output.span.lo) + try!(self.space_if_not_bol()); + try!(self.word_space("->")); + match decl.output { + ast::Return(ref ty) => { + try!(self.print_type(&**ty)); + self.maybe_print_comment(ty.span.lo) + } + ast::NoReturn(span) => { + try!(self.word_nbsp("!")); + self.maybe_print_comment(span.lo) + } + } } pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause) @@ -2359,16 +2353,24 @@ impl<'a> State<'a> { try!(self.print_fn_args(decl, None)); try!(word(&mut self.s, ")")); - match decl.output.node { - ast::TyInfer => {} - _ => { - try!(self.space_if_not_bol()); - try!(self.word_space("->")); - try!(self.print_type(&*decl.output)); + if let ast::Return(ref ty) = decl.output { + if ty.node == ast::TyInfer { + return self.maybe_print_comment(ty.span.lo); } } - self.maybe_print_comment(decl.output.span.lo) + try!(self.space_if_not_bol()); + try!(self.word_space("->")); + match decl.output { + ast::Return(ref ty) => { + try!(self.print_type(&**ty)); + self.maybe_print_comment(ty.span.lo) + } + ast::NoReturn(span) => { + try!(self.word_nbsp("!")); + self.maybe_print_comment(span.lo) + } + } } pub fn print_bounds(&mut self, @@ -2627,20 +2629,30 @@ impl<'a> State<'a> { } pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> IoResult<()> { - match decl.output.node { - ast::TyNil => Ok(()), - _ => { - try!(self.space_if_not_bol()); - try!(self.ibox(indent_unit)); - try!(self.word_space("->")); - if decl.cf == ast::NoReturn { - try!(self.word_nbsp("!")); - } else { - try!(self.print_type(&*decl.output)); + if let ast::Return(ref ty) = decl.output { + match ty.node { + ast::TyTup(ref tys) if tys.is_empty() => { + return self.maybe_print_comment(ty.span.lo); } - self.end() + _ => () } } + + try!(self.space_if_not_bol()); + try!(self.ibox(indent_unit)); + try!(self.word_space("->")); + match decl.output { + ast::NoReturn(_) => + try!(self.word_nbsp("!")), + ast::Return(ref ty) => + try!(self.print_type(&**ty)) + } + try!(self.end()); + + match decl.output { + ast::Return(ref output) => self.maybe_print_comment(output.span.lo), + _ => Ok(()) + } } pub fn print_ty_fn(&mut self, @@ -2700,8 +2712,6 @@ impl<'a> State<'a> { try!(self.print_bounds(":", bounds)); - try!(self.maybe_print_comment(decl.output.span.lo)); - try!(self.print_fn_output(decl)); match generics { @@ -2807,7 +2817,6 @@ impl<'a> State<'a> { ast_util::float_ty_to_string(t).as_slice()).as_slice()) } ast::LitFloatUnsuffixed(ref f) => word(&mut self.s, f.get()), - ast::LitNil => word(&mut self.s, "()"), ast::LitBool(val) => { if val { word(&mut self.s, "true") } else { word(&mut self.s, "false") } } @@ -3003,10 +3012,9 @@ mod test { let decl = ast::FnDecl { inputs: Vec::new(), - output: P(ast::Ty {id: 0, - node: ast::TyNil, - span: codemap::DUMMY_SP}), - cf: ast::Return, + output: ast::Return(P(ast::Ty {id: 0, + node: ast::TyTup(vec![]), + span: codemap::DUMMY_SP})), variadic: false }; let generics = ast_util::empty_generics(); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 29637e88dd5..8b6d752d484 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -289,9 +289,12 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { fn has_test_signature(i: &ast::Item) -> HasTestSignature { match &i.node { &ast::ItemFn(ref decl, _, _, ref generics, _) => { - let no_output = match decl.output.node { - ast::TyNil => true, - _ => false, + let no_output = match decl.output { + ast::Return(ref ret_ty) => match ret_ty.node { + ast::TyTup(ref tys) if tys.is_empty() => true, + _ => false, + }, + ast::NoReturn(_) => false }; if decl.inputs.is_empty() && no_output @@ -325,9 +328,12 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { match i.node { ast::ItemFn(ref decl, _, _, ref generics, _) => { let input_cnt = decl.inputs.len(); - let no_output = match decl.output.node { - ast::TyNil => true, - _ => false + let no_output = match decl.output { + ast::Return(ref ret_ty) => match ret_ty.node { + ast::TyTup(ref tys) if tys.is_empty() => true, + _ => false, + }, + ast::NoReturn(_) => false }; let tparm_cnt = generics.ty_params.len(); // NB: inadequate check, but we're running diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 1b1d1e9cace..f30a4325eb8 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -341,7 +341,7 @@ pub fn skip_ty<'v, V: Visitor<'v>>(_: &mut V, _: &'v Ty) { pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { match typ.node { - TyUniq(ref ty) | TyVec(ref ty) | TyParen(ref ty) => { + TyVec(ref ty) | TyParen(ref ty) => { visitor.visit_ty(&**ty) } TyPtr(ref mutable_type) => { @@ -360,7 +360,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output); + walk_fn_ret_ty(visitor, &function_declaration.decl.output); walk_ty_param_bounds(visitor, &function_declaration.bounds); walk_lifetime_decls(visitor, &function_declaration.lifetimes); } @@ -368,7 +368,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output); + walk_fn_ret_ty(visitor, &function_declaration.decl.output); walk_ty_param_bounds(visitor, &function_declaration.bounds); walk_lifetime_decls(visitor, &function_declaration.lifetimes); } @@ -376,7 +376,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { for argument in function_declaration.decl.inputs.iter() { visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.decl.output); + walk_fn_ret_ty(visitor, &function_declaration.decl.output); walk_lifetime_decls(visitor, &function_declaration.lifetimes); } TyPath(ref path, ref opt_bounds, id) => { @@ -403,7 +403,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { TyTypeof(ref expression) => { visitor.visit_expr(&**expression) } - TyNil | TyBot | TyInfer => {} + TyInfer => {} } } @@ -538,12 +538,18 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics } } +pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) { + if let Return(ref output_ty) = *ret_ty { + visitor.visit_ty(&**output_ty) + } +} + pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) { for argument in function_declaration.inputs.iter() { visitor.visit_pat(&*argument.pat); visitor.visit_ty(&*argument.ty) } - visitor.visit_ty(&*function_declaration.output) + walk_fn_ret_ty(visitor, &function_declaration.output) } // Note: there is no visit_method() method in the visitor, instead override @@ -601,7 +607,7 @@ pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v Type visitor.visit_ty(&*argument_type.ty) } visitor.visit_generics(&method_type.generics); - visitor.visit_ty(&*method_type.decl.output); + walk_fn_ret_ty(visitor, &method_type.decl.output); for attr in method_type.attrs.iter() { visitor.visit_attribute(attr); } |
