rust-lang / rust-lang/rust-clippy
Clippy returning incorrect exit code when automatically applying lint suggestions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I'm not exactly sure whether or not this is really a bug or intentional behavior, as pointed in another question on the same matter i've asked here, i think it would make more sense if
clippy, when executed with--fix, prioritized the lints when determining the exit code over whether or not it could apply the automatic fixes
I'm running Clippy with the following command:
cargo clippy --fix -- -F warnings
It runs, returns the output below, and terminates with the exit code 0:
warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
--> project-euler/multiples_of_3_or_5/src/main.rs:46:37
|
46 | pub fn sum_multiples(multiplicands: &Vec<u32>, maximum_possible_multiple: u32) -> u32 {
| ^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
= note: `-F clippy::ptr-arg` implied by `-F warnings`
help: change this to
|
46 ~ pub fn sum_multiples(multiplicands: &[u32], maximum_possible_multiple: u32) -> u32 {
47 | let possible_multiples: std::ops::Range<u32> = 1..maximum_possible_multiple;
...
50 | .filter(|possible_multiple| {
51 ~ multiplicands.to_owned()
|
warning: called `is_some()` after searching an `Iterator` with `find`
--> project-euler/multiples_of_3_or_5/src/main.rs:54:18
|
54 | .find(|multiplicand| possible_multiple.is_multiple_of(*multiplicand))
| __________________^
55 | | .is_some()
| |__________________________^ help: use `any()` instead: `any(|multiplicand| possible_multiple.is_multiple_of(multiplicand))`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
= note: `-F clippy::search-is-some` implied by `-F warnings`
warning: `multiples_of_3_or_5` (bin "multiples_of_3_or_5") generated 2 warnings
warning: `multiples_of_3_or_5` (bin "multiples_of_3_or_5" test) generated 2 warnings (2 duplicates)
Finished dev [unoptimized + debuginfo] target(s) in 1.49s
But whenever i repeat the same command, but without the --fix flag, works as expected, the output is similar to the one above but slightly different, it terminates with the exit code 101:
error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
--> project-euler/multiples_of_3_or_5/src/main.rs:46:37
|
46 | pub fn sum_multiples(multiplicands: &Vec<u32>, maximum_possible_multiple: u32) -> u32 {
| ^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
= note: `-F clippy::ptr-arg` implied by `-F warnings`
help: change this to
|
46 ~ pub fn sum_multiples(multiplicands: &[u32], maximum_possible_multiple: u32) -> u32 {
47 | let possible_multiples: std::ops::Range<u32> = 1..maximum_possible_multiple;
...
50 | .filter(|possible_multiple| {
51 ~ multiplicands.to_owned()
|
error: called `is_some()` after searching an `Iterator` with `find`
--> project-euler/multiples_of_3_or_5/src/main.rs:54:18
|
54 | .find(|multiplicand| possible_multiple.is_multiple_of(*multiplicand))
| __________________^
55 | | .is_some()
| |__________________________^ help: use `any()` instead: `any(|multiplicand| possible_multiple.is_multiple_of(multiplicand))`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
= note: `-F clippy::search-is-some` implied by `-F warnings`
error: could not compile `multiples_of_3_or_5` (bin "multiples_of_3_or_5") due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
Reproducer
The example below makes use of a local crate on my system called
is_multiple_of, to avoid making this issue too long, i intentionally left it out as i don't think it's very relevant to the problem in question, but if needed, let me know and i can include it as well
I tried this code:
use is_multiple_of::IsMultipleOf;
#[must_use]
pub fn sum_multiples(multiplicands: &Vec<u32>, maximum_possible_multiple: u32) -> u32 {
let possible_multiples: std::ops::Range<u32> = 1..maximum_possible_multiple;
possible_multiples
.filter(|possible_multiple| {
multiplicands
.clone()
.into_iter()
.find(|multiplicand| possible_multiple.is_multiple_of(*multiplicand))
.is_some()
})
.sum::<u32>()
}
fn main() {
const MAXIMUM_POSSIBLE_MULTIPLE: u32 = 1_000;
let multiplicands: Vec<u32> = vec![3, 5];
let multiples_sum = sum_multiples(&multiplicands, MAXIMUM_POSSIBLE_MULTIPLE);
println!("{multiples_sum}");
}
I expected to see this happen: clippy exit code be 101
Instead, this happened: clippy terminated with an exit code of 0
Version
rustc 1.72.0-nightly (f4b80cacf 2023-06-30)
binary: rustc
commit-hash: f4b80cacf93ca216c75f6ae12f4b9dec19eba42f
commit-date: 2023-06-30
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported cargo clippy --fix -- -F warnings and non---fix commands with the Rust example in the issue. Trace how Clippy determines its exit status when automatic fixes are applied; done means the behavior is defined and the command returns the expected nonzero status when denied lints remain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100