Skip to content

Commit 7a37e0c

Browse files
committed
Move condition out of maybe_report_ambiguous_plus and maybe_recover_from_bad_type_plus.
1 parent a148a32 commit 7a37e0c

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::pat::Expected;
2-
use super::ty::AllowPlus;
32
use super::{
43
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
54
SemiColonMode, SeqSep, TokenExpectType, TokenType,
@@ -1236,13 +1235,8 @@ impl<'a> Parser<'a> {
12361235
}
12371236
}
12381237

1239-
pub(super) fn maybe_report_ambiguous_plus(
1240-
&mut self,
1241-
allow_plus: AllowPlus,
1242-
impl_dyn_multi: bool,
1243-
ty: &Ty,
1244-
) {
1245-
if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi {
1238+
pub(super) fn maybe_report_ambiguous_plus(&mut self, impl_dyn_multi: bool, ty: &Ty) {
1239+
if impl_dyn_multi {
12461240
self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(&ty), span: ty.span });
12471241
}
12481242
}
@@ -1268,13 +1262,9 @@ impl<'a> Parser<'a> {
12681262
}
12691263
}
12701264

1271-
pub(super) fn maybe_recover_from_bad_type_plus(
1272-
&mut self,
1273-
allow_plus: AllowPlus,
1274-
ty: &Ty,
1275-
) -> PResult<'a, ()> {
1265+
pub(super) fn maybe_recover_from_bad_type_plus(&mut self, ty: &Ty) -> PResult<'a, ()> {
12761266
// Do not add `+` to expected tokens.
1277-
if matches!(allow_plus, AllowPlus::No) || !self.token.is_like_plus() {
1267+
if !self.token.is_like_plus() {
12781268
return Ok(());
12791269
}
12801270

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,11 @@ impl<'a> Parser<'a> {
315315
let mut ty = self.mk_ty(span, kind);
316316

317317
// Try to recover from use of `+` with incorrect priority.
318-
self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty);
319-
self.maybe_recover_from_bad_type_plus(allow_plus, &ty)?;
318+
if matches!(allow_plus, AllowPlus::Yes) {
319+
self.maybe_recover_from_bad_type_plus(&ty)?;
320+
} else {
321+
self.maybe_report_ambiguous_plus(impl_dyn_multi, &ty);
322+
}
320323
if let RecoverQuestionMark::Yes = recover_question_mark {
321324
ty = self.maybe_recover_from_question_mark(ty);
322325
}

0 commit comments

Comments
 (0)