Skip to content

Commit e368355

Browse files
committed
Auto merge of #6849 - flip1995:dogfood-fix, r=matthiaskrgr
Dogfood and CI fixes The CI fix is practically #6829 rebased and squashed into one commit Dogfood fix is a follow up of #6802 r? `@matthiaskrgr` for lintcheck changes (best reviewed with whitespace changes hidden) changelog: none
2 parents f0e6ce8 + 74eb448 commit e368355

File tree

10 files changed

+160
-126
lines changed

10 files changed

+160
-126
lines changed

.github/workflows/clippy.yml

Lines changed: 5 additions & 3 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:
@@ -50,9 +51,6 @@ jobs:
5051
- name: Build
5152
run: cargo build --features deny-warnings,internal-lints
5253

53-
- name: Test "--fix -Zunstable-options"
54-
run: cargo run --features deny-warnings,internal-lints --bin cargo-clippy -- clippy --fix -Zunstable-options
55-
5654
- name: Test
5755
run: cargo test --features deny-warnings,internal-lints
5856

@@ -72,6 +70,10 @@ jobs:
7270
run: ../target/debug/cargo-clippy
7371
working-directory: clippy_workspace_tests
7472

73+
- name: Test cargo-clippy --fix
74+
run: ../target/debug/cargo-clippy clippy --fix -Zunstable-options
75+
working-directory: clippy_workspace_tests
76+
7577
- name: Test clippy-driver
7678
run: bash .github/driver.sh
7779
env:

.github/workflows/clippy_bors.yml

Lines changed: 12 additions & 0 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
@@ -131,11 +132,22 @@ jobs:
131132
run: ../target/debug/cargo-clippy
132133
working-directory: clippy_workspace_tests
133134

135+
- name: Test cargo-clippy --fix
136+
run: ../target/debug/cargo-clippy clippy --fix -Zunstable-options
137+
working-directory: clippy_workspace_tests
138+
134139
- name: Test clippy-driver
135140
run: bash .github/driver.sh
136141
env:
137142
OS: ${{ runner.os }}
138143

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

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: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
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

13-
use std::collections::HashMap;
1412
use std::process::Command;
1513
use std::sync::atomic::{AtomicUsize, Ordering};
14+
use std::{collections::HashMap, io::ErrorKind};
1615
use std::{
1716
env, fmt,
1817
fs::write,
@@ -116,9 +115,7 @@ 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+
create_dirs(&krate_download_dir, &extract_dir);
122119

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

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 {
198+
if crate_root.exists() {
208199
println!(
209200
"Not copying {} to {}, destination already exists",
210201
path.display(),
211202
crate_root.display()
212203
);
204+
} else {
205+
println!("Copying {} to {}", path.display(), copy_dest.display());
206+
207+
dir::copy(path, &copy_dest, &dir::CopyOptions::new()).unwrap_or_else(|_| {
208+
panic!("Failed to copy from {}, to {}", path.display(), crate_root.display())
209+
});
213210
}
214211

215212
Crate {
@@ -236,8 +233,8 @@ impl Crate {
236233
// advance the atomic index by one
237234
let index = target_dir_index.fetch_add(1, Ordering::SeqCst);
238235
// "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;
236+
let thread_index = index % thread_limit;
237+
let perc = (index * 100) / total_crates_to_lint;
241238

242239
if thread_limit == 1 {
243240
println!(
@@ -247,7 +244,7 @@ impl Crate {
247244
} else {
248245
println!(
249246
"{}/{} {}% Linting {} {} in target dir {:?}",
250-
index, total_crates_to_lint, perc, &self.name, &self.version, target_dir_index
247+
index, total_crates_to_lint, perc, &self.name, &self.version, thread_index
251248
);
252249
}
253250

@@ -269,7 +266,7 @@ impl Crate {
269266
// use the looping index to create individual target dirs
270267
.env(
271268
"CARGO_TARGET_DIR",
272-
shared_target_dir.join(format!("_{:?}", target_dir_index)),
269+
shared_target_dir.join(format!("_{:?}", thread_index)),
273270
)
274271
// lint warnings will look like this:
275272
// src/cargo/ops/cargo_compile.rs:127:35: warning: usage of `FromIterator::from_iter`
@@ -529,6 +526,10 @@ fn lintcheck_needs_rerun(lintcheck_logs_path: &Path) -> bool {
529526
}
530527

531528
/// lintchecks `main()` function
529+
///
530+
/// # Panics
531+
///
532+
/// This function panics if the clippy binaries don't exist.
532533
pub fn run(clap_config: &ArgMatches) {
533534
let config = LintcheckConfig::from_clap(clap_config);
534535

@@ -579,9 +580,9 @@ pub fn run(clap_config: &ArgMatches) {
579580
// if we don't have the specified crate in the .toml, throw an error
580581
if !crates.iter().any(|krate| {
581582
let name = match krate {
582-
CrateSource::CratesIo { name, .. } => name,
583-
CrateSource::Git { name, .. } => name,
584-
CrateSource::Path { name, .. } => name,
583+
CrateSource::CratesIo { name, .. } | CrateSource::Git { name, .. } | CrateSource::Path { name, .. } => {
584+
name
585+
},
585586
};
586587
name == only_one_crate
587588
}) {
@@ -597,8 +598,7 @@ pub fn run(clap_config: &ArgMatches) {
597598
.into_iter()
598599
.map(|krate| krate.download_and_extract())
599600
.filter(|krate| krate.name == only_one_crate)
600-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1))
601-
.flatten()
601+
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, 1))
602602
.collect()
603603
} else {
604604
if config.max_jobs > 1 {
@@ -621,17 +621,15 @@ pub fn run(clap_config: &ArgMatches) {
621621
crates
622622
.into_par_iter()
623623
.map(|krate| krate.download_and_extract())
624-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates))
625-
.flatten()
624+
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, num_cpus, num_crates))
626625
.collect()
627626
} else {
628627
// run sequential
629628
let num_crates = crates.len();
630629
crates
631630
.into_iter()
632631
.map(|krate| krate.download_and_extract())
633-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates))
634-
.flatten()
632+
.flat_map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates))
635633
.collect()
636634
}
637635
};
@@ -646,7 +644,7 @@ pub fn run(clap_config: &ArgMatches) {
646644
.map(|w| (&w.crate_name, &w.message))
647645
.collect();
648646

649-
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(|warning| warning.to_string()).collect();
647+
let mut all_msgs: Vec<String> = clippy_warnings.iter().map(ToString::to_string).collect();
650648
all_msgs.sort();
651649
all_msgs.push("\n\n\n\nStats:\n".into());
652650
all_msgs.push(stats_formatted);
@@ -673,13 +671,13 @@ fn read_stats_from_file(file_path: &Path) -> HashMap<String, usize> {
673671
},
674672
};
675673

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

678676
// search for the beginning "Stats:" and the end "ICEs:" of the section we want
679677
let start = lines.iter().position(|line| line == "Stats:").unwrap();
680678
let end = lines.iter().position(|line| line == "ICEs:").unwrap();
681679

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

684682
stats_lines
685683
.iter()
@@ -738,6 +736,29 @@ fn print_stats(old_stats: HashMap<String, usize>, new_stats: HashMap<&String, us
738736
});
739737
}
740738

739+
/// Create necessary directories to run the lintcheck tool.
740+
///
741+
/// # Panics
742+
///
743+
/// This function panics if creating one of the dirs fails.
744+
fn create_dirs(krate_download_dir: &Path, extract_dir: &Path) {
745+
std::fs::create_dir("target/lintcheck/").unwrap_or_else(|err| {
746+
if err.kind() != ErrorKind::AlreadyExists {
747+
panic!("cannot create lintcheck target dir");
748+
}
749+
});
750+
std::fs::create_dir(&krate_download_dir).unwrap_or_else(|err| {
751+
if err.kind() != ErrorKind::AlreadyExists {
752+
panic!("cannot create crate download dir");
753+
}
754+
});
755+
std::fs::create_dir(&extract_dir).unwrap_or_else(|err| {
756+
if err.kind() != ErrorKind::AlreadyExists {
757+
panic!("cannot create crate extraction dir");
758+
}
759+
});
760+
}
761+
741762
#[test]
742763
fn lintcheck_test() {
743764
let args = [

clippy_lints/src/transmute/transmute_int_to_char.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,26 @@ pub(super) fn check<'tcx>(
1717
) -> bool {
1818
match (&from_ty.kind(), &to_ty.kind()) {
1919
(ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => {
20-
{
21-
span_lint_and_then(
22-
cx,
23-
TRANSMUTE_INT_TO_CHAR,
24-
e.span,
25-
&format!("transmute from a `{}` to a `char`", from_ty),
26-
|diag| {
27-
let arg = sugg::Sugg::hir(cx, &args[0], "..");
28-
let arg = if let ty::Int(_) = from_ty.kind() {
29-
arg.as_ty(ast::UintTy::U32.name_str())
30-
} else {
31-
arg
32-
};
33-
diag.span_suggestion(
34-
e.span,
35-
"consider using",
36-
format!("std::char::from_u32({}).unwrap()", arg.to_string()),
37-
Applicability::Unspecified,
38-
);
39-
},
40-
)
41-
};
20+
span_lint_and_then(
21+
cx,
22+
TRANSMUTE_INT_TO_CHAR,
23+
e.span,
24+
&format!("transmute from a `{}` to a `char`", from_ty),
25+
|diag| {
26+
let arg = sugg::Sugg::hir(cx, &args[0], "..");
27+
let arg = if let ty::Int(_) = from_ty.kind() {
28+
arg.as_ty(ast::UintTy::U32.name_str())
29+
} else {
30+
arg
31+
};
32+
diag.span_suggestion(
33+
e.span,
34+
"consider using",
35+
format!("std::char::from_u32({}).unwrap()", arg.to_string()),
36+
Applicability::Unspecified,
37+
);
38+
},
39+
);
4240
true
4341
},
4442
_ => false,

clippy_lints/src/transmute/transmute_ptr_to_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(
1717
qpath: &'tcx QPath<'_>,
1818
) -> bool {
1919
match (&from_ty.kind(), &to_ty.kind()) {
20-
(ty::RawPtr(from_pty), ty::Ref(_, to_ref_ty, mutbl)) => {
20+
(ty::RawPtr(from_ptr_ty), ty::Ref(_, to_ref_ty, mutbl)) => {
2121
span_lint_and_then(
2222
cx,
2323
TRANSMUTE_PTR_TO_REF,
@@ -34,7 +34,7 @@ pub(super) fn check<'tcx>(
3434
("&*", "*const")
3535
};
3636

37-
let arg = if from_pty.ty == *to_ref_ty {
37+
let arg = if from_ptr_ty.ty == *to_ref_ty {
3838
arg
3939
} else {
4040
arg.as_ty(&format!("{} {}", cast, get_type_snippet(cx, qpath, to_ref_ty)))

0 commit comments

Comments
 (0)