about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-12-30 13:12:33 +0100
committerGitHub <noreply@github.com>2021-12-30 13:12:33 +0100
commitb9f7197ab35f79b4df1f60104b9d8af9e77bb566 (patch)
tree98576295cc009ed696e2cfa177ec11557aedf401 /compiler/rustc_expand/src
parent65d8785f0a85d233e00fc84445f1aab451ec9f4f (diff)
parentbdb851f567ed6123172b849abbfc9163d268e291 (diff)
downloadrust-b9f7197ab35f79b4df1f60104b9d8af9e77bb566.tar.gz
rust-b9f7197ab35f79b4df1f60104b9d8af9e77bb566.zip
Rollup merge of #91519 - petrochenkov:cratexp2, r=Aaron1011
ast: Avoid aborts on fatal errors thrown from mutable AST visitor

Set the node to some dummy value and rethrow the error instead.

When using the old aborting `visit_clobber` in `InvocationCollector::visit_crate` the next tests abort due to fatal errors:
```
ui\modules\path-invalid-form.rs
ui\modules\path-macro.rs
ui\modules\path-no-file-name.rs
ui\parser\issues\issue-5806.rs
ui\parser\mod_file_with_path_attr.rs
```

Follow up to https://github.com/rust-lang/rust/pull/91313.
Diffstat (limited to 'compiler/rustc_expand/src')
-rw-r--r--compiler/rustc_expand/src/expand.rs20
1 files changed, 11 insertions, 9 deletions
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs
index ba675daac41..f216a661487 100644
--- a/compiler/rustc_expand/src/expand.rs
+++ b/compiler/rustc_expand/src/expand.rs
@@ -1160,13 +1160,18 @@ macro_rules! assign_id {
 
 impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
     fn visit_crate(&mut self, krate: &mut ast::Crate) {
-        let span = krate.span;
-        let empty_crate =
-            || ast::Crate { attrs: Vec::new(), items: Vec::new(), span, is_placeholder: None };
-        let mut fold_crate = |krate: ast::Crate| {
+        visit_clobber(krate, |krate| {
+            let span = krate.span;
             let mut krate = match self.configure(krate) {
                 Some(krate) => krate,
-                None => return empty_crate(),
+                None => {
+                    return ast::Crate {
+                        attrs: Vec::new(),
+                        items: Vec::new(),
+                        span,
+                        is_placeholder: None,
+                    };
+                }
             };
 
             if let Some(attr) = self.take_first_attr(&mut krate) {
@@ -1177,10 +1182,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
 
             noop_visit_crate(&mut krate, self);
             krate
-        };
-
-        // Cannot use `visit_clobber` here, see the FIXME on it.
-        *krate = fold_crate(mem::replace(krate, empty_crate()));
+        })
     }
 
     fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {