diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-17 08:29:34 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-03-24 06:28:10 +0100 |
| commit | 0f2d9686ccbb67ce23e6acf587c5d1395288dc00 (patch) | |
| tree | 838b878c7dfb8002f3874e882d9a9e201d2a07b1 | |
| parent | 342c5f33d097b2dc07a2dbc0ca45a37379d2ff60 (diff) | |
| download | rust-0f2d9686ccbb67ce23e6acf587c5d1395288dc00.tar.gz rust-0f2d9686ccbb67ce23e6acf587c5d1395288dc00.zip | |
rustc_expand::base: nix panictry! uses
| -rw-r--r-- | src/librustc_expand/base.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/librustc_expand/base.rs b/src/librustc_expand/base.rs index 0fc477bbd0b..e47e0a75786 100644 --- a/src/librustc_expand/base.rs +++ b/src/librustc_expand/base.rs @@ -1168,6 +1168,18 @@ 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>> { + match p.parse_expr() { + Ok(e) => return Some(e), + Err(mut err) => err.emit(), + } + while p.token != token::Eof { + p.bump(); + } + None +} + /// Interpreting `tts` as a comma-separated sequence of expressions, /// expect exactly one string literal, or emit an error and return `None`. pub fn get_single_str_from_tts( @@ -1181,7 +1193,7 @@ pub fn get_single_str_from_tts( cx.span_err(sp, &format!("{} takes 1 argument", name)); return None; } - let ret = panictry!(p.parse_expr()); + let ret = parse_expr(&mut p)?; let _ = p.eat(&token::Comma); if p.token != token::Eof { @@ -1190,8 +1202,8 @@ pub fn get_single_str_from_tts( expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s.to_string()) } -/// Extracts comma-separated expressions from `tts`. If there is a -/// parsing error, emit a non-fatal error and return `None`. +/// Extracts comma-separated expressions from `tts`. +/// On error, emit it, and return `None`. pub fn get_exprs_from_tts( cx: &mut ExtCtxt<'_>, sp: Span, @@ -1200,7 +1212,7 @@ pub fn get_exprs_from_tts( let mut p = cx.new_parser_from_tts(tts); let mut es = Vec::new(); while p.token != token::Eof { - let expr = panictry!(p.parse_expr()); + let expr = parse_expr(&mut p)?; // Perform eager expansion on the expression. // We want to be able to handle e.g., `concat!("foo", "bar")`. |
