-
Notifications
You must be signed in to change notification settings - Fork 1.7k
VsCode: spurious "x is never used" if Rust-analyzer > Check On Save > All Targets, is selected in rust-analyzer options #8626
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
Comments
This has caused me to remove what I thought was dead code, then having |
Do you have a code sample? |
If I disable the feature, then rust-analyzer stops checking tests. |
I can attach logs if someone wants, then I check it off, here is the config shown in the output of rust analyzer
When I turn it off:
|
Okay, I've tracked this down to the use of mockall_double::double macro, which is an attribute macro used to rewrite imports for testing. When run in release, it uses one impl, in test it uses another. It basically emits in test mode: #[cfg(test)]
pub use crat::some_module::MockClient as Client and in debug/release: #[cfg(not(test))]
pub use crate::some_module::Client So rust analyzer is facing two mutually exclusive module imports on test vs debug/release I don't know if this is 'fixable', I admit it's a bit weird. But I suspect this might come up with rust_analyzer facing any mutually exclusive of cfg based features as well. |
I'll see what the behavior is with explicit cfg values. |
Manually expanded:
Cargo check is still happy, but rust_analyzer now says it can't find MockClient, though MockClient should be created from Client via the mock_all macro. If I get some time, I will see if I can gin up a simple POC. I believe the fundamental issue might be support of #[cfg(not(test))] ? |
Note that we don't support attribute proc macros, nor crate splitting for your case (#7459). |
I think I have a fix for mockall_double. EDIT: Nope. Pebkac, but I just learned something... |
Do you not get the warning with |
I get the warning with --all-targets, I do not get it with it turned off. EDIT: I mean with --all-targets enabled for rust-analyzer. Cargo checks them correctly, Rust-analyzer produces more warnings. |
Then this is a cargo bug, if at all. (This might very well be expected behavior though.) |
No. |
Sorry, I mean, |
@DanielJoyce Can you provide an example project that shows this behavior? |
To be clear, rust-analyzer currently doesn't emit "unused variable" warnings from its own analysis, so these warnings can only come from |
Not enough info to reproduce this, closing. |
VSCode:
Rust Analyzer Version: 0.2.565
Rust Version: 1.51
If I disable Rust-analyzer > Check On Save > All Targets, the spurious warnings go away.
Cargo check also does not show any matching warnings.
It seems that when merging results between targets, especially when checking the test target and the default target, rust analyzer gets confused or doesn't do it properly?
The text was updated successfully, but these errors were encountered: