Skip to content

Commit 8b67d89

Browse files
committed
Auto merge of #6829 - matthiaskrgr:lintcheck_unclippy, r=<try>
lintcheck: clippy fixes, test on ci fixes clippy warnings in lintcheck and adds a small test (run on 3 small crates) to gha ci changelog: none
2 parents 43d19f6 + 24111ec commit 8b67d89

File tree

5 files changed

+82
-32
lines changed

5 files changed

+82
-32
lines changed

.github/workflows/clippy.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ env:
2727

2828
jobs:
2929
base:
30+
# NOTE: If you modify this job, make sure you copy the changes to clippy_bors.yml
3031
runs-on: ubuntu-latest
3132

3233
steps:
@@ -64,8 +65,8 @@ jobs:
6465
run: cargo test --features deny-warnings
6566
working-directory: rustc_tools_util
6667

67-
- name: Test clippy_dev
68-
run: cargo test --features deny-warnings
68+
- name: Test clippy_dev and lintcheck
69+
run: cargo test --features lintcheck,deny-warnings
6970
working-directory: clippy_dev
7071

7172
- name: Test cargo-clippy

.github/workflows/clippy_bors.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272

7373
runs-on: ${{ matrix.os }}
7474

75+
# NOTE: If you modify this job, make sure you copy the changes to clippy.yml
7576
steps:
7677
# Setup
7778
- uses: rust-lang/simpleinfra/github-actions/cancel-outdated-builds@master
@@ -112,6 +113,9 @@ jobs:
112113
- name: Build
113114
run: cargo build --features deny-warnings,internal-lints
114115

116+
- name: Test "--fix -Zunstable-options"
117+
run: cargo run --features deny-warnings,internal-lints --bin cargo-clippy -- clippy --fix -Zunstable-options
118+
115119
- name: Test
116120
run: cargo test --features deny-warnings,internal-lints
117121

@@ -123,8 +127,8 @@ jobs:
123127
run: cargo test --features deny-warnings
124128
working-directory: rustc_tools_util
125129

126-
- name: Test clippy_dev
127-
run: cargo test --features deny-warnings
130+
- name: Test clippy_dev and lintcheck
131+
run: cargo test --features lintcheck,deny-warnings
128132
working-directory: clippy_dev
129133

130134
- name: Test cargo-clippy
@@ -136,6 +140,13 @@ jobs:
136140
env:
137141
OS: ${{ runner.os }}
138142

143+
- name: Test cargo dev new lint
144+
run: |
145+
cargo dev new_lint --name new_early_pass --pass early
146+
cargo dev new_lint --name new_late_pass --pass late
147+
cargo check
148+
git reset --hard HEAD
149+
139150
integration_build:
140151
needs: changelog
141152
runs-on: ubuntu-latest

clippy_dev/ci_test_sources.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[crates]
2+
cc = {name = "cc", versions = ['1.0.67']}
3+
home = {name = "home", git_url = "https://github.com/brson/home", git_hash = "32044e53dfbdcd32bafad3109d1fbab805fc0f40"}
4+
rustc_tools_util = {name = "rustc_tools_util", versions = ['0.2.0']}

clippy_dev/src/lintcheck.rs

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
// positives.
66

77
#![cfg(feature = "lintcheck")]
8-
#![allow(clippy::filter_map)]
8+
#![allow(clippy::filter_map, clippy::collapsible_else_if)]
9+
#![allow(clippy::blocks_in_if_conditions)] // FP on `if x.iter().any(|x| ...)`
910

1011
use crate::clippy_project_root;
1112

1213
use std::collections::HashMap;
1314
use std::process::Command;
1415
use std::sync::atomic::{AtomicUsize, Ordering};
15-
use std::{env, fmt, fs::write, path::PathBuf};
16+
use std::{
17+
env, fmt,
18+
fs::write,
19+
path::{Path, PathBuf},
20+
};
1621

1722
use clap::ArgMatches;
1823
use rayon::prelude::*;
@@ -196,11 +201,9 @@ impl CrateSource {
196201
if !crate_root.exists() {
197202
println!("Copying {} to {}", path.display(), copy_dest.display());
198203

199-
dir::copy(path, &copy_dest, &dir::CopyOptions::new()).expect(&format!(
200-
"Failed to copy from {}, to {}",
201-
path.display(),
202-
crate_root.display()
203-
));
204+
dir::copy(path, &copy_dest, &dir::CopyOptions::new()).unwrap_or_else(|_| {
205+
panic!("Failed to copy from {}, to {}", path.display(), crate_root.display())
206+
});
204207
} else {
205208
println!(
206209
"Not copying {} to {}, destination already exists",
@@ -225,7 +228,7 @@ impl Crate {
225228
/// issued
226229
fn run_clippy_lints(
227230
&self,
228-
cargo_clippy_path: &PathBuf,
231+
cargo_clippy_path: &Path,
229232
target_dir_index: &AtomicUsize,
230233
thread_limit: usize,
231234
total_crates_to_lint: usize,
@@ -308,13 +311,13 @@ impl LintcheckConfig {
308311
// first, check if we got anything passed via the LINTCHECK_TOML env var,
309312
// if not, ask clap if we got any value for --crates-toml <foo>
310313
// if not, use the default "clippy_dev/lintcheck_crates.toml"
311-
let sources_toml = env::var("LINTCHECK_TOML").unwrap_or(
314+
let sources_toml = env::var("LINTCHECK_TOML").unwrap_or_else(|_| {
312315
clap_config
313316
.value_of("crates-toml")
314317
.clone()
315318
.unwrap_or("clippy_dev/lintcheck_crates.toml")
316-
.to_string(),
317-
);
319+
.to_string()
320+
});
318321

319322
let sources_toml_path = PathBuf::from(sources_toml);
320323

@@ -330,7 +333,7 @@ impl LintcheckConfig {
330333
Some(threads) => {
331334
let threads: usize = threads
332335
.parse()
333-
.expect(&format!("Failed to parse '{}' to a digit", threads));
336+
.unwrap_or_else(|_| panic!("Failed to parse '{}' to a digit", threads));
334337
if threads == 0 {
335338
// automatic choice
336339
// Rayon seems to return thread count so half that for core count
@@ -387,7 +390,7 @@ fn build_clippy() {
387390
}
388391

389392
/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
390-
fn read_crates(toml_path: &PathBuf) -> Vec<CrateSource> {
393+
fn read_crates(toml_path: &Path) -> Vec<CrateSource> {
391394
let toml_content: String =
392395
std::fs::read_to_string(&toml_path).unwrap_or_else(|_| panic!("Failed to read {}", toml_path.display()));
393396
let crate_list: SourceList =
@@ -499,7 +502,10 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
499502

500503
/// check if the latest modification of the logfile is older than the modification date of the
501504
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
502-
fn lintcheck_needs_rerun(lintcheck_logs_path: &PathBuf) -> bool {
505+
fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
506+
if !lintcheck_logs_path.exists() {
507+
return true;
508+
}
503509
let clippy_modified: std::time::SystemTime = {
504510
let mut times = [CLIPPY_DRIVER_PATH, CARGO_CLIPPY_PATH].iter().map(|p| {
505511
std::fs::metadata(p)
@@ -533,15 +539,13 @@ pub fn run(clap_config: &ArgMatches) {
533539
// refresh the logs
534540
if lintcheck_needs_rerun(&config.lintcheck_results_path) {
535541
let shared_target_dir = "target/lintcheck/shared_target_dir";
536-
match std::fs::metadata(&shared_target_dir) {
537-
Ok(metadata) => {
538-
if metadata.is_dir() {
539-
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
540-
std::fs::remove_dir_all(&shared_target_dir)
541-
.expect("failed to remove target/lintcheck/shared_target_dir");
542-
}
543-
},
544-
Err(_) => { /* dir probably does not exist, don't remove anything */ },
542+
// if we get an Err here, the shared target dir probably does simply not exist
543+
if let Ok(metadata) = std::fs::metadata(&shared_target_dir) {
544+
if metadata.is_dir() {
545+
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
546+
std::fs::remove_dir_all(&shared_target_dir)
547+
.expect("failed to remove target/lintcheck/shared_target_dir");
548+
}
545549
}
546550
}
547551

@@ -660,11 +664,10 @@ pub fn run(clap_config: &ArgMatches) {
660664
}
661665

662666
/// read the previous stats from the lintcheck-log file
663-
fn read_stats_from_file(file_path: &PathBuf) -> HashMap<String, usize> {
667+
fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
664668
let file_content: String = match std::fs::read_to_string(file_path).ok() {
665669
Some(content) => content,
666670
None => {
667-
eprintln!("RETURND");
668671
return HashMap::new();
669672
},
670673
};
@@ -678,9 +681,9 @@ fn read_stats_from_file(file_path: &PathBuf) -> HashMap<String, usize> {
678681
let stats_lines = &lines[start + 1..=end - 1];
679682

680683
stats_lines
681-
.into_iter()
684+
.iter()
682685
.map(|line| {
683-
let mut spl = line.split(" ").into_iter();
686+
let mut spl = line.split(' ');
684687
(
685688
spl.next().unwrap().to_string(),
686689
spl.next().unwrap().parse::<usize>().unwrap(),
@@ -733,3 +736,30 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
733736
println!("{} {} => 0", old_key, old_value);
734737
});
735738
}
739+
740+
#[test]
741+
fn lintcheck_test() {
742+
let args = [
743+
"run",
744+
"--target-dir",
745+
"clippy_dev/target",
746+
"--package",
747+
"clippy_dev",
748+
"--bin",
749+
"clippy_dev",
750+
"--manifest-path",
751+
"clippy_dev/Cargo.toml",
752+
"--features",
753+
"lintcheck",
754+
"--",
755+
"lintcheck",
756+
"--crates-toml",
757+
"clippy_dev/ci_test_sources.toml",
758+
];
759+
let status = std::process::Command::new("cargo")
760+
.args(&args)
761+
.current_dir("../" /* repo root */)
762+
.status();
763+
764+
assert!(status.unwrap().success());
765+
}

lintcheck-logs/lintcheck_crates_logs.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
clippy 0.1.52 (70d952e75 2021-02-28)
1+
clippy 0.1.52 (3c72f0b53 2021-03-02)
22

33
target/lintcheck/sources/anyhow-1.0.38/build.rs:1:null clippy::cargo_common_metadata "package `anyhow` is missing `package.keywords` metadata"
44
target/lintcheck/sources/anyhow-1.0.38/src/error.rs:350:5 clippy::missing_panics_doc "docs for function which may panic missing `# Panics` section"
@@ -99,6 +99,7 @@ target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:1:null clippy::multi
9999
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:1:null clippy::multiple_crate_versions "multiple versions for dependency `hex`: 0.3.2, 0.4.0"
100100
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:1:null clippy::multiple_crate_versions "multiple versions for dependency `humantime`: 1.3.0, 2.0.0"
101101
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:72:22 clippy::redundant_closure_for_method_calls "redundant closure found"
102+
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:79:40 clippy::manual_map "manual implementation of `Option::map`"
102103
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:94:13 clippy::match_wildcard_for_single_variants "wildcard match will miss any future added variants"
103104
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:96:41 clippy::redundant_closure_for_method_calls "redundant closure found"
104105
target/lintcheck/sources/cargo-0.49.0/src/bin/cargo/main.rs:98:60 clippy::redundant_closure_for_method_calls "redundant closure found"
@@ -1208,6 +1209,7 @@ target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/mod.rs:689:20 clippy
12081209
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/mod.rs:699:5 clippy::fn_params_excessive_bools "more than 3 bools in function parameters"
12091210
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/mod.rs:699:5 clippy::missing_errors_doc "docs for function returning `Result` missing `# Errors` section"
12101211
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/mod.rs:719:58 clippy::redundant_closure_for_method_calls "redundant closure found"
1212+
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/mod.rs:748:30 clippy::manual_map "manual implementation of `Option::map`"
12111213
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/mod.rs:816:5 clippy::missing_errors_doc "docs for function returning `Result` missing `# Errors` section"
12121214
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/path.rs:10:1 clippy::module_name_repetitions "item name ends with its containing module's name"
12131215
target/lintcheck/sources/cargo-0.49.0/src/cargo/util/config/path.rs:14:5 clippy::must_use_candidate "this method could have a `#[must_use]` attribute"
@@ -1463,6 +1465,7 @@ target/lintcheck/sources/cfg-expr-0.7.1/src/expr/mod.rs:464:5 clippy::missing_pa
14631465
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/mod.rs:57:13 clippy::enum_glob_use "usage of wildcard import for enum variants"
14641466
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/mod.rs:586:33 clippy::match_same_arms "this `match` has identical arm bodies"
14651467
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/mod.rs:599:32 clippy::match_same_arms "this `match` has identical arm bodies"
1468+
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/mod.rs:609:9 clippy::manual_map "manual implementation of `Option::map`"
14661469
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/parser.rs:116:31 clippy::similar_names "binding's name is too similar to existing binding"
14671470
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/parser.rs:124:36 clippy::similar_names "binding's name is too similar to existing binding"
14681471
target/lintcheck/sources/cfg-expr-0.7.1/src/expr/parser.rs:17:5 clippy::missing_errors_doc "docs for function returning `Result` missing `# Errors` section"
@@ -3509,6 +3512,7 @@ clippy::filter_map_next 3
35093512
clippy::fn_params_excessive_bools 3
35103513
clippy::if_same_then_else 3
35113514
clippy::inconsistent_struct_constructor 3
3515+
clippy::manual_map 3
35123516
clippy::mut_mut 3
35133517
clippy::ptr_arg 3
35143518
clippy::zero_ptr 3

0 commit comments

Comments
 (0)