From 962d5c16b5bb8103785781e61e578ab5a784b1c4 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 17 Jun 2016 02:30:01 +0000 Subject: Fix fallout --- src/libsyntax/parse/classify.rs | 10 +-- src/libsyntax/parse/mod.rs | 12 +-- src/libsyntax/parse/parser.rs | 183 +++++++++++++++++++++------------------- 3 files changed, 106 insertions(+), 99 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 89110f3160f..4fe4ec7e4c0 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -47,13 +47,9 @@ pub fn expr_is_simple_block(e: &ast::Expr) -> bool { /// seen the semicolon, and thus don't need another. pub fn stmt_ends_with_semi(stmt: &ast::StmtKind) -> bool { match *stmt { - ast::StmtKind::Decl(ref d, _) => { - match d.node { - ast::DeclKind::Local(_) => true, - ast::DeclKind::Item(_) => false, - } - } - ast::StmtKind::Expr(ref e, _) => expr_requires_semi_to_be_stmt(e), + ast::StmtKind::Local(_) => true, + ast::StmtKind::Item(_) => false, + ast::StmtKind::Expr(ref e) => expr_requires_semi_to_be_stmt(e), ast::StmtKind::Semi(..) => false, ast::StmtKind::Mac(..) => false, } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2e4d46bc983..f21d7cb8fdb 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -841,7 +841,7 @@ mod tests { #[test] fn parse_stmt_1 () { assert!(string_to_stmt("b;".to_string()) == - Some(Spanned{ + Some(ast::Stmt { node: ast::StmtKind::Expr(P(ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, ast::Path { @@ -855,8 +855,8 @@ mod tests { ), }), span: sp(0,1), - attrs: None}), - ast::DUMMY_NODE_ID), + attrs: None})), + id: ast::DUMMY_NODE_ID, span: sp(0,1)})) } @@ -932,7 +932,7 @@ mod tests { } }, P(ast::Block { - stmts: vec!(Spanned{ + stmts: vec!(ast::Stmt { node: ast::StmtKind::Semi(P(ast::Expr{ id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Path(None, @@ -950,8 +950,8 @@ mod tests { ), }), span: sp(17,18), - attrs: None,}), - ast::DUMMY_NODE_ID), + attrs: None,})), + id: ast::DUMMY_NODE_ID, span: sp(17,19)}), expr: None, id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 341b076e7cf..e74c30276ff 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -16,7 +16,7 @@ use ast::{Mod, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::Block; use ast::{BlockCheckMode, CaptureBy}; use ast::{Constness, Crate, CrateConfig}; -use ast::{Decl, DeclKind, Defaultness}; +use ast::Defaultness; use ast::{EMPTY_CTXT, EnumDef}; use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; @@ -3804,13 +3804,6 @@ impl<'a> Parser<'a> { })) } - /// Parse a "let" stmt - fn parse_let(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { - let lo = self.span.lo; - let local = self.parse_local(attrs)?; - Ok(P(spanned(lo, self.last_span.hi, DeclKind::Local(local)))) - } - /// Parse a structure field fn parse_name_and_ty(&mut self, pr: Visibility, attrs: Vec ) -> PResult<'a, StructField> { @@ -3923,12 +3916,12 @@ impl<'a> Parser<'a> { let attrs = self.parse_outer_attributes()?; let lo = self.span.lo; - Ok(Some(if self.check_keyword(keywords::Let) { - self.expect_keyword(keywords::Let)?; - let decl = self.parse_let(attrs.into_thin_attrs())?; - let hi = decl.span.hi; - let stmt = StmtKind::Decl(decl, ast::DUMMY_NODE_ID); - spanned(lo, hi, stmt) + Ok(Some(if self.eat_keyword(keywords::Let) { + Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Local(self.parse_local(attrs.into_thin_attrs())?), + span: mk_sp(lo, self.last_span.hi), + } } else if self.token.is_ident() && !self.token.is_any_keyword() && self.look_ahead(1, |t| *t == token::Not) { @@ -3979,9 +3972,12 @@ impl<'a> Parser<'a> { }; if id.name == keywords::Invalid.name() { - let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })); - let stmt = StmtKind::Mac(mac, style, attrs.into_thin_attrs()); - spanned(lo, hi, stmt) + let mac = spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }); + Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Mac(P((mac, style, attrs.into_thin_attrs()))), + span: mk_sp(lo, hi), + } } else { // if it has a special ident, it's definitely an item // @@ -3995,25 +3991,28 @@ impl<'a> Parser<'a> { followed by a semicolon"); } } - spanned(lo, hi, StmtKind::Decl( - P(spanned(lo, hi, DeclKind::Item( + Stmt { + id: ast::DUMMY_NODE_ID, + span: mk_sp(lo, hi), + node: StmtKind::Item({ self.mk_item( lo, hi, id /*id is good here*/, ItemKind::Mac(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })), - Visibility::Inherited, attrs)))), - ast::DUMMY_NODE_ID)) + Visibility::Inherited, attrs) + }), + } } } else { // FIXME: Bad copy of attrs let restrictions = self.restrictions | Restrictions::NO_NONINLINE_MOD; match self.with_res(restrictions, |this| this.parse_item_(attrs.clone(), false, true))? { - Some(i) => { - let hi = i.span.hi; - let decl = P(spanned(lo, hi, DeclKind::Item(i))); - spanned(lo, hi, StmtKind::Decl(decl, ast::DUMMY_NODE_ID)) - } + Some(i) => Stmt { + id: ast::DUMMY_NODE_ID, + span: mk_sp(lo, i.span.hi), + node: StmtKind::Item(i), + }, None => { let unused_attrs = |attrs: &[_], s: &mut Self| { if attrs.len() > 0 { @@ -4037,9 +4036,11 @@ impl<'a> Parser<'a> { // Remainder are line-expr stmts. let e = self.parse_expr_res( Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))?; - let hi = e.span.hi; - let stmt = StmtKind::Expr(e, ast::DUMMY_NODE_ID); - spanned(lo, hi, stmt) + Stmt { + id: ast::DUMMY_NODE_ID, + span: mk_sp(lo, e.span.hi), + node: StmtKind::Expr(e), + } } } })) @@ -4085,7 +4086,7 @@ impl<'a> Parser<'a> { let mut expr = None; while !self.eat(&token::CloseDelim(token::Brace)) { - let Spanned {node, span} = if let Some(s) = self.parse_stmt_() { + let Stmt {node, span, ..} = if let Some(s) = self.parse_stmt_() { s } else if self.token == token::Eof { break; @@ -4093,60 +4094,13 @@ impl<'a> Parser<'a> { // Found only `;` or `}`. continue; }; + match node { - StmtKind::Expr(e, _) => { + StmtKind::Expr(e) => { self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)?; } - StmtKind::Mac(mac, MacStmtStyle::NoBraces, attrs) => { - // statement macro without braces; might be an - // expr depending on whether a semicolon follows - match self.token { - token::Semi => { - stmts.push(Spanned { - node: StmtKind::Mac(mac, MacStmtStyle::Semicolon, attrs), - span: mk_sp(span.lo, self.span.hi), - }); - self.bump(); - } - _ => { - let e = self.mk_mac_expr(span.lo, span.hi, - mac.and_then(|m| m.node), - None); - let lo = e.span.lo; - let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?; - let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; - self.handle_expression_like_statement( - e, - span, - &mut stmts, - &mut expr)?; - } - } - } - StmtKind::Mac(m, style, attrs) => { - // statement macro; might be an expr - match self.token { - token::Semi => { - stmts.push(Spanned { - node: StmtKind::Mac(m, MacStmtStyle::Semicolon, attrs), - span: mk_sp(span.lo, self.span.hi), - }); - self.bump(); - } - token::CloseDelim(token::Brace) => { - // if a block ends in `m!(arg)` without - // a `;`, it must be an expr - expr = Some(self.mk_mac_expr(span.lo, span.hi, - m.and_then(|x| x.node), - attrs)); - } - _ => { - stmts.push(Spanned { - node: StmtKind::Mac(m, style, attrs), - span: span - }); - } - } + StmtKind::Mac(mac) => { + self.handle_macro_in_block(mac.unwrap(), span, &mut stmts, &mut expr)?; } _ => { // all other kinds of statements: let mut hi = span.hi; @@ -4155,7 +4109,8 @@ impl<'a> Parser<'a> { hi = self.last_span.hi; } - stmts.push(Spanned { + stmts.push(Stmt { + id: ast::DUMMY_NODE_ID, node: node, span: mk_sp(span.lo, hi) }); @@ -4172,6 +4127,60 @@ impl<'a> Parser<'a> { })) } + fn handle_macro_in_block(&mut self, + (mac, style, attrs): (ast::Mac, MacStmtStyle, ThinAttributes), + span: Span, + stmts: &mut Vec, + last_block_expr: &mut Option>) + -> PResult<'a, ()> { + if style == MacStmtStyle::NoBraces { + // statement macro without braces; might be an + // expr depending on whether a semicolon follows + match self.token { + token::Semi => { + stmts.push(Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Mac(P((mac, MacStmtStyle::Semicolon, attrs))), + span: mk_sp(span.lo, self.span.hi), + }); + self.bump(); + } + _ => { + let e = self.mk_mac_expr(span.lo, span.hi, mac.node, None); + let lo = e.span.lo; + let e = self.parse_dot_or_call_expr_with(e, lo, attrs)?; + let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?; + self.handle_expression_like_statement(e, span, stmts, last_block_expr)?; + } + } + } else { + // statement macro; might be an expr + match self.token { + token::Semi => { + stmts.push(Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Mac(P((mac, MacStmtStyle::Semicolon, attrs))), + span: mk_sp(span.lo, self.span.hi), + }); + self.bump(); + } + token::CloseDelim(token::Brace) => { + // if a block ends in `m!(arg)` without + // a `;`, it must be an expr + *last_block_expr = Some(self.mk_mac_expr(span.lo, span.hi, mac.node, attrs)); + } + _ => { + stmts.push(Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Mac(P((mac, style, attrs))), + span: span + }); + } + } + } + Ok(()) + } + fn handle_expression_like_statement(&mut self, e: P, span: Span, @@ -4197,15 +4206,17 @@ impl<'a> Parser<'a> { hi: self.last_span.hi, expn_id: span.expn_id, }; - stmts.push(Spanned { - node: StmtKind::Semi(e, ast::DUMMY_NODE_ID), + stmts.push(Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Semi(e), span: span_with_semi, }); } token::CloseDelim(token::Brace) => *last_block_expr = Some(e), _ => { - stmts.push(Spanned { - node: StmtKind::Expr(e, ast::DUMMY_NODE_ID), + stmts.push(Stmt { + id: ast::DUMMY_NODE_ID, + node: StmtKind::Expr(e), span: span }); } -- cgit 1.4.1-3-g733a5 From f0b21c2d1e21a6502098ff86773fd1b0bb39ce10 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 17 Jun 2016 02:34:18 +0000 Subject: Rename `ast::ExprKind::Again` -> `ast::ExprKind::Continue` --- src/librustc/hir/lowering.rs | 2 +- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_resolve/lib.rs | 2 +- src/libsyntax/ast.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/print/pprust.rs | 2 +- src/libsyntax/visit.rs | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 1387bc876e0..70de40e17b3 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1210,7 +1210,7 @@ impl<'a> LoweringContext<'a> { hir::ExprPath(hir_qself, self.lower_path(path)) } ExprKind::Break(opt_ident) => hir::ExprBreak(self.lower_opt_sp_ident(opt_ident)), - ExprKind::Again(opt_ident) => hir::ExprAgain(self.lower_opt_sp_ident(opt_ident)), + ExprKind::Continue(opt_ident) => hir::ExprAgain(self.lower_opt_sp_ident(opt_ident)), ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| self.lower_expr(x))), ExprKind::InlineAsm(InlineAsm { ref inputs, diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 919c717f888..199f0a4e9d5 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -73,7 +73,7 @@ impl<'a, 'v> Visitor<'v> for AstValidator<'a> { match expr.node { ExprKind::While(_, _, Some(ident)) | ExprKind::Loop(_, Some(ident)) | ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) | - ExprKind::Break(Some(ident)) | ExprKind::Again(Some(ident)) => { + ExprKind::Break(Some(ident)) | ExprKind::Continue(Some(ident)) => { self.check_label(ident.node, ident.span, expr.id); } _ => {} diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 377863b016d..1e527cac953 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2988,7 +2988,7 @@ impl<'a> Resolver<'a> { }) } - ExprKind::Break(Some(label)) | ExprKind::Again(Some(label)) => { + ExprKind::Break(Some(label)) | ExprKind::Continue(Some(label)) => { match self.search_label(mtwt::resolve(label.node)) { None => { self.record_def(expr.id, err_path_resolution()); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a3d2ba4d6fc..e55c2645e6e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1020,7 +1020,7 @@ pub enum ExprKind { /// A `break`, with an optional label to break Break(Option), /// A `continue`, with an optional label - Again(Option), + Continue(Option), /// A `return`, with an optional value to be returned Ret(Option>), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 7ca10568291..a9d89c9b55c 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1238,7 +1238,7 @@ pub fn noop_fold_expr(Expr {id, node, span, attrs}: Expr, folder: &mu respan(folder.new_span(label.span), folder.fold_ident(label.node))) ), - ExprKind::Again(opt_ident) => ExprKind::Again(opt_ident.map(|label| + ExprKind::Continue(opt_ident) => ExprKind::Continue(opt_ident.map(|label| respan(folder.new_span(label.span), folder.fold_ident(label.node))) ), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e74c30276ff..a3fbc3da955 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2285,14 +2285,14 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Continue) { let ex = if self.token.is_lifetime() { - let ex = ExprKind::Again(Some(Spanned{ + let ex = ExprKind::Continue(Some(Spanned{ node: self.get_lifetime(), span: self.span })); self.bump(); ex } else { - ExprKind::Again(None) + ExprKind::Continue(None) }; let hi = self.last_span.hi; return Ok(self.mk_expr(lo, hi, ex, attrs)); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 33de675767b..c257ea6a536 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2184,7 +2184,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); } } - ast::ExprKind::Again(opt_ident) => { + ast::ExprKind::Continue(opt_ident) => { try!(word(&mut self.s, "continue")); try!(space(&mut self.s)); if let Some(ident) = opt_ident { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 4152cb451ae..2498f33f873 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -755,7 +755,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } visitor.visit_path(path, expression.id) } - ExprKind::Break(ref opt_sp_ident) | ExprKind::Again(ref opt_sp_ident) => { + ExprKind::Break(ref opt_sp_ident) | ExprKind::Continue(ref opt_sp_ident) => { walk_opt_sp_ident(visitor, opt_sp_ident); } ExprKind::Ret(ref optional_expression) => { -- cgit 1.4.1-3-g733a5