about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/ty.rs
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-06-02 06:44:27 +0900
committerGitHub <noreply@github.com>2022-06-02 06:44:27 +0900
commitd126de111bdf74cbcd20f043139af4f1e57b3cba (patch)
treec4898d93146c2adc40885e5185086030dd450160 /compiler/rustc_parse/src/parser/ty.rs
parent9fc3fc3a0cf63b9be317f92b84dcaa9b20162279 (diff)
parent7b6c5c76a5b4b1a7676f7792c92939c4a7e85f5b (diff)
downloadrust-d126de111bdf74cbcd20f043139af4f1e57b3cba.tar.gz
rust-d126de111bdf74cbcd20f043139af4f1e57b3cba.zip
Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebank
Move conditions out of recover/report functions.

`Parser` has six recover/report functions that are passed a boolean, and
nothing is done if the boolean has a particular value.

This PR moves the tests outside the functions. This has the following effects.
- The number of lines of code goes down.
- Some `use` items become shorter.
- Avoids the strangeness whereby 11 out of 12 calls to
  `maybe_recover_from_bad_qpath` pass `true` as the second argument.
- Makes it clear at the call site that only one of
  `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be
  run.

r? `@estebank`
Diffstat (limited to 'compiler/rustc_parse/src/parser/ty.rs')
-rw-r--r--compiler/rustc_parse/src/parser/ty.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs
index fb3f5eb3f9f..dee025cfd3c 100644
--- a/compiler/rustc_parse/src/parser/ty.rs
+++ b/compiler/rustc_parse/src/parser/ty.rs
@@ -312,13 +312,18 @@ 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);
-        self.maybe_recover_from_bad_qpath(ty, allow_qpath_recovery)
+        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);
+        }
+        if allow_qpath_recovery { self.maybe_recover_from_bad_qpath(ty) } else { Ok(ty) }
     }
 
     /// Parses either: