Move condition out of maybe_report_ambiguous_plus and maybe_recover_from_bad_type_plus.

This commit is contained in:
Nicholas Nethercote 2022-05-19 15:59:52 +10:00
parent a148a32fdc
commit 7a37e0c2ff
2 changed files with 9 additions and 16 deletions

View File

@ -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(());
}

View File

@ -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);
}