Rust analyzer notifying me of any type errors in my code can be immensely useful, both in production code and tests. However, when making a large refactoring, errors in tests are just noise up to the point where the production code is error free.
Is there any way to temporarily make RA ignore errors in tests? Bonus points for solutions that work for the VS Code plugin.
--Edit
I should point out that I'm particularly interested in silencing these errors in the "Problems" window of VS Code
- 1You can set a setting, but that will require unsetting it <s>and restarting rust-analyzer</s> (looks like it doesn't require restarting).Chayim Friedman– Chayim Friedman2025-07-20 20:57:39 +00:00CommentedJul 20 at 20:57
- 3rust-analyzer.github.io/book/configuration.html#cfg.setTestChayim Friedman– Chayim Friedman2025-07-20 20:59:30 +00:00CommentedJul 20 at 20:59
- Instead of disabling errors in tests why won't you simply fix them? That would be infinitely more useful. Honestly, this sounds like XY problem.freakish– freakish2025-07-21 13:31:32 +00:00CommentedJul 21 at 13:31
- 1It's beneficial to have some way to 'divide and conquer' when dealing with large amount of compiler errors during a refactor. Hence the request is about a way to temporary de-prioritize errors in tests - with the aim to enable those back once refactored changes crystalize.lufterd– lufterd2025-07-21 16:48:48 +00:00CommentedJul 21 at 16:48
2 Answers2
Rust-analyzer's documentationdescribes the optioncfg.setTest which allows to disabletest feature when language server compiles the crate and suppress all errors in#[test] and#[cfg(test)] blocks. It'strue by default, so setting it tofalse prevents errors in test cases from being produced.
It's possible to set this option tofalse temporarily in VSCode's user-sidesettings.json ifrust-analyzer plugin is installed:
{ "rust-analyzer.cfg.setTest": false}Note that the current implementation would also exclude benchmark targets. Argument is applied tocargo check on the nightly version ofrust-analyzer at the moment or writing (the patch was merged after the initial reply).
Another option which provides a bit more control on which targets should be included is to providecheck.allTargets option asfalse (socargo check wouldn't receive--all-targets flag), and specify target flags manually:
{ "rust-analyzer.check.allTargets": false, "rust-analyzer.check.extraArgs": ["--bins", "--examples"]}That way it would be possible to decide if--examples,--benches and--lib/--bins should be included or not.
3 Comments
cargo check on them (maybe this is something we should change). To disablecargo check too, you need to setrust-analyzer.check.overrideCommand.According to experimentation, to silence errors in tests in the "Problems" section of VS Code, what works is setting
{ "rust-analyzer.check.allTargets": false}though I'm not yet sure if that may perhaps be a little too strict and perhaps will disable other configurations as well.
You can use this until the changes by @Chayim Friedman are available to you
1 Comment
Explore related questions
See similar questions with these tags.