Skip to content

Commit b7909b2

Browse files
committed
nix remaining rustc_expand::panictry! uses.
1 parent 0a8db69 commit b7909b2

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
@@ -5,7 +5,6 @@ use rustc_ast::tokenstream::TokenStream;
55
use rustc_ast_pretty::pprust;
66
use rustc_expand::base::{self, *};
77
use rustc_expand::module::DirectoryOwnership;
8-
use rustc_expand::panictry;
98
use rustc_parse::{self, new_parser_from_file, parser::Parser};
109
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
1110
use rustc_span::symbol::Symbol;
@@ -126,7 +125,7 @@ pub fn expand_include<'cx>(
126125
}
127126
impl<'a> base::MacResult for ExpandResult<'a> {
128127
fn make_expr(mut self: Box<ExpandResult<'a>>) -> Option<P<ast::Expr>> {
129-
let r = panictry!(self.p.parse_expr());
128+
let r = base::parse_expr(&mut self.p)?;
130129
if self.p.token != token::Eof {
131130
self.p.sess.buffer_lint(
132131
&INCOMPLETE_INCLUDE,
@@ -141,18 +140,17 @@ pub fn expand_include<'cx>(
141140
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
142141
let mut ret = SmallVec::new();
143142
while self.p.token != token::Eof {
144-
match panictry!(self.p.parse_item()) {
145-
Some(item) => ret.push(item),
146-
None => {
143+
match self.p.parse_item() {
144+
Err(mut err) => {
145+
err.emit();
146+
break;
147+
}
148+
Ok(Some(item)) => ret.push(item),
149+
Ok(None) => {
147150
let token = pprust::token_to_string(&self.p.token);
148-
self.p
149-
.sess
150-
.span_diagnostic
151-
.span_fatal(
152-
self.p.token.span,
153-
&format!("expected item, found `{}`", token),
154-
)
155-
.raise();
151+
let msg = format!("expected item, found `{}`", token);
152+
self.p.struct_span_err(self.p.token.span, &msg).emit();
153+
break;
156154
}
157155
}
158156
}

src/librustc_expand/base.rs

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

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

src/librustc_expand/lib.rs

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

1010
extern crate proc_macro as pm;
1111

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

0 commit comments

Comments
 (0)