diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-04-21 23:29:15 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-04-21 23:29:15 -0400 |
| commit | 48a9d5f6d3509355d0d8729b35c4d91cc463c38c (patch) | |
| tree | 628e53750f62e5ccea557a0afecbcb28d6b075a3 /src/libsyntax | |
| parent | aff40e2de340ce8b468495941e46d9f0dffdce79 (diff) | |
| parent | 910532ea4559684e16d4acbd058c643599fe9536 (diff) | |
| download | rust-48a9d5f6d3509355d0d8729b35c4d91cc463c38c.tar.gz rust-48a9d5f6d3509355d0d8729b35c4d91cc463c38c.zip | |
Rollup merge of #41432 - abonander:issue_41211, r=jseyfried
Don't panic if an attribute macro fails to resolve at crate root Adds temporary regression test; this ideally should work as-is (#41430) Closes #41211 r? @jseyfried
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 680bd7599ac..842398ea02b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -205,6 +205,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { module.directory.pop(); self.cx.current_expansion.module = Rc::new(module); + let orig_mod_span = krate.module.inner; + let krate_item = Expansion::Items(SmallVector::one(P(ast::Item { attrs: krate.attrs, span: krate.span, @@ -214,11 +216,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> { vis: ast::Visibility::Public, }))); - match self.expand(krate_item).make_items().pop().unwrap().unwrap() { - ast::Item { attrs, node: ast::ItemKind::Mod(module), .. } => { + match self.expand(krate_item).make_items().pop().map(P::unwrap) { + Some(ast::Item { attrs, node: ast::ItemKind::Mod(module), .. }) => { krate.attrs = attrs; krate.module = module; }, + None => { + // Resolution failed so we return an empty expansion + krate.attrs = vec![]; + krate.module = ast::Mod { + inner: orig_mod_span, + items: vec![], + }; + }, _ => unreachable!(), }; |
