Skip to content

Commit 0f2d968

Browse files
committed
rustc_expand::base: nix panictry! uses
1 parent 342c5f3 commit 0f2d968

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
@@ -1168,6 +1168,18 @@ pub fn check_zero_tts(cx: &ExtCtxt<'_>, sp: Span, tts: TokenStream, name: &str)
11681168
}
11691169
}
11701170

1171+
/// 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>> {
1173+
match p.parse_expr() {
1174+
Ok(e) => return Some(e),
1175+
Err(mut err) => err.emit(),
1176+
}
1177+
while p.token != token::Eof {
1178+
p.bump();
1179+
}
1180+
None
1181+
}
1182+
11711183
/// Interpreting `tts` as a comma-separated sequence of expressions,
11721184
/// expect exactly one string literal, or emit an error and return `None`.
11731185
pub fn get_single_str_from_tts(
@@ -1181,7 +1193,7 @@ pub fn get_single_str_from_tts(
11811193
cx.span_err(sp, &format!("{} takes 1 argument", name));
11821194
return None;
11831195
}
1184-
let ret = panictry!(p.parse_expr());
1196+
let ret = parse_expr(&mut p)?;
11851197
let _ = p.eat(&token::Comma);
11861198

11871199
if p.token != token::Eof {
@@ -1190,8 +1202,8 @@ pub fn get_single_str_from_tts(
11901202
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s.to_string())
11911203
}
11921204

1193-
/// Extracts comma-separated expressions from `tts`. If there is a
1194-
/// parsing error, emit a non-fatal error and return `None`.
1205+
/// Extracts comma-separated expressions from `tts`.
1206+
/// On error, emit it, and return `None`.
11951207
pub fn get_exprs_from_tts(
11961208
cx: &mut ExtCtxt<'_>,
11971209
sp: Span,
@@ -1200,7 +1212,7 @@ pub fn get_exprs_from_tts(
12001212
let mut p = cx.new_parser_from_tts(tts);
12011213
let mut es = Vec::new();
12021214
while p.token != token::Eof {
1203-
let expr = panictry!(p.parse_expr());
1215+
let expr = parse_expr(&mut p)?;
12041216

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

0 commit comments

Comments
 (0)