nix remaining rustc_expand::panictry! uses.
This commit is contained in:
parent
0a8db690a4
commit
b7909b22b5
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(),
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user