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

Don't pass --all-targets when a target is specified #18110

Open
mo8it opened this issue Sep 13, 2024 · 0 comments
Open

Don't pass --all-targets when a target is specified #18110

mo8it opened this issue Sep 13, 2024 · 0 comments
Assignees
Labels
C-bug Category: bug

Comments

@mo8it
Copy link
Contributor

mo8it commented Sep 13, 2024

We apply a target in this line:

But then, apply_on_command is called in this line:

options.apply_on_command(&mut cmd);

apply_on_command adds --all-targets if the config value all_targets is true (which is the default).

Sadly, Cargo currently ignores any target specification like --bin BIN_NAME if --all-targets is specified. Which means that PR #17912 is ineffective right now.

So what is the solution? Don't pass --all-targets when a specific target is passed? This currently can't be the solution.

The first problem is that when not using --all-targets and without --profile test, Cargo doesn't check tests with #[cfg(test)]. So we should (always?) add --profile test to cargo check?

The second problem is that Rust-Analyzer seems to forget all errors and warnings after an invocation of cargo check. See the video from VS-Code in a Windows VM with the pre-release Rust-Analyzer extension:

Screencast.from.2024-09-13.15-47-18.webm

In this video, I disabled all_targets in the extension settings. When Rust-Analyzer starts, it runs cargo check and collects 113 errors and 8 warnings. Then, while still starting up, it forgets all these errors and warnings and runs cargo check again until it reaches the same 113 errors and 8 warnings that it already had!?

But this isn't the main issue here. The issue is that, after saving one file associated with a binary, Rust-Analyzer runs cargo check --bin if1 quickly as expected from #17912 but it forgets all diagnostics it had before about the other targets!

TL;DR

  • We need to omit --all-targets when specifying a specific target like --bin.
  • We need to pass --target test to the check command.
  • Rust-Analyzer shouldn't forget all diagnostics from other targets.
  • (Why does Rust-Analyzer run cargo check twice on startup?)

CC @alibektas @Veykril from the other PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants