diff options
| author | bors <bors@rust-lang.org> | 2018-01-26 17:41:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-01-26 17:41:36 +0000 |
| commit | bacb5c58dfdde7c35e99b2b0d8171238cc33cf6c (patch) | |
| tree | a4a44364f143350bb7262ca8e63612e2ee71f6ed /src/libsyntax/parse | |
| parent | a97cd17f5d71fb4ec362f4fbd79373a6e7ed7b82 (diff) | |
| parent | a06d333a148f6c620044a765f47497f1ed1e4dde (diff) | |
| download | rust-bacb5c58dfdde7c35e99b2b0d8171238cc33cf6c.tar.gz rust-bacb5c58dfdde7c35e99b2b0d8171238cc33cf6c.zip | |
Auto merge of #47748 - alexcrichton:rollup, r=alexcrichton
Rollup of 19 pull requests - Successful merges: #47415, #47437, #47439, #47453, #47460, #47502, #47529, #47600, #47607, #47618, #47626, #47656, #47668, #47696, #47701, #47705, #47710, #47711, #47719 - Failed merges: #47455, #47521
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 67 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 64 |
4 files changed, 59 insertions, 78 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 49362f07799..63aa5d28ce8 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -265,7 +265,7 @@ fn read_block_comment(rdr: &mut StringReader, while level > 0 { debug!("=== block comment level {}", level); if rdr.is_eof() { - panic!(rdr.fatal("unterminated block comment")); + rdr.fatal("unterminated block comment").raise(); } if rdr.ch_is('\n') { trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 9828995362a..b95c91548d0 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -90,7 +90,7 @@ impl<'a> StringReader<'a> { Ok(tok) => tok, Err(_) => { self.emit_fatal_errors(); - panic!(FatalError); + FatalError.raise(); } } } @@ -191,7 +191,7 @@ impl<'a> StringReader<'a> { let mut sr = StringReader::new_raw(sess, filemap); if sr.advance_token().is_err() { sr.emit_fatal_errors(); - panic!(FatalError); + FatalError.raise(); } sr } @@ -216,7 +216,7 @@ impl<'a> StringReader<'a> { if sr.advance_token().is_err() { sr.emit_fatal_errors(); - panic!(FatalError); + FatalError.raise(); } sr } @@ -647,7 +647,7 @@ impl<'a> StringReader<'a> { "unterminated block comment" }; let last_bpos = self.pos; - panic!(self.fatal_span_(start_bpos, last_bpos, msg)); + self.fatal_span_(start_bpos, last_bpos, msg).raise(); } let n = self.ch.unwrap(); match n { @@ -808,9 +808,9 @@ impl<'a> StringReader<'a> { for _ in 0..n_digits { if self.is_eof() { let last_bpos = self.pos; - panic!(self.fatal_span_(start_bpos, - last_bpos, - "unterminated numeric character escape")); + self.fatal_span_(start_bpos, + last_bpos, + "unterminated numeric character escape").raise(); } if self.ch_is(delim) { let last_bpos = self.pos; @@ -1025,9 +1025,9 @@ impl<'a> StringReader<'a> { } }, None => { - panic!(self.fatal_span_(start_bpos, - self.pos, - "unterminated unicode escape (found EOF)")); + self.fatal_span_(start_bpos, + self.pos, + "unterminated unicode escape (found EOF)").raise(); } } self.bump(); @@ -1283,9 +1283,9 @@ impl<'a> StringReader<'a> { // lifetimes shouldn't end with a single quote // if we find one, then this is an invalid character literal if self.ch_is('\'') { - panic!(self.fatal_span_verbose( - start_with_quote, self.next_pos, - String::from("character literal may only contain one codepoint"))); + self.fatal_span_verbose(start_with_quote, self.next_pos, + String::from("character literal may only contain one codepoint")) + .raise(); } @@ -1332,9 +1332,8 @@ impl<'a> StringReader<'a> { break; } } - panic!(self.fatal_span_verbose( - start_with_quote, pos, - String::from("character literal may only contain one codepoint"))); + self.fatal_span_verbose(start_with_quote, pos, + String::from("character literal may only contain one codepoint")).raise(); } let id = if valid { @@ -1364,9 +1363,9 @@ impl<'a> StringReader<'a> { while !self.ch_is('"') { if self.is_eof() { let last_bpos = self.pos; - panic!(self.fatal_span_(start_bpos, - last_bpos, - "unterminated double quote string")); + self.fatal_span_(start_bpos, + last_bpos, + "unterminated double quote string").raise(); } let ch_start = self.pos; @@ -1399,15 +1398,15 @@ impl<'a> StringReader<'a> { if self.is_eof() { let last_bpos = self.pos; - panic!(self.fatal_span_(start_bpos, last_bpos, "unterminated raw string")); + self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise(); } else if !self.ch_is('"') { let last_bpos = self.pos; let curr_char = self.ch.unwrap(); - panic!(self.fatal_span_char(start_bpos, - last_bpos, - "found invalid character; only `#` is allowed \ - in raw string delimitation", - curr_char)); + self.fatal_span_char(start_bpos, + last_bpos, + "found invalid character; only `#` is allowed \ + in raw string delimitation", + curr_char).raise(); } self.bump(); let content_start_bpos = self.pos; @@ -1416,7 +1415,7 @@ impl<'a> StringReader<'a> { 'outer: loop { if self.is_eof() { let last_bpos = self.pos; - panic!(self.fatal_span_(start_bpos, last_bpos, "unterminated raw string")); + self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise(); } // if self.ch_is('"') { // content_end_bpos = self.pos; @@ -1573,9 +1572,9 @@ impl<'a> StringReader<'a> { // character before position `start` are an // ascii single quote and ascii 'b'. let pos = self.pos; - panic!(self.fatal_span_verbose(start - BytePos(2), - pos, - "unterminated byte constant".to_string())); + self.fatal_span_verbose(start - BytePos(2), + pos, + "unterminated byte constant".to_string()).raise(); } let id = if valid { @@ -1599,7 +1598,7 @@ impl<'a> StringReader<'a> { while !self.ch_is('"') { if self.is_eof() { let pos = self.pos; - panic!(self.fatal_span_(start, pos, "unterminated double quote byte string")); + self.fatal_span_(start, pos, "unterminated double quote byte string").raise(); } let ch_start = self.pos; @@ -1631,15 +1630,15 @@ impl<'a> StringReader<'a> { if self.is_eof() { let pos = self.pos; - panic!(self.fatal_span_(start_bpos, pos, "unterminated raw string")); + self.fatal_span_(start_bpos, pos, "unterminated raw string").raise(); } else if !self.ch_is('"') { let pos = self.pos; let ch = self.ch.unwrap(); - panic!(self.fatal_span_char(start_bpos, + self.fatal_span_char(start_bpos, pos, "found invalid character; only `#` is allowed in raw \ string delimitation", - ch)); + ch).raise(); } self.bump(); let content_start_bpos = self.pos; @@ -1648,7 +1647,7 @@ impl<'a> StringReader<'a> { match self.ch { None => { let pos = self.pos; - panic!(self.fatal_span_(start_bpos, pos, "unterminated raw string")) + self.fatal_span_(start_bpos, pos, "unterminated raw string").raise() } Some('"') => { content_end_bpos = self.pos; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a9b1e4aaa60..b671f81c2a8 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -212,8 +212,8 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>) Err(e) => { let msg = format!("couldn't read {:?}: {}", path.display(), e); match spanopt { - Some(sp) => panic!(sess.span_diagnostic.span_fatal(sp, &msg)), - None => panic!(sess.span_diagnostic.fatal(&msg)) + Some(sp) => sess.span_diagnostic.span_fatal(sp, &msg).raise(), + None => sess.span_diagnostic.fatal(&msg).raise() } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8213d604b91..d393cab4718 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -23,7 +23,7 @@ use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::GenericParam; use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; -use ast::{Lifetime, LifetimeDef, Lit, LitKind, UintTy}; +use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind, UintTy}; use ast::Local; use ast::MacStmtStyle; use ast::Mac_; @@ -1325,15 +1325,17 @@ impl<'a> Parser<'a> { self.check_keyword(keywords::Extern) } - fn get_label(&mut self) -> ast::Ident { - match self.token { + fn eat_label(&mut self) -> Option<Label> { + let ident = match self.token { token::Lifetime(ref ident) => *ident, token::Interpolated(ref nt) => match nt.0 { token::NtLifetime(lifetime) => lifetime.ident, - _ => self.bug("not a lifetime"), + _ => return None, }, - _ => self.bug("not a lifetime"), - } + _ => return None, + }; + self.bump(); + Some(Label { ident, span: self.prev_span }) } /// parse a TyKind::BareFn type: @@ -2317,11 +2319,8 @@ impl<'a> Parser<'a> { let lo = self.prev_span; return self.parse_while_expr(None, lo, attrs); } - if self.token.is_lifetime() { - let label = Spanned { node: self.get_label(), - span: self.span }; - let lo = self.span; - self.bump(); + if let Some(label) = self.eat_label() { + let lo = label.span; self.expect(&token::Colon)?; if self.eat_keyword(keywords::While) { return self.parse_while_expr(Some(label), lo, attrs) @@ -2339,16 +2338,8 @@ impl<'a> Parser<'a> { return self.parse_loop_expr(None, lo, attrs); } if self.eat_keyword(keywords::Continue) { - let ex = if self.token.is_lifetime() { - let ex = ExprKind::Continue(Some(Spanned{ - node: self.get_label(), - span: self.span - })); - self.bump(); - ex - } else { - ExprKind::Continue(None) - }; + let label = self.eat_label(); + let ex = ExprKind::Continue(label); let hi = self.prev_span; return Ok(self.mk_expr(lo.to(hi), ex, attrs)); } @@ -2376,16 +2367,7 @@ impl<'a> Parser<'a> { ex = ExprKind::Ret(None); } } else if self.eat_keyword(keywords::Break) { - let lt = if self.token.is_lifetime() { - let spanned_lt = Spanned { - node: self.get_label(), - span: self.span - }; - self.bump(); - Some(spanned_lt) - } else { - None - }; + let label = self.eat_label(); let e = if self.token.can_begin_expr() && !(self.token == token::OpenDelim(token::Brace) && self.restrictions.contains( @@ -2394,7 +2376,7 @@ impl<'a> Parser<'a> { } else { None }; - ex = ExprKind::Break(lt, e); + ex = ExprKind::Break(label, e); hi = self.prev_span; } else if self.eat_keyword(keywords::Yield) { if self.token.can_begin_expr() { @@ -3291,7 +3273,7 @@ impl<'a> Parser<'a> { } /// Parse a 'for' .. 'in' expression ('for' token already eaten) - pub fn parse_for_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, + pub fn parse_for_expr(&mut self, opt_label: Option<Label>, span_lo: Span, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> { // Parse: `for <src_pat> in <src_expr> <src_loop_block>` @@ -3309,25 +3291,25 @@ impl<'a> Parser<'a> { attrs.extend(iattrs); let hi = self.prev_span; - Ok(self.mk_expr(span_lo.to(hi), ExprKind::ForLoop(pat, expr, loop_block, opt_ident), attrs)) + Ok(self.mk_expr(span_lo.to(hi), ExprKind::ForLoop(pat, expr, loop_block, opt_label), attrs)) } /// Parse a 'while' or 'while let' expression ('while' token already eaten) - pub fn parse_while_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, + pub fn parse_while_expr(&mut self, opt_label: Option<Label>, span_lo: Span, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> { if self.token.is_keyword(keywords::Let) { - return self.parse_while_let_expr(opt_ident, span_lo, attrs); + return self.parse_while_let_expr(opt_label, span_lo, attrs); } let cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?; let (iattrs, body) = self.parse_inner_attrs_and_block()?; attrs.extend(iattrs); let span = span_lo.to(body.span); - return Ok(self.mk_expr(span, ExprKind::While(cond, body, opt_ident), attrs)); + return Ok(self.mk_expr(span, ExprKind::While(cond, body, opt_label), attrs)); } /// Parse a 'while let' expression ('while' token already eaten) - pub fn parse_while_let_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, + pub fn parse_while_let_expr(&mut self, opt_label: Option<Label>, span_lo: Span, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> { self.expect_keyword(keywords::Let)?; @@ -3337,17 +3319,17 @@ impl<'a> Parser<'a> { let (iattrs, body) = self.parse_inner_attrs_and_block()?; attrs.extend(iattrs); let span = span_lo.to(body.span); - return Ok(self.mk_expr(span, ExprKind::WhileLet(pat, expr, body, opt_ident), attrs)); + return Ok(self.mk_expr(span, ExprKind::WhileLet(pat, expr, body, opt_label), attrs)); } // parse `loop {...}`, `loop` token already eaten - pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::SpannedIdent>, + pub fn parse_loop_expr(&mut self, opt_label: Option<Label>, span_lo: Span, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> { let (iattrs, body) = self.parse_inner_attrs_and_block()?; attrs.extend(iattrs); let span = span_lo.to(body.span); - Ok(self.mk_expr(span, ExprKind::Loop(body, opt_ident), attrs)) + Ok(self.mk_expr(span, ExprKind::Loop(body, opt_label), attrs)) } /// Parse a `do catch {...}` expression (`do catch` token already eaten) |
