Skip to content

Commit c46a051

Browse files
committed
Fix dogfood errors in clippy_dev
1 parent 1d71d9a commit c46a051

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

clippy_dev/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ fn test_gen_deprecated() {
530530
#[should_panic]
531531
fn test_gen_deprecated_fail() {
532532
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
533-
let _ = gen_deprecated(lints.iter());
533+
let _deprecated_lints = gen_deprecated(lints.iter());
534534
}
535535

536536
#[test]

clippy_dev/src/lintcheck.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

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

1110
use crate::clippy_project_root;
1211

@@ -116,9 +115,9 @@ impl CrateSource {
116115
// url to download the crate from crates.io
117116
let url = format!("https://crates.io/api/v1/crates/{}/{}/download", name, version);
118117
println!("Downloading and extracting {} {} from {}", name, version, url);
119-
let _ = std::fs::create_dir("target/lintcheck/");
120-
let _ = std::fs::create_dir(&krate_download_dir);
121-
let _ = std::fs::create_dir(&extract_dir);
118+
std::fs::create_dir("target/lintcheck/").expect("cannot create lintcheck target dir");
119+
std::fs::create_dir(&krate_download_dir).expect("cannot create crate download dir");
120+
std::fs::create_dir(&extract_dir).expect("cannot create crate extraction dir");
122121

123122
let krate_file_path = krate_download_dir.join(format!("{}-{}.crate.tar.gz", name, version));
124123
// don't download/extract if we already have done so
@@ -198,18 +197,18 @@ impl CrateSource {
198197
// the source path of the crate we copied, ${copy_dest}/crate_name
199198
let crate_root = copy_dest.join(name); // .../crates/local_crate
200199

201-
if !crate_root.exists() {
202-
println!("Copying {} to {}", path.display(), copy_dest.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-
});
207-
} else {
200+
if crate_root.exists() {
208201
println!(
209202
"Not copying {} to {}, destination already exists",
210203
path.display(),
211204
crate_root.display()
212205
);
206+
} else {
207+
println!("Copying {} to {}", path.display(), copy_dest.display());
208+
209+
dir::copy(path, &copy_dest, &dir::CopyOptions::new()).unwrap_or_else(|_| {
210+
panic!("Failed to copy from {}, to {}", path.display(), crate_root.display())
211+
});
213212
}
214213

215214
Crate {
@@ -236,8 +235,8 @@ impl Crate {
236235
// advance the atomic index by one
237236
let index = target_dir_index.fetch_add(1, Ordering::SeqCst);
238237
// "loop" the index within 0..thread_limit
239-
let target_dir_index = index % thread_limit;
240-
let perc = ((index * 100) as f32 / total_crates_to_lint as f32) as u8;
238+
let thread_index = index % thread_limit;
239+
let perc = (index * 100) / total_crates_to_lint;
241240

242241
if thread_limit == 1 {
243242
println!(
@@ -247,7 +246,7 @@ impl Crate {
247246
} else {
248247
println!(
249248
"{}/{} {}% Linting {} {} in target dir {:?}",
250-
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index
249+
index, total_crates_to_lint, perc, &self.name, &self.version, thread_index
251250
);
252251
}
253252

@@ -269,7 +268,7 @@ impl Crate {
269268
// use the looping index to create individual target dirs
270269
.env(
271270
"CARGO_TARGET_DIR",
272-
shared_target_dir.join(format!("_{:?}", target_dir_index)),
271+
shared_target_dir.join(format!("_{:?}", thread_index)),
273272
)
274273
// lint warnings will look like this:
275274
// src/cargo/ops/cargo_compile.rs:127:35: warning: usage of `FromIterator::from_iter`
@@ -529,6 +528,10 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
529528
}
530529

531530
/// lintchecks `main()` function
531+
///
532+
/// # Panics
533+
///
534+
/// This function panics if the clippy binaries don't exist.
532535
pub fn run(clap_config: &ArgMatches) {
533536
let config = LintcheckConfig::from_clap(clap_config);
534537

@@ -579,9 +582,9 @@ pub fn run(clap_config: &ArgMatches) {
579582
// if we don't have the specified crate in the .toml, throw an error
580583
if !crates.iter().any(|krate| {
581584
let name = match krate {
582-
CrateSource::CratesIo { name, .. } => name,
583-
CrateSource::Git { name, .. } => name,
584-
CrateSource::Path { name, .. } => name,
585+
CrateSource::CratesIo { name, .. } | CrateSource::Git { name, .. } | CrateSource::Path { name, .. } => {
586+
name
587+
},
585588
};
586589
name == only_one_crate
587590
}) {
@@ -597,8 +600,7 @@ pub fn run(clap_config: &ArgMatches) {
597600
.into_iter()
598601
.map(|krate| krate.download_and_extract())
599602
.filter(|krate| krate.name == only_one_crate)
600-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1))
601-
.flatten()
603+
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1))
602604
.collect()
603605
} else {
604606
if config.max_jobs > 1 {
@@ -621,17 +623,15 @@ pub fn run(clap_config: &ArgMatches) {
621623
crates
622624
.into_par_iter()
623625
.map(|krate| krate.download_and_extract())
624-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates))
625-
.flatten()
626+
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates))
626627
.collect()
627628
} else {
628629
// run sequential
629630
let num_crates = crates.len();
630631
crates
631632
.into_iter()
632633
.map(|krate| krate.download_and_extract())
633-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates))
634-
.flatten()
634+
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates))
635635
.collect()
636636
}
637637
};
@@ -646,7 +646,7 @@ pub fn run(clap_config: &ArgMatches) {
646646
.map(|w| (&w.crate_name, &w.message))
647647
.collect();
648648

649-
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(|warning| warning.to_string()).collect();
649+
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(ToString::to_string).collect();
650650
all_msgs.sort();
651651
all_msgs.push("\n\n\n\nStats:\n".into());
652652
all_msgs.push(stats_formatted);
@@ -673,13 +673,13 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
673673
},
674674
};
675675

676-
let lines: Vec<String> = file_content.lines().map(|l| l.to_string()).collect();
676+
let lines: Vec<String> = file_content.lines().map(ToString::to_string).collect();
677677

678678
// search for the beginning "Stats:" and the end "ICEs:" of the section we want
679679
let start = lines.iter().position(|line| line == "Stats:").unwrap();
680680
let end = lines.iter().position(|line| line == "ICEs:").unwrap();
681681

682-
let stats_lines = &lines[start + 1..=end - 1];
682+
let stats_lines = &lines[start + 1..end];
683683

684684
stats_lines
685685
.iter()

0 commit comments

Comments
 (0)