Skip to content

Commit 1b8331b

Browse files
committed
nix remaining rustc_expand::panictry! uses.
1 parent a57ccf7 commit 1b8331b

File tree

4 files changed

+19
-35
lines changed

4 files changed

+19
-35
lines changed

src/librustc_builtin_macros/cmdline_attrs.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use rustc_ast::ast::{self, AttrItem, AttrStyle};
44
use rustc_ast::attr::mk_attr;
55
use rustc_ast::token;
6-
use rustc_expand::panictry;
76
use rustc_session::parse::ParseSess;
87
use rustc_span::FileName;
98

@@ -16,7 +15,13 @@ pub fn inject(mut krate: ast::Crate, parse_sess: &ParseSess, attrs: &[String]) -
1615
);
1716

1817
let start_span = parser.token.span;
19-
let AttrItem { path, args } = panictry!(parser.parse_attr_item());
18+
let AttrItem { path, args } = match parser.parse_attr_item() {
19+
Ok(ai) => ai,
20+
Err(mut err) => {
21+
err.emit();
22+
continue;
23+
}
24+
};
2025
let end_span = parser.token.span;
2126
if parser.token != token::Eof {
2227
parse_sess.span_diagnostic.span_err(start_span.to(end_span), "invalid crate attribute");

src/librustc_builtin_macros/source_util.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_ast::token;
44
use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast_pretty::pprust;
66
use rustc_expand::base::{self, *};
7-
use rustc_expand::panictry;
87
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser, DirectoryOwnership};
98
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
109
use rustc_span::symbol::Symbol;
@@ -116,7 +115,7 @@ pub fn expand_include<'cx>(
116115
}
117116
impl<'a> base::MacResult for ExpandResult<'a> {
118117
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
119-
let r = panictry!(self.p.parse_expr());
118+
let r = base::parse_expr(&mut self.p)?;
120119
if self.p.token != token::Eof {
121120
self.p.sess.buffer_lint(
122121
&INCOMPLETE_INCLUDE,
@@ -131,18 +130,17 @@ pub fn expand_include<'cx>(
131130
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
132131
let mut ret = SmallVec::new();
133132
while self.p.token != token::Eof {
134-
match panictry!(self.p.parse_item()) {
135-
Some(item) => ret.push(item),
136-
None => {
133+
match self.p.parse_item() {
134+
Err(mut err) => {
135+
err.emit();
136+
break;
137+
}
138+
Ok(Some(item)) => ret.push(item),
139+
Ok(None) => {
137140
let token = pprust::token_to_string(&self.p.token);
138-
self.p
139-
.sess
140-
.span_diagnostic
141-
.span_fatal(
142-
self.p.token.span,
143-
&format!("expected item, found `{}`", token),
144-
)
145-
.raise();
141+
let msg = format!("expected item, found `{}`", token);
142+
self.p.struct_span_err(self.p.token.span, &msg).emit();
143+
break;
146144
}
147145
}
148146
}

src/librustc_expand/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>, sp: Span, tts: TokenStream, name: &str)
11621162
}
11631163

11641164
/// Parse an expression. On error, emit it, advancing to `Eof`, and return `None`.
1165-
fn parse_expr(p: &mut parser::Parser<'_>) -> Option<P<ast::Expr>> {
1165+
pub fn parse_expr(p: &mut parser::Parser<'_>) -> Option<P<ast::Expr>> {
11661166
match p.parse_expr() {
11671167
Ok(e) => return Some(e),
11681168
Err(mut err) => err.emit(),

src/librustc_expand/lib.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,6 @@
77

88
extern crate proc_macro as pm;
99

10-
// A variant of 'try!' that panics on an Err. This is used as a crutch on the
11-
// way towards a non-panic!-prone parser. It should be used for fatal parsing
12-
// errors; eventually we plan to convert all code using panictry to just use
13-
// normal try.
14-
#[macro_export]
15-
macro_rules! panictry {
16-
($e:expr) => {{
17-
use rustc_errors::FatalError;
18-
use std::result::Result::{Err, Ok};
19-
match $e {
20-
Ok(e) => e,
21-
Err(mut e) => {
22-
e.emit();
23-
FatalError.raise()
24-
}
25-
}
26-
}};
27-
}
28-
2910
mod placeholders;
3011
mod proc_macro_server;
3112

0 commit comments

Comments
 (0)