Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inactive-code incorrectly applied when #![cfg(os)] is used in module file #17817

Closed
chris-oo opened this issue Aug 7, 2024 · 4 comments · Fixed by #17823
Closed

inactive-code incorrectly applied when #![cfg(os)] is used in module file #17817

chris-oo opened this issue Aug 7, 2024 · 4 comments · Fixed by #17823
Assignees
Labels
Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug

Comments

@chris-oo
Copy link

chris-oo commented Aug 7, 2024

I have a minimal repro of this issue here: https://github.com/chris-oo/ra-inactive-code-repro

Essentially, if a module file is cfg gated with #![cfg(windows)] or any OS that you're not currently targeting, rust-analyzer incorrectly marks the whole parent file as greyed out with the inactive code warning instead of just marking the module as greyed out. It also marks the module that should be inactive as not greyed out, but with no type completions.

image

This code does compile with rustc and runs as expected. It seemed to repro with both release and pre-release versions.

Pictured RA version: v0.4.2064 (pre-release)
Rust version: 1.80

@chris-oo chris-oo added the C-bug Category: bug label Aug 7, 2024
@chris-oo
Copy link
Author

chris-oo commented Aug 7, 2024

It does seem like you can not hit this issue if you instead use #[cfg(windows)] where the module is defined, instead of #![cfg(windows)] at the top of the module file. It seems like somehow #![cfg(windows)] is getting propagated to the parent instead of the local module?

@Veykril
Copy link
Member

Veykril commented Aug 7, 2024

Likely regressed in 9cbafa2

@Veykril Veykril added the Broken Window Bugs / technical debt to be addressed immediately label Aug 7, 2024
@Veykril
Copy link
Member

Veykril commented Aug 7, 2024

Yep 9cbafa2#diff-3cb35c45ff5d9609122d5bc02989d082a2ed0937b08015c1ba839153a58505b8R1952-R1957 this now marks the whole parent tree accidentally, instead of the module

@chris-oo
Copy link
Author

chris-oo commented Aug 7, 2024

Thanks for the fast turnaround!

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 13, 2024
fix: Fix unconfigured diagnostic being attached to the wrong file for modules

Fixes rust-lang/rust-analyzer#17817
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants