rust/crates
bors[bot] 47b74cadf9
Merge #7970
7970: Fix incorrect diagnostics for failing built in macros r=jonas-schievink a=brandondong

**Reproduction:**
1. Use a built in macro in such a way that rust-analyzer fails to expand it. For example:

**lib.rs**
```
include!("<valid file but without a .rs extension so it is not indexed by rust-analyzer>");
```
2. rust-analyzer highlights the macro call and says the macro itself cannot be resolved even though include! is in the standard library (unresolved-macro-call diagnostic).
3. No macro-error diagnostic is raised.

**Root cause for incorrect unresolved-macro-call diagnostic:**
1. collector:collect_macro_call is able to resolve include! in legacy scope but the expansion fails. Therefore, it's pushed into unexpanded_macros to be retried with module scope.
2. include! fails at the resolution step in collector:resolve_macros now that it's using module scope. Therefore, it's retained in unexpanded_macros.
3. Finally, collector:finish tries resolving the remaining unexpanded macros but only with module scope. include! again fails at the resolution step so a diagnostic is created.

**Root cause for missing macro-error diagnostic:**
1. In collector:resolve_macros, directive.legacy is None since eager expansion failed in collector:collect_macro_call. The macro_call_as_call_id fails to resolve since we're retrying in module scope. Therefore, collect_macro_expansion is not called for the macro and no macro-error diagnostic is generated.

**Fix:**
- In collector:collect_macro_call, do not add failing built-in macros to the unexpanded_macros list and immediately raise the macro-error diagnostic. This is in contrast to lazy macros which are resolved in collector::resolve_macros and later expanded in collect_macro_expansion where a macro-error diagnostic may be raised.

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: brandondong <brandondong604@hotmail.com>
2021-03-15 18:24:22 +00:00
..
base_db Fixed remaining references to AnalysisChange (now: Change) 2021-02-28 12:57:41 +01:00
cfg Add runnables::related_tests 2021-02-27 18:00:17 +03:00
flycheck Bump cargo_metadata 2021-03-02 14:27:29 +02:00
hir Return multiple modules in parent_module 2021-03-15 15:15:40 +01:00
hir_def Merge #7970 2021-03-15 18:24:22 +00:00
hir_expand 7709: Updated the implementation. 2021-03-15 22:48:50 +05:30
hir_ty Fix unification logic 2021-03-15 19:14:10 +01:00
ide Merge #8028 2021-03-15 17:50:20 +00:00
ide_assists 7709: Updated the implementation. 2021-03-15 22:48:50 +05:30
ide_completion Merge #8035 2021-03-15 16:51:53 +00:00
ide_db Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
ide_ssr Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
mbe Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
parser Fix remaining references to cargo xtask codegen 2021-03-12 15:10:33 +01:00
paths
proc_macro_api Add test for proc-macro meta info retrieval 2021-03-15 23:38:22 +08:00
proc_macro_srv Add test for proc-macro meta info retrieval 2021-03-15 23:38:22 +08:00
proc_macro_test
profile
project_model some clippy::performance fixes 2021-03-15 10:19:59 +01:00
rust-analyzer Enable proc-macros by default 2021-03-15 18:19:08 +03:00
stdx
syntax Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
test_utils Use upstream cov-mark 2021-03-08 22:19:44 +02:00
text_edit
toolchain
tt add expand log 2021-03-13 20:14:21 +08:00
vfs Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00
vfs-notify Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00