]> git.lizzy.rs Git - rust.git/commitdiff
macros: Cancel DiagnosticBuilder when not emitting error
authorKamal Marhubi <kamal@marhubi.com>
Thu, 7 Apr 2016 20:29:05 +0000 (16:29 -0400)
committerKamal Marhubi <kamal@marhubi.com>
Thu, 7 Apr 2016 22:05:57 +0000 (18:05 -0400)
The error handling in libsyntax changed to use a `DiagnosticBuilder`
type in the `Err` variant of `PResult`. This type has `emit()` and
`cancel()` methods. Once created, errors must be emitted or canceled; if
not, the `Drop` impl on `DiagnosticBuilder` will panic.

The first syntex_syntax release to include this change was v0.25.0. The
bump from v0.23.0 to v0.29.1 in #847 did not add any `cancel()` calls,
even though at least one was required. There may be others not caught in
this commit.

src/macros.rs

index d2709bed809e5057124715b0f26f260421289b50..a6cbd634dd9265c7f931010bbfc430f11d07f6e2 100644 (file)
@@ -82,7 +82,10 @@ pub fn rewrite_macro(mac: &ast::Mac,
         loop {
             expr_vec.push(match parser.parse_expr() {
                 Ok(expr) => expr,
-                Err(..) => return None,
+                Err(mut e) => {
+                    e.cancel();
+                    return None;
+                }
             });
 
             match parser.token {