Skip to content

Clippy subtree update #141814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 82 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ae0e3b7
Default `trivial_copy_size_limit` to the width of a target pointer
Alexendoo Apr 2, 2025
565cf5a
Optimize documentation lints **a lot** (1/2)
blyxyas Apr 25, 2025
38d2387
Simplify `is_simple_break_expr`
samueltardieu May 8, 2025
d14c6f2
Include `let` assignment in suggestion
samueltardieu May 8, 2025
f3bad7f
do away with `_Self` and `TraitName` and check generic params for rus…
mejrs May 17, 2025
e5617a7
fix: `needless_for_each` suggests wrongly when closure has no braces
profetia May 5, 2025
520cb09
Apply `needless_for_each` to clippy itself
profetia May 18, 2025
7debaf6
Merge commit 'cadf98bb7d783e2ea3572446c3f80d3592ec5f86' into clippy-s…
flip1995 May 21, 2025
f1ad1cd
Support different lintcheck CARGO_TARGET_DIR
blyxyas May 21, 2025
544c300
Improve speed of `cargo dev fmt`.
Jarcho May 21, 2025
106ac79
Add `expect_action` helper to `clippy_dev`
Jarcho May 21, 2025
9fa448a
Make `trivial-copy-size-limit` consistently the size of the target po…
Jarcho May 21, 2025
3da4c10
Improve speed of `cargo dev fmt` (#14862)
samueltardieu May 21, 2025
acff5d3
Review comments & Add testing
blyxyas May 21, 2025
a6e40fa
[Perf] Optimize documentation lints **a lot** (1/2) (18% -> 10%) (#14…
Jarcho May 21, 2025
a0760cf
Rename `kw::Empty` as `sym::empty`.
nnethercote May 22, 2025
7e5c819
Rollup merge of #141130 - mejrs:use_self, r=compiler-errors
matthiaskrgr May 22, 2025
5dccb10
Fix `needless_for_each` suggests wrongly when closure has no braces (…
blyxyas May 22, 2025
0a059d9
`needless_borrow`: do not contradict `dangerous_implicit_autorefs`
samueltardieu May 14, 2025
6059d59
Properly analyze captures from unsafe binders
compiler-errors May 23, 2025
c364717
`needless_return`: look inside `else if` parts as well
samueltardieu May 13, 2025
09c50a4
Rollup merge of #141376 - nnethercote:rename-kw-Empty, r=petrochenkov
matthiaskrgr May 23, 2025
7ab910f
`needless_borrow`: do not contradict `dangerous_implicit_autorefs` (#…
blyxyas May 23, 2025
4a7598f
[HEAVY PERF] Optimize documentation lints 2/2
blyxyas May 22, 2025
1029572
Optimize documentation lints **a lot** (2/2) (7.5% -> 1%) (#14870)
Jarcho May 24, 2025
e3adf14
Remove compiletest headers test
Alexendoo May 24, 2025
836c657
Remove compiletest headers test (#14884)
llogiq May 24, 2025
24a2a66
Support different lintcheck CARGO_TARGET_DIR env variables (#14859)
dswij May 24, 2025
03af373
fix: `assign_op_pattern` FP on unstable const trait
profetia May 24, 2025
843a45f
Consider consts in patterns as refutable
Alexendoo May 24, 2025
b6b97a7
Fix `assign_op_pattern` FP on unstable const trait (#14886)
llogiq May 24, 2025
f674c80
Update `askama` to `0.14.0` version
GuillaumeGomez May 24, 2025
6291b91
docs(trait_checking): import the right function
ada4a May 25, 2025
7ffc886
fix: `manual_find` suggests wrongly when return type needs adjustment
profetia May 25, 2025
c12bc22
Update `askama` to `0.14.0` version (#14888)
samueltardieu May 25, 2025
aa667f4
use the correct path to the function
ada4a May 25, 2025
954034b
Fix `manual_find` suggests wrongly when return type needs adjustment …
dswij May 25, 2025
93a509f
exhaustive match instead of returns
ada4a May 25, 2025
b72cb48
use ?
ada4a May 25, 2025
f04eb59
use if-let
ada4a May 25, 2025
028e1c2
use let-chains
ada4a May 25, 2025
c256bcc
refactor(mut_reference): replace `match` with `if-let` to reduce nesting
ada4a May 25, 2025
32a3744
refactor(mut_reference): replace `match` with `if-let` to reduce nest…
y21 May 26, 2025
8cced0f
Show total count lints
alex-semenyuk May 26, 2025
816fa0a
changelog: [manual_flatten]: fix with nested Some or Ok pattern
a-yossy May 19, 2025
ce0adf0
Rollup merge of #141433 - compiler-errors:unsafe-binder-captures, r=o…
jieyouxu May 26, 2025
b719f99
Consider consts in patterns as refutable (#14887)
y21 May 26, 2025
3927a61
[`manual_flatten`]: Fix with nested `Some` or `Ok` pattern (#14846)
Alexendoo May 26, 2025
763a7bd
Extend `manual_is_variant_and` lint to check for boolean `map` compar…
GuillaumeGomez Apr 17, 2025
634f875
Add regression test for `manual_is_variant_and` extension
GuillaumeGomez Apr 17, 2025
327967c
Rename unpack to kind
compiler-errors May 24, 2025
cb27c8a
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.
nnethercote May 27, 2025
013ab6c
Use `builin_index` instead of hand-rolling it
oli-obk May 26, 2025
551870d
Extend `manual_is_variant_and lint` to check for boolean map comparis…
samueltardieu May 28, 2025
1d903b6
Stabilise `repr128`
beetrees Mar 9, 2025
402fc81
Update trait_checking.md
donkomura May 28, 2025
854a0b6
Mark myself as on vacation until June 30
blyxyas May 28, 2025
a31d3b0
Mark myself as on vacation until June 30 (#14909)
blyxyas May 28, 2025
291b8fd
[book] fix the trait checking example code (#14908)
flip1995 May 28, 2025
3a1159e
`needless_return`: look inside `else if` parts as well (#14798)
blyxyas May 28, 2025
7e590de
Optimize `unit_return_expecting_ord`
blyxyas May 27, 2025
b90880d
Optimize `unit_return_expecting_ord` (#14905)
samueltardieu May 28, 2025
beaf155
`while_let_loop`: Include `let` assignment in suggestion (#14756)
Jarcho May 28, 2025
eeb4fa4
Rollup merge of #141638 - oli-obk:builtin-index, r=lcnr
jhpratt May 29, 2025
f7a97cc
Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-dead
jhpratt May 29, 2025
660aede
Auto merge of #141717 - jhpratt:rollup-neu8nzl, r=jhpratt
bors May 29, 2025
e34368b
Improve wording of `manual_contains` docs
eopb May 29, 2025
6275f52
Improve wording of `manual_contains` docs (#14917)
samueltardieu May 29, 2025
77f4e00
Show total count lints (#14901)
samueltardieu May 30, 2025
1822006
clean-up `modulo_arithmetic` (#14898)
samueltardieu May 30, 2025
af5b6e8
docs(trait_checking): import the right function (#14891)
samueltardieu May 30, 2025
b283ea3
Corrected code comments
relaxcn May 30, 2025
10ec6fc
Correct code comments (#14920)
samueltardieu May 30, 2025
bb19ae5
[`explicit_deref_methods`]: do not lint on method chains
a-yossy May 30, 2025
010c2d3
[`explicit_deref_methods`]: do not lint on method chains (#14921)
samueltardieu May 30, 2025
7631648
fix: `dbg_macro` fail to handle async coroutine desugar
profetia May 31, 2025
2948678
Fix `dbg_macro` fail to handle async coroutine desugar (#14937)
llogiq May 31, 2025
384b53e
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 May 31, 2025
cd71411
Bump nightly version -> 2025-05-31
flip1995 May 31, 2025
57cbadd
Rustup (#14938)
flip1995 May 31, 2025
cce4ea9
Merge commit '57cbadd68ac473bc50453f6b1320a02b68115f12'
flip1995 May 31, 2025
8ac5f7f
Update Cargo.lock
flip1995 May 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 5 additions & 47 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,56 +177,26 @@ version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"

[[package]]
name = "askama"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d4744ed2eef2645831b441d8f5459689ade2ab27c854488fbab1fbe94fce1a7"
dependencies = [
"askama_derive 0.13.1",
"itoa",
"percent-encoding",
"serde",
"serde_json",
]

[[package]]
name = "askama"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"
dependencies = [
"askama_derive 0.14.0",
"askama_derive",
"itoa",
"percent-encoding",
"serde",
"serde_json",
]

[[package]]
name = "askama_derive"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d661e0f57be36a5c14c48f78d09011e67e0cb618f269cca9f2fd8d15b68c46ac"
dependencies = [
"askama_parser 0.13.0",
"basic-toml",
"memchr",
"proc-macro2",
"quote",
"rustc-hash 2.1.1",
"serde",
"serde_derive",
"syn 2.0.101",
]

[[package]]
name = "askama_derive"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"
dependencies = [
"askama_parser 0.14.0",
"askama_parser",
"basic-toml",
"memchr",
"proc-macro2",
Expand All @@ -237,18 +207,6 @@ dependencies = [
"syn 2.0.101",
]

[[package]]
name = "askama_parser"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f"
dependencies = [
"memchr",
"serde",
"serde_derive",
"winnow 0.7.10",
]

[[package]]
name = "askama_parser"
version = "0.14.0"
Expand Down Expand Up @@ -582,7 +540,7 @@ name = "clippy"
version = "0.1.89"
dependencies = [
"anstream",
"askama 0.13.1",
"askama",
"cargo_metadata 0.18.1",
"clippy_config",
"clippy_lints",
Expand Down Expand Up @@ -1432,7 +1390,7 @@ name = "generate-copyright"
version = "0.1.0"
dependencies = [
"anyhow",
"askama 0.14.0",
"askama",
"cargo_metadata 0.18.1",
"serde",
"serde_json",
Expand Down Expand Up @@ -4676,7 +4634,7 @@ name = "rustdoc"
version = "0.0.0"
dependencies = [
"arrayvec",
"askama 0.14.0",
"askama",
"base64",
"expect-test",
"indexmap",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ walkdir = "2.3"
filetime = "0.2.9"
itertools = "0.12"
pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] }
askama = { version = "0.13", default-features = false, features = ["alloc", "config", "derive"] }
askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }

# UI test dependencies
if_chain = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/book/src/development/trait_checking.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ providing the `LateContext` (`cx`), our expression at hand, and
the symbol of the trait in question:

```rust
use clippy_utils::is_trait_method;
use clippy_utils::ty::implements_trait;
use rustc_hir::Expr;
use rustc_lint::{LateContext, LateLintPass};
use rustc_span::symbol::sym;

impl LateLintPass<'_> for CheckIteratorTraitLint {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
let implements_iterator = cx.tcx.get_diagnostic_item(sym::Iterator).map_or(false, |id| {
implements_trait(cx, cx.typeck_results().expr_ty(arg), id, &[])
implements_trait(cx, cx.typeck_results().expr_ty(expr), id, &[])
});
if implements_iterator {
// [...]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ The order of associated items in traits.
The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
reference.

**Default Value:** `target_pointer_width * 2`
**Default Value:** `target_pointer_width`

---
**Affected lints:**
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ define_Conf! {
trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(),
/// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
/// reference.
#[default_text = "target_pointer_width * 2"]
#[default_text = "target_pointer_width"]
#[lints(trivially_copy_pass_by_ref)]
trivial_copy_size_limit: Option<u64> = None,
/// The maximum complexity a type can have
Expand Down
133 changes: 44 additions & 89 deletions src/tools/clippy/clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::utils::{
ClippyInfo, ErrAction, FileUpdater, UpdateMode, UpdateStatus, panic_action, run_with_args_split, run_with_output,
ErrAction, FileUpdater, UpdateMode, UpdateStatus, expect_action, run_with_output, split_args_for_threads,
walk_dir_no_dot_or_target,
};
use itertools::Itertools;
use rustc_lexer::{TokenKind, tokenize};
Expand All @@ -9,7 +10,6 @@ use std::io::{self, Read};
use std::ops::ControlFlow;
use std::path::PathBuf;
use std::process::{self, Command, Stdio};
use walkdir::WalkDir;

pub enum Error {
Io(io::Error),
Expand Down Expand Up @@ -260,50 +260,27 @@ fn fmt_syms(update_mode: UpdateMode) {
);
}

fn run_rustfmt(clippy: &ClippyInfo, update_mode: UpdateMode) {
fn run_rustfmt(update_mode: UpdateMode) {
let mut rustfmt_path = String::from_utf8(run_with_output(
"rustup which rustfmt",
Command::new("rustup").args(["which", "rustfmt"]),
))
.expect("invalid rustfmt path");
rustfmt_path.truncate(rustfmt_path.trim_end().len());

let mut cargo_path = String::from_utf8(run_with_output(
"rustup which cargo",
Command::new("rustup").args(["which", "cargo"]),
))
.expect("invalid cargo path");
cargo_path.truncate(cargo_path.trim_end().len());

// Start all format jobs first before waiting on the results.
let mut children = Vec::with_capacity(16);
for &path in &[
".",
"clippy_config",
"clippy_dev",
"clippy_lints",
"clippy_lints_internal",
"clippy_utils",
"rustc_tools_util",
"lintcheck",
] {
let mut cmd = Command::new(&cargo_path);
cmd.current_dir(clippy.path.join(path))
.args(["fmt"])
.env("RUSTFMT", &rustfmt_path)
.stdout(Stdio::null())
.stdin(Stdio::null())
.stderr(Stdio::piped());
if update_mode.is_check() {
cmd.arg("--check");
}
match cmd.spawn() {
Ok(x) => children.push(("cargo fmt", x)),
Err(ref e) => panic_action(&e, ErrAction::Run, "cargo fmt".as_ref()),
}
}
let args: Vec<_> = walk_dir_no_dot_or_target()
.filter_map(|e| {
let e = expect_action(e, ErrAction::Read, ".");
e.path()
.as_os_str()
.as_encoded_bytes()
.ends_with(b".rs")
.then(|| e.into_path().into_os_string())
})
.collect();

run_with_args_split(
let mut children: Vec<_> = split_args_for_threads(
32,
|| {
let mut cmd = Command::new(&rustfmt_path);
if update_mode.is_check() {
Expand All @@ -312,66 +289,44 @@ fn run_rustfmt(clippy: &ClippyInfo, update_mode: UpdateMode) {
cmd.stdout(Stdio::null())
.stdin(Stdio::null())
.stderr(Stdio::piped())
.args(["--config", "show_parse_errors=false"]);
.args(["--unstable-features", "--skip-children"]);
cmd
},
|cmd| match cmd.spawn() {
Ok(x) => children.push(("rustfmt", x)),
Err(ref e) => panic_action(&e, ErrAction::Run, "rustfmt".as_ref()),
},
WalkDir::new("tests")
.into_iter()
.filter_entry(|p| p.path().file_name().is_none_or(|x| x != "skip_rustfmt"))
.filter_map(|e| {
let e = e.expect("error reading `tests`");
e.path()
.as_os_str()
.as_encoded_bytes()
.ends_with(b".rs")
.then(|| e.into_path().into_os_string())
}),
);
args.iter(),
)
.map(|mut cmd| expect_action(cmd.spawn(), ErrAction::Run, "rustfmt"))
.collect();

for (name, child) in &mut children {
match child.wait() {
Ok(status) => match (update_mode, status.exit_ok()) {
(UpdateMode::Check | UpdateMode::Change, Ok(())) => {},
(UpdateMode::Check, Err(_)) => {
let mut s = String::new();
if let Some(mut stderr) = child.stderr.take()
&& stderr.read_to_string(&mut s).is_ok()
{
eprintln!("{s}");
}
eprintln!("Formatting check failed!\nRun `cargo dev fmt` to update.");
process::exit(1);
},
(UpdateMode::Change, Err(e)) => {
let mut s = String::new();
if let Some(mut stderr) = child.stderr.take()
&& stderr.read_to_string(&mut s).is_ok()
{
eprintln!("{s}");
}
panic_action(&e, ErrAction::Run, name.as_ref());
},
for child in &mut children {
let status = expect_action(child.wait(), ErrAction::Run, "rustfmt");
match (update_mode, status.exit_ok()) {
(UpdateMode::Check | UpdateMode::Change, Ok(())) => {},
(UpdateMode::Check, Err(_)) => {
let mut s = String::new();
if let Some(mut stderr) = child.stderr.take()
&& stderr.read_to_string(&mut s).is_ok()
{
eprintln!("{s}");
}
eprintln!("Formatting check failed!\nRun `cargo dev fmt` to update.");
process::exit(1);
},
(UpdateMode::Change, e) => {
let mut s = String::new();
if let Some(mut stderr) = child.stderr.take()
&& stderr.read_to_string(&mut s).is_ok()
{
eprintln!("{s}");
}
expect_action(e, ErrAction::Run, "rustfmt");
},
Err(ref e) => panic_action(e, ErrAction::Run, name.as_ref()),
}
}
}

// the "main" function of cargo dev fmt
pub fn run(clippy: &ClippyInfo, update_mode: UpdateMode) {
if clippy.has_intellij_hook {
eprintln!(
"error: a local rustc repo is enabled as path dependency via `cargo dev setup intellij`.\n\
Not formatting because that would format the local repo as well!\n\
Please revert the changes to `Cargo.toml`s with `cargo dev remove intellij`."
);
return;
}
run_rustfmt(clippy, update_mode);
pub fn run(update_mode: UpdateMode) {
run_rustfmt(update_mode);
fmt_syms(update_mode);
if let Err(e) = fmt_conf(update_mode.is_check()) {
e.display();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
allow_staged,
allow_no_vcs,
} => dogfood::dogfood(fix, allow_dirty, allow_staged, allow_no_vcs),
DevCommand::Fmt { check } => fmt::run(&clippy, utils::UpdateMode::from_check(check)),
DevCommand::Fmt { check } => fmt::run(utils::UpdateMode::from_check(check)),
DevCommand::UpdateLints { check } => update_lints::update(utils::UpdateMode::from_check(check)),
DevCommand::NewLint {
pass,
Expand Down
20 changes: 6 additions & 14 deletions src/tools/clippy/clippy_dev/src/rename_lint.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::update_lints::{RenamedLint, find_lint_decls, generate_lint_files, read_deprecated_lints};
use crate::utils::{
FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, Version, delete_dir_if_exists, delete_file_if_exists,
try_rename_dir, try_rename_file,
ErrAction, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, Version, delete_dir_if_exists,
delete_file_if_exists, expect_action, try_rename_dir, try_rename_file, walk_dir_no_dot_or_target,
};
use rustc_lexer::TokenKind;
use std::ffi::OsString;
use std::fs;
use std::path::Path;
use walkdir::WalkDir;

/// Runs the `rename_lint` command.
///
Expand Down Expand Up @@ -133,17 +132,10 @@ pub fn rename(clippy_version: Version, old_name: &str, new_name: &str, uplift: b
}

let mut update_fn = file_update_fn(old_name, new_name, mod_edit);
for file in WalkDir::new(".").into_iter().filter_entry(|e| {
// Skip traversing some of the larger directories.
e.path()
.as_os_str()
.as_encoded_bytes()
.get(2..)
.is_none_or(|x| x != "target".as_bytes() && x != ".git".as_bytes())
}) {
let file = file.expect("error reading clippy directory");
if file.path().as_os_str().as_encoded_bytes().ends_with(b".rs") {
updater.update_file(file.path(), &mut update_fn);
for e in walk_dir_no_dot_or_target() {
let e = expect_action(e, ErrAction::Read, ".");
if e.path().as_os_str().as_encoded_bytes().ends_with(b".rs") {
updater.update_file(e.path(), &mut update_fn);
}
}
generate_lint_files(UpdateMode::Change, &lints, &deprecated_lints, &renamed_lints);
Expand Down
7 changes: 2 additions & 5 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::utils::{
ErrAction, File, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, panic_action, update_text_region_fn,
ErrAction, File, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, expect_action, update_text_region_fn,
};
use itertools::Itertools;
use std::collections::HashSet;
Expand Down Expand Up @@ -201,10 +201,7 @@ pub fn find_lint_decls() -> Vec<Lint> {
/// Reads the source files from the given root directory
fn read_src_with_module(src_root: &Path) -> impl use<'_> + Iterator<Item = (DirEntry, String)> {
WalkDir::new(src_root).into_iter().filter_map(move |e| {
let e = match e {
Ok(e) => e,
Err(ref e) => panic_action(e, ErrAction::Read, src_root),
};
let e = expect_action(e, ErrAction::Read, src_root);
let path = e.path().as_os_str().as_encoded_bytes();
if let Some(path) = path.strip_suffix(b".rs")
&& let Some(path) = path.get("clippy_lints/src/".len()..)
Expand Down
Loading
Loading