From d4347ed6786d2f37218af1a4c112bf1d66500c02 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 19 May 2022 16:04:35 +1000 Subject: Move condition out of `maybe_recover_colon_colon_in_pat_typo`. --- compiler/rustc_parse/src/parser/diagnostics.rs | 7 +++---- compiler/rustc_parse/src/parser/pat.rs | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index c58b43de1b8..dc02a22b769 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1,7 +1,7 @@ use super::pat::Expected; use super::{ - BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions, - SemiColonMode, SeqSep, TokenExpectType, TokenType, + BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverComma, Restrictions, SemiColonMode, + SeqSep, TokenExpectType, TokenType, }; use crate::lexer::UnmatchedBrace; @@ -2444,10 +2444,9 @@ impl<'a> Parser<'a> { crate fn maybe_recover_colon_colon_in_pat_typo( &mut self, mut first_pat: P, - ra: RecoverColon, expected: Expected, ) -> P { - if RecoverColon::Yes != ra || token::Colon != self.token.kind { + if token::Colon != self.token.kind { return first_pat; } if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..)) diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index d521db7a058..aec3f269956 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -100,7 +100,7 @@ impl<'a> Parser<'a> { }; // Parse the first pattern (`p_0`). - let first_pat = self.parse_pat_no_top_alt(expected)?; + let mut first_pat = self.parse_pat_no_top_alt(expected)?; self.maybe_recover_unexpected_comma(first_pat.span, rc, rt)?; // If the next token is not a `|`, @@ -111,7 +111,9 @@ impl<'a> Parser<'a> { // This complicated procedure is done purely for diagnostics UX. // Check if the user wrote `foo:bar` instead of `foo::bar`. - let first_pat = self.maybe_recover_colon_colon_in_pat_typo(first_pat, ra, expected); + if ra == RecoverColon::Yes { + first_pat = self.maybe_recover_colon_colon_in_pat_typo(first_pat, expected); + } if let Some(leading_vert_span) = leading_vert_span { // If there was a leading vert, treat this as an or-pattern. This improves -- cgit 1.4.1-3-g733a5