Skip to content

Commit 7b6c5c7

Browse files
committed
Move condition out of maybe_recover_unexpected_comma.
1 parent d4347ed commit 7b6c5c7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-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, RecoverComma, Restrictions, SemiColonMode,
4-
SeqSep, TokenExpectType, TokenType,
3+
BlockMode, CommaRecoveryMode, Parser, PathStyle, Restrictions, SemiColonMode, SeqSep,
4+
TokenExpectType, TokenType,
55
};
66

77
use crate::lexer::UnmatchedBrace;
@@ -2580,10 +2580,9 @@ impl<'a> Parser<'a> {
25802580
crate fn maybe_recover_unexpected_comma(
25812581
&mut self,
25822582
lo: Span,
2583-
rc: RecoverComma,
25842583
rt: CommaRecoveryMode,
25852584
) -> PResult<'a, ()> {
2586-
if rc == RecoverComma::No || self.token != token::Comma {
2585+
if self.token != token::Comma {
25872586
return Ok(());
25882587
}
25892588

compiler/rustc_parse/src/parser/pat.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ impl<'a> Parser<'a> {
101101

102102
// Parse the first pattern (`p_0`).
103103
let mut first_pat = self.parse_pat_no_top_alt(expected)?;
104-
self.maybe_recover_unexpected_comma(first_pat.span, rc, rt)?;
104+
if rc == RecoverComma::Yes {
105+
self.maybe_recover_unexpected_comma(first_pat.span, rt)?;
106+
}
105107

106108
// If the next token is not a `|`,
107109
// this is not an or-pattern and we should exit here.
@@ -141,7 +143,9 @@ impl<'a> Parser<'a> {
141143
err.span_label(lo, WHILE_PARSING_OR_MSG);
142144
err
143145
})?;
144-
self.maybe_recover_unexpected_comma(pat.span, rc, rt)?;
146+
if rc == RecoverComma::Yes {
147+
self.maybe_recover_unexpected_comma(pat.span, rt)?;
148+
}
145149
pats.push(pat);
146150
}
147151
let or_pattern_span = lo.to(self.prev_token.span);

0 commit comments

Comments
 (0)