]> git.lizzy.rs Git - rust.git/commitdiff
Improved try_macro_suggestion
authorDuddino <rezziandrea106@gmail.com>
Fri, 17 Apr 2020 17:10:29 +0000 (19:10 +0200)
committerDuddino <rezziandrea106@gmail.com>
Fri, 17 Apr 2020 17:10:29 +0000 (19:10 +0200)
src/librustc_parse/parser/diagnostics.rs
src/librustc_parse/parser/expr.rs

index a79e1a44e96ba9b67f9d8022abdf7835bee25df6..e2b8da64dc76c86bcfbe06f1a86513978e49630d 100644 (file)
@@ -1054,7 +1054,7 @@ pub(super) fn recover_from_await_method_call(&mut self) {
         }
     }
 
-    pub(super) fn try_macro_suggestion(&mut self) -> DiagnosticBuilder<'a> {
+    pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> {
         let is_try = self.token.is_keyword(kw::Try);
         let is_questionmark = self.look_ahead(1, |t| t == &token::Not); //check for !
         let is_open = self.look_ahead(2, |t| t == &token::OpenDelim(token::Paren)); //check for (
@@ -1082,9 +1082,10 @@ pub(super) fn try_macro_suggestion(&mut self) -> DiagnosticBuilder<'a> {
                 //if the try! macro is empty, it isn't possible to suggest something using the `?` operator
                 err.span_suggestion(lo.shrink_to_lo(), "you can still access the deprecated `try!()` macro using the \"raw identifier\" syntax", "r#".to_string(), Applicability::MachineApplicable);
             }
-            err
+            err.emit();
+            Ok(self.mk_expr_err(lo.to(hi)))
         } else {
-            self.expected_expression_found() // The user isn't trying to invoke the try! macro
+            Err(self.expected_expression_found()) // The user isn't trying to invoke the try! macro
         }
     }
 
index ef98aab9c9f9033e3f26d129bbd332ccf0440bfe..986f5410e26c0b454d83fa098d7a6f1a62185401 100644 (file)
@@ -1006,7 +1006,7 @@ fn parse_lit_expr(&mut self, attrs: AttrVec) -> PResult<'a, P<Expr>> {
                 let expr = self.mk_expr(lo.to(self.prev_token.span), ExprKind::Lit(literal), attrs);
                 self.maybe_recover_from_bad_qpath(expr, true)
             }
-            None => Err(self.try_macro_suggestion()),
+            None => self.try_macro_suggestion(),
         }
     }