diff options
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/lexer/mod.rs | 22 | ||||
| -rw-r--r-- | src/librustc_parse/parser/diagnostics.rs | 2 | ||||
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 6 | ||||
| -rw-r--r-- | src/librustc_parse/parser/generics.rs | 9 | ||||
| -rw-r--r-- | src/librustc_parse/parser/mod.rs | 6 |
5 files changed, 34 insertions, 11 deletions
diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 7e59f06e44a..84b3335a0f6 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -191,7 +191,15 @@ impl<'a> StringReader<'a> { "unterminated block comment" }; let last_bpos = self.pos; - self.fatal_span_(start, last_bpos, msg).raise(); + self.sess + .span_diagnostic + .struct_span_fatal_with_code( + self.mk_sp(start, last_bpos), + msg, + error_code!(E0758), + ) + .emit(); + FatalError.raise(); } if is_doc_comment { @@ -317,7 +325,15 @@ impl<'a> StringReader<'a> { let (lit_kind, mode, prefix_len, postfix_len) = match kind { rustc_lexer::LiteralKind::Char { terminated } => { if !terminated { - self.fatal_span_(start, suffix_start, "unterminated character literal").raise() + self.sess + .span_diagnostic + .struct_span_fatal_with_code( + self.mk_sp(start, suffix_start), + "unterminated character literal", + error_code!(E0762), + ) + .emit(); + FatalError.raise(); } (token::Char, Mode::Char, 1, 1) // ' ' } @@ -393,7 +409,7 @@ impl<'a> StringReader<'a> { let content_end = suffix_start - BytePos(postfix_len); let id = self.symbol_from_to(content_start, content_end); self.validate_literal_escape(mode, content_start, content_end); - return (lit_kind, id); + (lit_kind, id) } pub fn pos(&self) -> BytePos { diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index 660a63841bc..8792605c08d 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -936,7 +936,7 @@ impl<'a> Parser<'a> { } else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) { // The current token is in the same line as the prior token, not recoverable. } else if [token::Comma, token::Colon].contains(&self.token.kind) - && &self.prev_token.kind == &token::CloseDelim(token::Paren) + && self.prev_token.kind == token::CloseDelim(token::Paren) { // Likely typo: The current token is on a new line and is expected to be // `.`, `;`, `?`, or an operator after a close delimiter token. diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index e0c37284839..49a5c880176 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -639,7 +639,7 @@ impl<'a> Parser<'a> { ExprKind::Index(_, _) => "indexing", ExprKind::Try(_) => "?", ExprKind::Field(_, _) => "a field access", - ExprKind::MethodCall(_, _) => "a method call", + ExprKind::MethodCall(_, _, _) => "a method call", ExprKind::Call(_, _) => "a function call", ExprKind::Await(_) => "`.await`", ExprKind::Err => return Ok(with_postfix), @@ -865,6 +865,7 @@ impl<'a> Parser<'a> { return self.mk_await_expr(self_arg, lo); } + let fn_span_lo = self.token.span; let segment = self.parse_path_segment(PathStyle::Expr)?; self.check_trailing_angle_brackets(&segment, token::OpenDelim(token::Paren)); @@ -873,8 +874,9 @@ impl<'a> Parser<'a> { let mut args = self.parse_paren_expr_seq()?; args.insert(0, self_arg); + let fn_span = fn_span_lo.to(self.prev_token.span); let span = lo.to(self.prev_token.span); - Ok(self.mk_expr(span, ExprKind::MethodCall(segment, args), AttrVec::new())) + Ok(self.mk_expr(span, ExprKind::MethodCall(segment, args, fn_span), AttrVec::new())) } else { // Field access `expr.f` if let Some(args) = segment.args { diff --git a/src/librustc_parse/parser/generics.rs b/src/librustc_parse/parser/generics.rs index 8e8f864728c..04b64d93c70 100644 --- a/src/librustc_parse/parser/generics.rs +++ b/src/librustc_parse/parser/generics.rs @@ -157,6 +157,7 @@ impl<'a> Parser<'a> { Ok(ast::Generics { params, where_clause: WhereClause { + has_where_token: false, predicates: Vec::new(), span: self.prev_token.span.shrink_to_hi(), }, @@ -170,12 +171,16 @@ impl<'a> Parser<'a> { /// where T : Trait<U, V> + 'b, 'a : 'b /// ``` pub(super) fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> { - let mut where_clause = - WhereClause { predicates: Vec::new(), span: self.prev_token.span.shrink_to_hi() }; + let mut where_clause = WhereClause { + has_where_token: false, + predicates: Vec::new(), + span: self.prev_token.span.shrink_to_hi(), + }; if !self.eat_keyword(kw::Where) { return Ok(where_clause); } + where_clause.has_where_token = true; let lo = self.prev_token.span; // We are considering adding generics to the `where` keyword as an alternative higher-rank diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index c00b6084829..47ae92c48bd 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -193,7 +193,7 @@ impl TokenCursor { tree, self.stack.len() ); - collecting.buf.push(tree.clone().into()) + collecting.buf.push(tree.clone()) } } @@ -675,7 +675,7 @@ impl<'a> Parser<'a> { // If this was a missing `@` in a binding pattern // bail with a suggestion // https://github.com/rust-lang/rust/issues/72373 - if self.prev_token.is_ident() && &self.token.kind == &token::DotDot { + if self.prev_token.is_ident() && self.token.kind == token::DotDot { let msg = format!( "if you meant to bind the contents of \ the rest of the array pattern into `{}`, use `@`", @@ -1193,7 +1193,7 @@ impl<'a> Parser<'a> { let mut collected_tokens = if let Some(collecting) = self.token_cursor.collecting.take() { collecting.buf } else { - let msg = format!("our vector went away?"); + let msg = "our vector went away?"; debug!("collect_tokens: {}", msg); self.sess.span_diagnostic.delay_span_bug(self.token.span, &msg); // This can happen due to a bad interaction of two unrelated recovery mechanisms |
