diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-05-19 15:52:52 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-05-19 16:13:48 +1000 |
| commit | a148a32fdc3f3767487d54147edbbe2c225c4fbf (patch) | |
| tree | e84a0b0dd62f70153c36d97bb4dda5225831010b /compiler/rustc_parse/src | |
| parent | 1b422451aeb61b57e2843d379d83d710ea50b9d9 (diff) | |
| download | rust-a148a32fdc3f3767487d54147edbbe2c225c4fbf.tar.gz rust-a148a32fdc3f3767487d54147edbbe2c225c4fbf.zip | |
Move condition out of `maybe_recover_from_question_mark`.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 6 |
2 files changed, 6 insertions, 11 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 51db52fbf40..3ed19219fa4 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1,5 +1,5 @@ use super::pat::Expected; -use super::ty::{AllowPlus, RecoverQuestionMark}; +use super::ty::AllowPlus; use super::{ BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverColon, RecoverComma, Restrictions, 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. - pub(super) fn maybe_recover_from_question_mark( - &mut self, - ty: P<Ty>, - recover_question_mark: RecoverQuestionMark, - ) -> P<Ty> { - if let RecoverQuestionMark::No = recover_question_mark { - return ty; - } + pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty> { if self.token == token::Question { self.bump(); self.struct_span_err(self.prev_token.span, "invalid `?` in type") diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index fea12178879..6c8eb8b39d1 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -312,12 +312,14 @@ impl<'a> Parser<'a> { }; 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. self.maybe_report_ambiguous_plus(allow_plus, impl_dyn_multi, &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) } } |
