diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-15 18:24:22 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-15 18:24:22 +0000 |
commit | 47b74cadf9774f624ff13f8c7929c66be8247fc8 (patch) | |
tree | 6dc42e70ef3635bb53354b4e8991f517eb9b389d /crates/syntax/test_data/parser/fragments/stmt/err | |
parent | e24453c5ee46546b0852c15500d51f77b10a7a6f (diff) | |
parent | ebb10da563f1c3a0ebf48c1022bceb9641b6e964 (diff) |
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 <[email protected]>
Co-authored-by: brandondong <[email protected]>
Diffstat (limited to 'crates/syntax/test_data/parser/fragments/stmt/err')
0 files changed, 0 insertions, 0 deletions