Skip to content

Commit bb9f14c

Browse files
committed
rustc_expand::base: nix panictry! uses
1 parent f509b26 commit bb9f14c

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/librustc_expand/base.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,18 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>, sp: Span, tts: TokenStream, name: &str)
11611161
}
11621162
}
11631163

1164+
/// 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>> {
1166+
match p.parse_expr() {
1167+
Ok(e) => return Some(e),
1168+
Err(mut err) => err.emit(),
1169+
}
1170+
while p.token != token::Eof {
1171+
p.bump();
1172+
}
1173+
None
1174+
}
1175+
11641176
/// Interpreting `tts` as a comma-separated sequence of expressions,
11651177
/// expect exactly one string literal, or emit an error and return `None`.
11661178
pub fn get_single_str_from_tts(
@@ -1174,7 +1186,7 @@ pub fn get_single_str_from_tts(
11741186
cx.span_err(sp, &format!("{} takes 1 argument", name));
11751187
return None;
11761188
}
1177-
let ret = panictry!(p.parse_expr());
1189+
let ret = parse_expr(&mut p)?;
11781190
let _ = p.eat(&token::Comma);
11791191

11801192
if p.token != token::Eof {
@@ -1183,8 +1195,8 @@ pub fn get_single_str_from_tts(
11831195
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s.to_string())
11841196
}
11851197

1186-
/// Extracts comma-separated expressions from `tts`. If there is a
1187-
/// parsing error, emit a non-fatal error and return `None`.
1198+
/// Extracts comma-separated expressions from `tts`.
1199+
/// On error, emit it, and return `None`.
11881200
pub fn get_exprs_from_tts(
11891201
cx: &mut ExtCtxt<'_>,
11901202
sp: Span,
@@ -1193,7 +1205,7 @@ pub fn get_exprs_from_tts(
11931205
let mut p = cx.new_parser_from_tts(tts);
11941206
let mut es = Vec::new();
11951207
while p.token != token::Eof {
1196-
let expr = panictry!(p.parse_expr());
1208+
let expr = parse_expr(&mut p)?;
11971209

11981210
// Perform eager expansion on the expression.
11991211
// We want to be able to handle e.g., `concat!("foo", "bar")`.

0 commit comments

Comments
 (0)