about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorDuddino <rezziandrea106@gmail.com>2020-04-17 19:10:29 +0200
committerDuddino <rezziandrea106@gmail.com>2020-04-17 19:10:29 +0200
commit67128f1e4a880dd8c364f38e919bac19afb08282 (patch)
treec9913ebcfad7846b48e7b85727c76b31a64da187 /src
parentd3f5c274c6990db429b934212f1d9efd101104e3 (diff)
downloadrust-67128f1e4a880dd8c364f38e919bac19afb08282.tar.gz
rust-67128f1e4a880dd8c364f38e919bac19afb08282.zip
Improved try_macro_suggestion
Diffstat (limited to 'src')
-rw-r--r--src/librustc_parse/parser/diagnostics.rs7
-rw-r--r--src/librustc_parse/parser/expr.rs2
2 files changed, 5 insertions, 4 deletions
diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs
index a79e1a44e96..e2b8da64dc7 100644
--- a/src/librustc_parse/parser/diagnostics.rs
+++ b/src/librustc_parse/parser/diagnostics.rs
@@ -1054,7 +1054,7 @@ impl<'a> Parser<'a> {
         }
     }
 
-    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 @@ impl<'a> Parser<'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
         }
     }
 
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs
index ef98aab9c9f..986f5410e26 100644
--- a/src/librustc_parse/parser/expr.rs
+++ b/src/librustc_parse/parser/expr.rs
@@ -1006,7 +1006,7 @@ impl<'a> Parser<'a> {
                 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(),
         }
     }