Move condition out of maybe_recover_from_question_mark
.
This commit is contained in:
parent
1b422451ae
commit
a148a32fdc
2 changed files with 6 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
use super::pat::Expected;
|
use super::pat::Expected;
|
||||||
use super::ty::{AllowPlus, RecoverQuestionMark};
|
use super::ty::AllowPlus;
|
||||||
use super::{
|
use super::{
|
||||||
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
|
BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions,
|
||||||
SemiColonMode, SeqSep, TokenExpectType, TokenType,
|
SemiColonMode, SeqSep, TokenExpectType, TokenType,
|
||||||
|
@ -1248,14 +1248,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Swift lets users write `Ty?` to mean `Option<Ty>`. Parse the construct and recover from it.
|
/// Swift lets users write `Ty?` to mean `Option<Ty>`. Parse the construct and recover from it.
|
||||||
pub(super) fn maybe_recover_from_question_mark(
|
pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty> {
|
||||||
&mut self,
|
|
||||||
ty: P<Ty>,
|
|
||||||
recover_question_mark: RecoverQuestionMark,
|
|
||||||
) -> P<Ty> {
|
|
||||||
if let RecoverQuestionMark::No = recover_question_mark {
|
|
||||||
return ty;
|
|
||||||
}
|
|
||||||
if self.token == token::Question {
|
if self.token == token::Question {
|
||||||
self.bump();
|
self.bump();
|
||||||
self.struct_span_err(self.prev_token.span, "invalid `?` in type")
|
self.struct_span_err(self.prev_token.span, "invalid `?` in type")
|
||||||
|
|
|
@ -312,12 +312,14 @@ impl<'a> Parser<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let span = lo.to(self.prev_token.span);
|
let span = lo.to(self.prev_token.span);
|
||||||
let ty = self.mk_ty(span, kind);
|
let mut ty = self.mk_ty(span, kind);
|
||||||
|
|
||||||
// Try to recover from use of `+` with incorrect priority.
|
// Try to recover from use of `+` with incorrect priority.
|
||||||
self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty);
|
self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &ty);
|
||||||
self.maybe_recover_from_bad_type_plus(allow_plus, &ty)?;
|
self.maybe_recover_from_bad_type_plus(allow_plus, &ty)?;
|
||||||
let ty = self.maybe_recover_from_question_mark(ty, recover_question_mark);
|
if let RecoverQuestionMark::Yes = recover_question_mark {
|
||||||
|
ty = self.maybe_recover_from_question_mark(ty);
|
||||||
|
}
|
||||||
if allow_qpath_recovery { self.maybe_recover_from_bad_qpath(ty) } else { Ok(ty) }
|
if allow_qpath_recovery { self.maybe_recover_from_bad_qpath(ty) } else { Ok(ty) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue