Skip to content

Commit 4c7a8cb

Browse files
authored
Merge pull request #20271 from ChayimFriedman2/cfg-settest-flycheck
fix: Disable tests in flycheck if `cfg.setTest` is set to false
2 parents 8b45a73 + 2e0b364 commit 4c7a8cb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,6 +2162,7 @@ impl Config {
21622162
extra_test_bin_args: self.runnables_extraTestBinaryArgs(source_root).clone(),
21632163
extra_env: self.extra_env(source_root).clone(),
21642164
target_dir: self.target_dir_from_config(source_root),
2165+
set_test: true,
21652166
}
21662167
}
21672168

@@ -2219,6 +2220,7 @@ impl Config {
22192220
extra_test_bin_args: self.runnables_extraTestBinaryArgs(source_root).clone(),
22202221
extra_env: self.check_extra_env(source_root),
22212222
target_dir: self.target_dir_from_config(source_root),
2223+
set_test: *self.cfg_setTest(source_root),
22222224
},
22232225
ansi_color_output: self.color_diagnostic_output(),
22242226
},

crates/rust-analyzer/src/flycheck.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) enum InvocationStrategy {
3131
pub(crate) struct CargoOptions {
3232
pub(crate) target_tuples: Vec<String>,
3333
pub(crate) all_targets: bool,
34+
pub(crate) set_test: bool,
3435
pub(crate) no_default_features: bool,
3536
pub(crate) all_features: bool,
3637
pub(crate) features: Vec<String>,
@@ -54,7 +55,13 @@ impl CargoOptions {
5455
cmd.args(["--target", target.as_str()]);
5556
}
5657
if self.all_targets {
57-
cmd.arg("--all-targets");
58+
if self.set_test {
59+
cmd.arg("--all-targets");
60+
} else {
61+
// No --benches unfortunately, as this implies --tests (see https://github.com/rust-lang/cargo/issues/6454),
62+
// and users setting `cfg.seTest = false` probably prefer disabling benches than enabling tests.
63+
cmd.args(["--lib", "--bins", "--examples"]);
64+
}
5865
}
5966
if self.all_features {
6067
cmd.arg("--all-features");

0 commit comments

Comments
 (0)