]> git.lizzy.rs Git - rust.git/commitdiff
nix remaining rustc_expand::panictry! uses.
authorMazdak Farrokhzad <twingoow@gmail.com>
Tue, 17 Mar 2020 07:59:56 +0000 (08:59 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Tue, 24 Mar 2020 05:28:55 +0000 (06:28 +0100)
src/librustc_builtin_macros/cmdline_attrs.rs
src/librustc_builtin_macros/source_util.rs
src/librustc_expand/base.rs
src/librustc_expand/lib.rs

index 7ddbf08306b72031ab2e7695b565d5b59510d506..093815dbbcd4f1c1dfb9821119f9a305fbdf2b48 100644 (file)
@@ -3,7 +3,6 @@
 use rustc_ast::ast::{self, AttrItem, AttrStyle};
 use rustc_ast::attr::mk_attr;
 use rustc_ast::token;
-use rustc_expand::panictry;
 use rustc_session::parse::ParseSess;
 use rustc_span::FileName;
 
@@ -16,7 +15,13 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
         );
 
         let start_span = parser.token.span;
-        let AttrItem { path, args } = panictry!(parser.parse_attr_item());
+        let AttrItem { path, args } = match parser.parse_attr_item() {
+            Ok(ai) => ai,
+            Err(mut err) => {
+                err.emit();
+                continue;
+            }
+        };
         let end_span = parser.token.span;
         if parser.token != token::Eof {
             parse_sess.span_diagnostic.span_err(start_span.to(end_span), "invalid crate attribute");
index 51a15f9df1bc79b57c9f35cc97bd0867eb2408a0..67145c6bf433be3c2c950ccfc6b5f6197ffd6891 100644 (file)
@@ -5,7 +5,6 @@
 use rustc_ast_pretty::pprust;
 use rustc_expand::base::{self, *};
 use rustc_expand::module::DirectoryOwnership;
-use rustc_expand::panictry;
 use rustc_parse::{self, new_parser_from_file, parser::Parser};
 use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
 use rustc_span::symbol::Symbol;
@@ -126,7 +125,7 @@ struct ExpandResult<'a> {
     }
     impl<'a> base::MacResult for ExpandResult<'a> {
         fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
-            let r = panictry!(self.p.parse_expr());
+            let r = base::parse_expr(&mut self.p)?;
             if self.p.token != token::Eof {
                 self.p.sess.buffer_lint(
                     &INCOMPLETE_INCLUDE,
@@ -141,18 +140,17 @@ fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
         fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
             let mut ret = SmallVec::new();
             while self.p.token != token::Eof {
-                match panictry!(self.p.parse_item()) {
-                    Some(item) => ret.push(item),
-                    None => {
+                match self.p.parse_item() {
+                    Err(mut err) => {
+                        err.emit();
+                        break;
+                    }
+                    Ok(Some(item)) => ret.push(item),
+                    Ok(None) => {
                         let token = pprust::token_to_string(&self.p.token);
-                        self.p
-                            .sess
-                            .span_diagnostic
-                            .span_fatal(
-                                self.p.token.span,
-                                &format!("expected item, found `{}`", token),
-                            )
-                            .raise();
+                        let msg = format!("expected item, found `{}`", token);
+                        self.p.struct_span_err(self.p.token.span, &msg).emit();
+                        break;
                     }
                 }
             }
index e47e0a757866c0339f731c4fed73eae7a0f661fa..b615b34634fb25654695733b818df88b41849f55 100644 (file)
@@ -1169,7 +1169,7 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>, sp: Span, tts: TokenStream, name: &str)
 }
 
 /// Parse an expression. On error, emit it, advancing to `Eof`, and return `None`.
-fn parse_expr(p: &mut parser::Parser<'_>) -> Option<P<ast::Expr>> {
+pub fn parse_expr(p: &mut parser::Parser<'_>) -> Option<P<ast::Expr>> {
     match p.parse_expr() {
         Ok(e) => return Some(e),
         Err(mut err) => err.emit(),
index 0320a275e5d20de35c773dd602a57768785551c4..876a26de3fb7e86c8fe355c585d6f8dd3490c840 100644 (file)
@@ -9,25 +9,6 @@
 
 extern crate proc_macro as pm;
 
-// A variant of 'try!' that panics on an Err. This is used as a crutch on the
-// way towards a non-panic!-prone parser. It should be used for fatal parsing
-// errors; eventually we plan to convert all code using panictry to just use
-// normal try.
-#[macro_export]
-macro_rules! panictry {
-    ($e:expr) => {{
-        use rustc_errors::FatalError;
-        use std::result::Result::{Err, Ok};
-        match $e {
-            Ok(e) => e,
-            Err(mut e) => {
-                e.emit();
-                FatalError.raise()
-            }
-        }
-    }};
-}
-
 mod placeholders;
 mod proc_macro_server;