diff options
| author | Austin Bonander <austin.bonander@gmail.com> | 2017-04-20 16:13:13 -0700 |
|---|---|---|
| committer | Austin Bonander <austin.bonander@gmail.com> | 2017-04-20 16:13:13 -0700 |
| commit | 910532ea4559684e16d4acbd058c643599fe9536 (patch) | |
| tree | 5676fceaa0141783352f70463d40c5ca5e206a2a /src/libsyntax/ext | |
| parent | c398efc53f09f6e1a8cba4ec2259ffb9d89f0542 (diff) | |
| download | rust-910532ea4559684e16d4acbd058c643599fe9536.tar.gz rust-910532ea4559684e16d4acbd058c643599fe9536.zip | |
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
Diffstat (limited to 'src/libsyntax/ext')
| -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!(), }; |
