diff options
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 7 |
2 files changed, 9 insertions, 16 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 3ed19219fa4..c58b43de1b8 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1,5 +1,4 @@ use super::pat::Expected; -use super::ty::AllowPlus; use super::{ BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions, SemiColonMode, SeqSep, TokenExpectType, TokenType, @@ -1236,13 +1235,8 @@ impl<'a> Parser<'a> { } } - pub(super) fn maybe_report_ambiguous_plus( - &mut self, - allow_plus: AllowPlus, - impl_dyn_multi: bool, - ty: &Ty, - ) { - if matches!(allow_plus, AllowPlus::No) && impl_dyn_multi { + pub(super) fn maybe_report_ambiguous_plus(&mut self, impl_dyn_multi: bool, ty: &Ty) { + if impl_dyn_multi { self.sess.emit_err(AmbiguousPlus { sum_ty: pprust::ty_to_string(&ty), span: ty.span }); } } @@ -1268,13 +1262,9 @@ impl<'a> Parser<'a> { } } - pub(super) fn maybe_recover_from_bad_type_plus( - &mut self, - allow_plus: AllowPlus, - ty: &Ty, - ) -> PResult<'a, ()> { + pub(super) fn maybe_recover_from_bad_type_plus(&mut self, ty: &Ty) -> PResult<'a, ()> { // Do not add `+` to expected tokens. - if matches!(allow_plus, AllowPlus::No) || !self.token.is_like_plus() { + if !self.token.is_like_plus() { return Ok(()); } diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 6c8eb8b39d1..708940c8aa8 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -315,8 +315,11 @@ impl<'a> Parser<'a> { let mut ty = self.mk_ty(span, kind); // Try to recover from use of `+` with incorrect priority. - self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty); - self.maybe_recover_from_bad_type_plus(allow_plus, &ty)?; + if matches!(allow_plus, AllowPlus::Yes) { + self.maybe_recover_from_bad_type_plus(&ty)?; + } else { + self.maybe_report_ambiguous_plus(impl_dyn_multi, &ty); + } if let RecoverQuestionMark::Yes = recover_question_mark { ty = self.maybe_recover_from_question_mark(ty); } |
