rust-analyzer/crates
bors[bot] c3d96f64ef
Merge #1795
1795: Make macro scope a real name scope and fix some details r=matklad a=uHOOCCOOHu

This PR make macro's module scope a real name scope in `PerNs`, instead of handling `Either<PerNs, MacroDef>` everywhere.

In `rustc`, the macro scope behave exactly the same as type and value scope.
It is valid that macros, types and values having exact the same name, and a `use` statement will import all of them. This happened to module `alloc::vec` and macro `alloc::vec!`.
So `Either` is not suitable here.

There is a trap that not only does `#[macro_use]` import all `#[macro_export] macro_rules`, but also imports all macros `use`d in the crate root.
In other words, it just _imports all macros in the module scope of crate root_. (Visibility of `use` doesn't matter.)

And it also happened to `libstd` which has `use alloc_crate::vec;` in crate root to re-export `alloc::vec`, which it both a module and a macro.
The current implementation of `#[macro_use] extern crate` doesn't work here, so that is why only macros directly from  `libstd` like `dbg!` work, while `vec!` from `liballoc` doesn't.
This PR fixes this.

Another point is that, after some tests, I figure out that _`macro_rules` does NOT define macro in current module scope at all_.
It defines itself in legacy textual scope. And if `#[macro_export]` is given, it also is defined ONLY in module scope of crate root. (Then being `macro_use`d, as mentioned above)
(Well, the nightly [Declarative Macro 2.0](https://github.com/rust-lang/rust/issues/39412) simply always define in current module scope only, just like normal items do. But it is not yet supported by us)

After this PR, in my test, all non-builtin macros are resolved now. (Hover text for documentation is available) So it fixes #1688 . Since compiler builtin macros are marked as `#[rustc_doc_only_macro]` instead of `#[macro_export]`, we can simply tweak the condition to let it resolved, but it may cause expansion error.

Some critical notes are also given in doc-comments.

<img width="447" alt="Screenshot_20190909_223859" src="https://user-images.githubusercontent.com/14816024/64540366-ac1ef600-d352-11e9-804f-566ba7559206.png">


Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
2019-09-09 21:09:23 +00:00
..
ra_arena cleanup 2019-08-06 10:57:16 +02:00
ra_assists Minor typo fix for ra_assists code doc 2019-09-08 02:10:53 -07:00
ra_batch document module 2019-09-09 17:31:11 +03:00
ra_cli make source_root API more abstract 2019-09-06 14:21:11 +03:00
ra_db introduce hir debugging infra 2019-09-09 12:32:16 +03:00
ra_fmt fix hir for new block syntax 2019-09-02 21:23:19 +03:00
ra_hir Merge #1795 2019-09-09 21:09:23 +00:00
ra_ide_api introduce hir debugging infra 2019-09-09 12:32:16 +03:00
ra_lsp_server introduce hir debugging infra 2019-09-09 12:32:16 +03:00
ra_mbe fix assists 2019-09-02 21:52:06 +03:00
ra_parser tiny simplification 2019-09-09 13:23:41 +03:00
ra_prof ⬆️ once_cell 2019-09-01 23:18:15 +03:00
ra_project_model introduce hir debugging infra 2019-09-09 12:32:16 +03:00
ra_syntax Fix outer doc-comments of macro_rules 2019-09-09 11:13:14 +08:00
ra_text_edit allow rustfmt to reorder imports 2019-07-04 23:09:09 +03:00
ra_tools disable clap's features 2019-08-22 15:57:48 +03:00
ra_tt allow rustfmt to reorder imports 2019-07-04 23:09:09 +03:00
ra_vfs_glob add option to disable notify 2019-09-06 17:21:29 +03:00
test_utils translate \n -> \r\n on the way out 2019-08-20 19:53:05 +03:00