diff options
| author | bors <bors@rust-lang.org> | 2022-06-13 23:36:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-13 23:36:51 +0000 |
| commit | 3bdec3c8abdc48e46715d7b14b764af28da1cee3 (patch) | |
| tree | b72fb84b835e64cc9e6de4c5fc71491b96711fb0 /compiler/rustc_parse/src/parser/path.rs | |
| parent | ca122c7ebb3ab50149c9d3d24ddb59c252b32272 (diff) | |
| parent | aa71be1b39d7b672414c622093e906e81aa06351 (diff) | |
| download | rust-3bdec3c8abdc48e46715d7b14b764af28da1cee3.tar.gz rust-3bdec3c8abdc48e46715d7b14b764af28da1cee3.zip | |
Auto merge of #98075 - JohnTitor:rollup-nqwodnk, r=JohnTitor
Rollup of 4 pull requests Successful merges: - #95211 (Improve parser diagnostics) - #95243 (Add Apple WatchOS compile targets) - #97385 (Add WIP stable MIR crate) - #97508 (Harden bad placeholder checks on statics/consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser/path.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index da46af60f72..5cf1758c31f 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -2,7 +2,7 @@ use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign}; use super::{Parser, Restrictions, TokenType}; use crate::maybe_whole; use rustc_ast::ptr::P; -use rustc_ast::token::{self, Delimiter, Token}; +use rustc_ast::token::{self, Delimiter, Token, TokenKind}; use rustc_ast::{ self as ast, AngleBracketedArg, AngleBracketedArgs, AnonConst, AssocConstraint, AssocConstraintKind, BlockCheckMode, GenericArg, GenericArgs, Generics, ParenthesizedArgs, @@ -96,7 +96,7 @@ impl<'a> Parser<'a> { /// ^ help: use double colon /// ``` fn recover_colon_before_qpath_proj(&mut self) -> bool { - if self.token.kind != token::Colon + if !self.check_noexpect(&TokenKind::Colon) || self.look_ahead(1, |t| !t.is_ident() || t.is_reserved_ident()) { return false; @@ -478,7 +478,7 @@ impl<'a> Parser<'a> { while let Some(arg) = self.parse_angle_arg(ty_generics)? { args.push(arg); if !self.eat(&token::Comma) { - if self.token.kind == token::Semi + if self.check_noexpect(&TokenKind::Semi) && self.look_ahead(1, |t| t.is_ident() || t.is_lifetime()) { // Add `>` to the list of expected tokens. @@ -517,7 +517,11 @@ impl<'a> Parser<'a> { let arg = self.parse_generic_arg(ty_generics)?; match arg { Some(arg) => { - if self.check(&token::Colon) | self.check(&token::Eq) { + // we are using noexpect here because we first want to find out if either `=` or `:` + // is present and then use that info to push the other token onto the tokens list + let separated = + self.check_noexpect(&token::Colon) || self.check_noexpect(&token::Eq); + if separated && (self.check(&token::Colon) | self.check(&token::Eq)) { let arg_span = arg.span(); let (binder, ident, gen_args) = match self.get_ident_from_generic_arg(&arg) { Ok(ident_gen_args) => ident_gen_args, @@ -553,6 +557,14 @@ impl<'a> Parser<'a> { AssocConstraint { id: ast::DUMMY_NODE_ID, ident, gen_args, kind, span }; Ok(Some(AngleBracketedArg::Constraint(constraint))) } else { + // we only want to suggest `:` and `=` in contexts where the previous token + // is an ident and the current token or the next token is an ident + if self.prev_token.is_ident() + && (self.token.is_ident() || self.look_ahead(1, |token| token.is_ident())) + { + self.check(&token::Colon); + self.check(&token::Eq); + } Ok(Some(AngleBracketedArg::Arg(arg))) } } |
