Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3d8b961

Browse files
authoredMar 24, 2020
Rollup merge of #70074 - Centril:unpanictry, r=petrochenkov
Expand: nix all fatal errors Basically, we go after all `.span_fatal` / `FatalError.raise()` and similar things and remove them one by one until there are no fatal errors left. r? @petrochenkov
2 parents 0a39964 + 470e163 commit 3d8b961

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+584
-274
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
}

0 commit comments

Comments
 (0)
Please sign in to comment.