diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-02 11:30:49 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-02 11:30:49 +0100 |
commit | fb8fb65131c8d3e6335efd401e4e83287be49357 (patch) | |
tree | 9b82278d8f204a012a1e115f92b252c7c6150e15 /crates/ra_hir_def/src/nameres/raw.rs | |
parent | 75bc0249463b72971200e482d69dad88d4e76ae3 (diff) | |
parent | edf0b4c1528407d5077220191e601ac41f790b99 (diff) |
Merge #4234
4234: Support local_inner_macros r=jonas-schievink a=edwin0cheng
This PR implements `#[macro_export(local_inner_macros)]` support.
Note that the rustc implementation is quite [hacky][1] too. :)
[1]: https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/nameres/raw.rs')
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 39b011ad7..a71503c76 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -188,6 +188,7 @@ pub(super) struct MacroData { | |||
188 | pub(super) path: ModPath, | 188 | pub(super) path: ModPath, |
189 | pub(super) name: Option<Name>, | 189 | pub(super) name: Option<Name>, |
190 | pub(super) export: bool, | 190 | pub(super) export: bool, |
191 | pub(super) local_inner: bool, | ||
191 | pub(super) builtin: bool, | 192 | pub(super) builtin: bool, |
192 | } | 193 | } |
193 | 194 | ||
@@ -401,14 +402,32 @@ impl RawItemsCollector { | |||
401 | 402 | ||
402 | let name = m.name().map(|it| it.as_name()); | 403 | let name = m.name().map(|it| it.as_name()); |
403 | let ast_id = self.source_ast_id_map.ast_id(&m); | 404 | let ast_id = self.source_ast_id_map.ast_id(&m); |
404 | // FIXME: cfg_attr | ||
405 | let export = m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "macro_export"); | ||
406 | 405 | ||
407 | // FIXME: cfg_attr | 406 | // FIXME: cfg_attr |
408 | let builtin = | 407 | let export_attr = attrs.by_key("macro_export"); |
409 | m.attrs().filter_map(|x| x.simple_name()).any(|name| name == "rustc_builtin_macro"); | 408 | |
409 | let export = export_attr.exists(); | ||
410 | let local_inner = if export { | ||
411 | export_attr.tt_values().map(|it| &it.token_trees).flatten().any(|it| match it { | ||
412 | tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => { | ||
413 | ident.text.contains("local_inner_macros") | ||
414 | } | ||
415 | _ => false, | ||
416 | }) | ||
417 | } else { | ||
418 | false | ||
419 | }; | ||
420 | |||
421 | let builtin = attrs.by_key("rustc_builtin_macro").exists(); | ||
410 | 422 | ||
411 | let m = self.raw_items.macros.alloc(MacroData { ast_id, path, name, export, builtin }); | 423 | let m = self.raw_items.macros.alloc(MacroData { |
424 | ast_id, | ||
425 | path, | ||
426 | name, | ||
427 | export, | ||
428 | local_inner, | ||
429 | builtin, | ||
430 | }); | ||
412 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); | 431 | self.push_item(current_module, attrs, RawItemKind::Macro(m)); |
413 | } | 432 | } |
414 | 433 | ||