Skip to content

Commit 417751e

Browse files
committed
Merge branch 'master' into new-lint-bytes-count-to-len
2 parents 20ca570 + 38ba055 commit 417751e

File tree

572 files changed

+17346
-7514
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

572 files changed

+17346
-7514
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ body:
1818
id: reproducer
1919
attributes:
2020
label: Reproducer
21-
description: Please provide the code and steps to repoduce the bug
21+
description: Please provide the code and steps to reproduce the bug
2222
value: |
2323
I tried this code:
2424

.github/ISSUE_TEMPLATE/ice.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ body:
1010
attributes:
1111
label: Summary
1212
description: |
13-
If possible, try to provide a minimal verifiable example. You can read ["Rust Bug Minimization Patterns"][mve] for how to create smaller examples. Otherwise, provide the crate where the ICE occured.
13+
If possible, try to provide a minimal verifiable example. You can read ["Rust Bug Minimization Patterns"][mve] for how to create smaller examples. Otherwise, provide the crate where the ICE occurred.
1414
1515
[mve]: http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
1616
validations:

.github/workflows/clippy.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,3 @@ jobs:
7474
run: bash .github/driver.sh
7575
env:
7676
OS: ${{ runner.os }}
77-
78-
- name: Test cargo dev new lint
79-
run: |
80-
cargo dev new_lint --name new_early_pass --pass early
81-
cargo dev new_lint --name new_late_pass --pass late
82-
cargo check
83-
git reset --hard HEAD

.github/workflows/clippy_bors.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ jobs:
143143
env:
144144
OS: ${{ runner.os }}
145145

146-
- name: Test cargo dev new lint
147-
run: |
148-
cargo dev new_lint --name new_early_pass --pass early
149-
cargo dev new_lint --name new_late_pass --pass late
150-
cargo check
151-
git reset --hard HEAD
152-
153146
integration_build:
154147
needs: changelog
155148
runs-on: ubuntu-latest

.github/workflows/clippy_dev.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ jobs:
3636
- name: Test fmt
3737
run: cargo dev fmt --check
3838

39+
- name: Test cargo dev new lint
40+
run: |
41+
cargo dev new_lint --name new_early_pass --pass early
42+
cargo dev new_lint --name new_late_pass --pass late
43+
cargo check
44+
git reset --hard HEAD
45+
3946
# These jobs doesn't actually test anything, but they're only used to tell
4047
# bors the build completed, as there is no practical way to detect when a
4148
# workflow is successful listening to webhooks only.

CHANGELOG.md

Lines changed: 333 additions & 7 deletions
Large diffs are not rendered by default.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.60"
3+
version = "0.1.62"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -21,13 +21,12 @@ name = "clippy-driver"
2121
path = "src/driver.rs"
2222

2323
[dependencies]
24-
clippy_lints = { version = "0.1", path = "clippy_lints" }
24+
clippy_lints = { path = "clippy_lints" }
2525
semver = "1.0"
26-
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }
26+
rustc_tools_util = { path = "rustc_tools_util" }
2727
tempfile = { version = "3.2", optional = true }
2828

2929
[dev-dependencies]
30-
cargo_metadata = "0.14"
3130
compiletest_rs = { version = "0.7.1", features = ["tmp"] }
3231
tester = "0.9"
3332
regex = "1.5"
@@ -43,13 +42,14 @@ rustc-workspace-hack = "1.0"
4342
clippy_utils = { path = "clippy_utils" }
4443
derive-new = "0.5"
4544
if_chain = "1.0"
46-
itertools = "0.10"
45+
itertools = "0.10.1"
4746
quote = "1.0"
48-
serde = { version = "1.0", features = ["derive"] }
47+
serde = { version = "1.0.125", features = ["derive"] }
4948
syn = { version = "1.0", features = ["full"] }
5049
futures = "0.3"
5150
parking_lot = "0.11.2"
5251
tokio = { version = "1", features = ["io-util"] }
52+
rustc-semver = "1.1"
5353

5454
[build-dependencies]
5555
rustc_tools_util = { version = "0.2", path = "rustc_tools_util" }

clippy_dev/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ version = "0.0.1"
44
edition = "2021"
55

66
[dependencies]
7-
bytecount = "0.6"
87
clap = "2.33"
98
indoc = "1.0"
10-
itertools = "0.10"
9+
itertools = "0.10.1"
1110
opener = "0.5"
12-
regex = "1.5"
1311
shell-escape = "0.1"
12+
tempfile = "3.3"
1413
walkdir = "2.3"
15-
cargo_metadata = "0.14"
1614

1715
[features]
1816
deny-warnings = []
17+
18+
[package.metadata.rust-analyzer]
19+
# This package uses #[feature(rustc_private)]
20+
rustc_private = true

clippy_dev/src/bless.rs

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,39 @@
11
//! `bless` updates the reference files in the repo with changed output files
22
//! from the last test run.
33
4+
use crate::cargo_clippy_path;
45
use std::ffi::OsStr;
56
use std::fs;
67
use std::lazy::SyncLazy;
78
use std::path::{Path, PathBuf};
8-
use walkdir::WalkDir;
9+
use walkdir::{DirEntry, WalkDir};
910

10-
use crate::clippy_project_root;
11-
12-
#[cfg(not(windows))]
13-
static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
14-
#[cfg(windows)]
15-
static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe";
16-
17-
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> = SyncLazy::new(|| {
18-
let mut path = std::env::current_exe().unwrap();
19-
path.set_file_name(CARGO_CLIPPY_EXE);
20-
fs::metadata(path).ok()?.modified().ok()
21-
});
11+
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> =
12+
SyncLazy::new(|| cargo_clippy_path().metadata().ok()?.modified().ok());
2213

2314
/// # Panics
2415
///
2516
/// Panics if the path to a test file is broken
2617
pub fn bless(ignore_timestamp: bool) {
27-
let test_suite_dirs = [
28-
clippy_project_root().join("tests").join("ui"),
29-
clippy_project_root().join("tests").join("ui-internal"),
30-
clippy_project_root().join("tests").join("ui-toml"),
31-
clippy_project_root().join("tests").join("ui-cargo"),
32-
];
33-
for test_suite_dir in &test_suite_dirs {
34-
WalkDir::new(test_suite_dir)
35-
.into_iter()
36-
.filter_map(Result::ok)
37-
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
38-
.for_each(|f| {
39-
let test_name = f.path().strip_prefix(test_suite_dir).unwrap();
40-
for &ext in &["stdout", "stderr", "fixed"] {
41-
let test_name_ext = format!("stage-id.{}", ext);
42-
update_reference_file(
43-
f.path().with_extension(ext),
44-
test_name.with_extension(test_name_ext),
45-
ignore_timestamp,
46-
);
47-
}
48-
});
49-
}
18+
let extensions = ["stdout", "stderr", "fixed"].map(OsStr::new);
19+
20+
WalkDir::new(build_dir())
21+
.into_iter()
22+
.map(Result::unwrap)
23+
.filter(|entry| entry.path().extension().map_or(false, |ext| extensions.contains(&ext)))
24+
.for_each(|entry| update_reference_file(&entry, ignore_timestamp));
5025
}
5126

52-
fn update_reference_file(reference_file_path: PathBuf, test_name: PathBuf, ignore_timestamp: bool) {
53-
let test_output_path = build_dir().join(test_name);
54-
let relative_reference_file_path = reference_file_path.strip_prefix(clippy_project_root()).unwrap();
27+
fn update_reference_file(test_output_entry: &DirEntry, ignore_timestamp: bool) {
28+
let test_output_path = test_output_entry.path();
5529

56-
// If compiletest did not write any changes during the test run,
57-
// we don't have to update anything
58-
if !test_output_path.exists() {
59-
return;
60-
}
30+
let reference_file_name = test_output_entry.file_name().to_str().unwrap().replace(".stage-id", "");
31+
let reference_file_path = Path::new("tests")
32+
.join(test_output_path.strip_prefix(build_dir()).unwrap())
33+
.with_file_name(reference_file_name);
6134

6235
// If the test output was not updated since the last clippy build, it may be outdated
63-
if !ignore_timestamp && !updated_since_clippy_build(&test_output_path).unwrap_or(true) {
36+
if !ignore_timestamp && !updated_since_clippy_build(test_output_entry).unwrap_or(true) {
6437
return;
6538
}
6639

@@ -69,23 +42,14 @@ fn update_reference_file(reference_file_path: PathBuf, test_name: PathBuf, ignor
6942

7043
if test_output_file != reference_file {
7144
// If a test run caused an output file to change, update the reference file
72-
println!("updating {}", &relative_reference_file_path.display());
45+
println!("updating {}", reference_file_path.display());
7346
fs::copy(test_output_path, &reference_file_path).expect("Could not update reference file");
74-
75-
// We need to re-read the file now because it was potentially updated from copying
76-
let reference_file = fs::read(&reference_file_path).unwrap_or_default();
77-
78-
if reference_file.is_empty() {
79-
// If we copied over an empty output file, we remove the now empty reference file
80-
println!("removing {}", &relative_reference_file_path.display());
81-
fs::remove_file(reference_file_path).expect("Could not remove reference file");
82-
}
8347
}
8448
}
8549

86-
fn updated_since_clippy_build(path: &Path) -> Option<bool> {
50+
fn updated_since_clippy_build(entry: &DirEntry) -> Option<bool> {
8751
let clippy_build_time = (*CLIPPY_BUILD_TIME)?;
88-
let modified = fs::metadata(path).ok()?.modified().ok()?;
52+
let modified = entry.metadata().ok()?.modified().ok()?;
8953
Some(modified >= clippy_build_time)
9054
}
9155

clippy_dev/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#![feature(let_else)]
12
#![feature(once_cell)]
3+
#![feature(rustc_private)]
24
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
35
// warn on lints, that are included in `rust-lang/rust`s bootstrap
46
#![warn(rust_2018_idioms, unused_lifetimes)]
57

8+
extern crate rustc_lexer;
9+
610
use std::path::PathBuf;
711

812
pub mod bless;
@@ -13,6 +17,19 @@ pub mod serve;
1317
pub mod setup;
1418
pub mod update_lints;
1519

20+
#[cfg(not(windows))]
21+
static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
22+
#[cfg(windows)]
23+
static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe";
24+
25+
/// Returns the path to the `cargo-clippy` binary
26+
#[must_use]
27+
pub fn cargo_clippy_path() -> PathBuf {
28+
let mut path = std::env::current_exe().expect("failed to get current executable name");
29+
path.set_file_name(CARGO_CLIPPY_EXE);
30+
path
31+
}
32+
1633
/// Returns the path to the Clippy project directory
1734
///
1835
/// # Panics

0 commit comments

Comments
 (0)