Skip to content

Commit d4347ed

Browse files
committed
Move condition out of maybe_recover_colon_colon_in_pat_typo.
1 parent 7a37e0c commit d4347ed

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::pat::Expected;
22
use super::{
3-
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
4-
SemiColonMode, SeqSep, TokenExpectType, TokenType,
3+
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverComma, Restrictions, SemiColonMode,
4+
SeqSep, TokenExpectType, TokenType,
55
};
66

77
use crate::lexer::UnmatchedBrace;
@@ -2444,10 +2444,9 @@ impl<'a> Parser<'a> {
24442444
crate fn maybe_recover_colon_colon_in_pat_typo(
24452445
&mut self,
24462446
mut first_pat: P<Pat>,
2447-
ra: RecoverColon,
24482447
expected: Expected,
24492448
) -> P<Pat> {
2450-
if RecoverColon::Yes != ra || token::Colon != self.token.kind {
2449+
if token::Colon != self.token.kind {
24512450
return first_pat;
24522451
}
24532452
if !matches!(first_pat.kind, PatKind::Ident(_, _, None) | PatKind::Path(..))

compiler/rustc_parse/src/parser/pat.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a> Parser<'a> {
100100
};
101101

102102
// Parse the first pattern (`p_0`).
103-
let first_pat = self.parse_pat_no_top_alt(expected)?;
103+
let mut first_pat = self.parse_pat_no_top_alt(expected)?;
104104
self.maybe_recover_unexpected_comma(first_pat.span, rc, rt)?;
105105

106106
// If the next token is not a `|`,
@@ -111,7 +111,9 @@ impl<'a> Parser<'a> {
111111
// This complicated procedure is done purely for diagnostics UX.
112112

113113
// Check if the user wrote `foo:bar` instead of `foo::bar`.
114-
let first_pat = self.maybe_recover_colon_colon_in_pat_typo(first_pat, ra, expected);
114+
if ra == RecoverColon::Yes {
115+
first_pat = self.maybe_recover_colon_colon_in_pat_typo(first_pat, expected);
116+
}
115117

116118
if let Some(leading_vert_span) = leading_vert_span {
117119
// If there was a leading vert, treat this as an or-pattern. This improves

0 commit comments

Comments
 (0)