Skip to content

Commit 15a6485

Browse files
committed
Merge commit '20b085d500dfba5afe0869707bf357af3afe20be' into clippy-subtree-update
2 parents f5efc3c + 20b085d commit 15a6485

File tree

124 files changed

+1664
-755
lines changed

Some content is hidden

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

124 files changed

+1664
-755
lines changed

src/tools/clippy/CHANGELOG.md

+54-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,62 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[66c29b97...master](https://github.com/rust-lang/rust-clippy/compare/66c29b97...master)
9+
[93f0a9a9...master](https://github.com/rust-lang/rust-clippy/compare/93f0a9a9...master)
10+
11+
## Rust 1.78
12+
13+
Current stable, released 2024-05-02
14+
15+
[View all 112 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2024-01-26T05%3A46%3A23Z..2024-03-07T16%3A25%3A52Z+base%3Amaster)
16+
17+
### New Lints
18+
19+
* [`assigning_clones`]
20+
[#12077](https://github.com/rust-lang/rust-clippy/pull/12077)
21+
* [`mixed_attributes_style`]
22+
[#12354](https://github.com/rust-lang/rust-clippy/pull/12354)
23+
* [`empty_docs`]
24+
[#12342](https://github.com/rust-lang/rust-clippy/pull/12342)
25+
* [`unnecessary_get_then_check`]
26+
[#12339](https://github.com/rust-lang/rust-clippy/pull/12339)
27+
* [`multiple_bound_locations`]
28+
[#12259](https://github.com/rust-lang/rust-clippy/pull/12259)
29+
* [`unnecessary_clippy_cfg`]
30+
[#12303](https://github.com/rust-lang/rust-clippy/pull/12303)
31+
* [`deprecated_clippy_cfg_attr`]
32+
[#12292](https://github.com/rust-lang/rust-clippy/pull/12292)
33+
* [`manual_c_str_literals`]
34+
[#11919](https://github.com/rust-lang/rust-clippy/pull/11919)
35+
* [`ref_as_ptr`]
36+
[#12087](https://github.com/rust-lang/rust-clippy/pull/12087)
37+
* [`lint_groups_priority`]
38+
[#11832](https://github.com/rust-lang/rust-clippy/pull/11832)
39+
* [`unnecessary_result_map_or_else`]
40+
[#12169](https://github.com/rust-lang/rust-clippy/pull/12169)
41+
* [`to_string_trait_impl`]
42+
[#12122](https://github.com/rust-lang/rust-clippy/pull/12122)
43+
* [`incompatible_msrv`]
44+
[#12160](https://github.com/rust-lang/rust-clippy/pull/12160)
45+
46+
### Enhancements
47+
48+
* [`thread_local_initializer_can_be_made_const`]: Now checks the [`msrv`] configuration
49+
[#12405](https://github.com/rust-lang/rust-clippy/pull/12405)
50+
* [`disallowed_macros`]: Code generated by derive macros can no longer allow this lint
51+
[#12267](https://github.com/rust-lang/rust-clippy/pull/12267)
52+
* [`wildcard_imports`]: Add configuration [`allowed-wildcard-imports`] to allow preconfigured wildcards
53+
[#11979](https://github.com/rust-lang/rust-clippy/pull/11979)
54+
55+
### ICE Fixes
56+
57+
* [`ptr_as_ptr`]: No longer ICEs when the cast source is a function call to a local variable
58+
[#12617](https://github.com/rust-lang/rust-clippy/pull/12617)
59+
* [`cast_sign_loss`]: Avoids an infinite loop when casting two chained `.unwrap()` calls
60+
[#12508](https://github.com/rust-lang/rust-clippy/pull/12508)
1061

1162
## Rust 1.77
1263

13-
Current stable, released 2024-03-18
64+
Released 2024-03-18
1465

1566
[View all 93 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-12-16T18%3A20%3A00Z..2024-01-25T18%3A15%3A56Z+base%3Amaster)
1667

@@ -5891,6 +5942,7 @@ Released 2018-09-13
58915942
[`allow-print-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-print-in-tests
58925943
[`allow-private-module-inception`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-private-module-inception
58935944
[`allow-unwrap-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-unwrap-in-tests
5945+
[`allow-useless-vec-in-tests`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-useless-vec-in-tests
58945946
[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles
58955947
[`allowed-duplicate-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-duplicate-crates
58965948
[`allowed-idents-below-min-chars`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-idents-below-min-chars

src/tools/clippy/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.79"
3+
version = "0.1.80"
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"
@@ -30,7 +30,7 @@ color-print = "0.3.4"
3030
anstream = "0.6.0"
3131

3232
[dev-dependencies]
33-
ui_test = "0.22.2"
33+
ui_test = "0.23"
3434
regex = "1.5.5"
3535
toml = "0.7.3"
3636
walkdir = "2.3"

src/tools/clippy/book/src/development/adding_lints.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ This is good, because it makes writing this particular lint less complicated.
299299
We have to make this decision with every new Clippy lint. It boils down to using
300300
either [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass].
301301

302-
In short, the `LateLintPass` has access to type information while the
303-
`EarlyLintPass` doesn't. If you don't need access to type information, use the
304-
`EarlyLintPass`. The `EarlyLintPass` is also faster. However, linting speed
305-
hasn't really been a concern with Clippy so far.
302+
In short, the `EarlyLintPass` runs before type checking and
303+
[HIR](https://rustc-dev-guide.rust-lang.org/hir.html) lowering and the `LateLintPass`
304+
has access to type information. Consider using the `LateLintPass` unless you need
305+
something specific from the `EarlyLintPass`.
306306

307307
Since we don't need type information for checking the function name, we used
308308
`--pass=early` when running the new lint automation and all the imports were

src/tools/clippy/book/src/lint_configuration.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ Whether `unwrap` should be allowed in test functions or `#[cfg(test)]`
132132
* [`unwrap_used`](https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used)
133133

134134

135+
## `allow-useless-vec-in-tests`
136+
Whether `useless_vec` should ignore test functions or `#[cfg(test)]`
137+
138+
**Default Value:** `false`
139+
140+
---
141+
**Affected lints:**
142+
* [`useless_vec`](https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec)
143+
144+
135145
## `allowed-dotfiles`
136146
Additional dotfiles (files or directories starting with a dot) to allow
137147

@@ -506,13 +516,14 @@ The maximum byte size a `Future` can have, before it triggers the `clippy::large
506516

507517

508518
## `ignore-interior-mutability`
509-
A list of paths to types that should be treated like `Arc`, i.e. ignored but
510-
for the generic parameters for determining interior mutability
519+
A list of paths to types that should be treated as if they do not contain interior mutability
511520

512521
**Default Value:** `["bytes::Bytes"]`
513522

514523
---
515524
**Affected lints:**
525+
* [`borrow_interior_mutable_const`](https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const)
526+
* [`declare_interior_mutable_const`](https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const)
516527
* [`ifs_same_cond`](https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond)
517528
* [`mutable_key_type`](https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key_type)
518529

src/tools/clippy/clippy_config/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.79"
3+
version = "0.1.80"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/tools/clippy/clippy_config/src/conf.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -463,14 +463,17 @@ define_Conf! {
463463
///
464464
/// Whether print macros (ex. `println!`) should be allowed in test functions or `#[cfg(test)]`
465465
(allow_print_in_tests: bool = false),
466+
/// Lint: USELESS_VEC.
467+
///
468+
/// Whether `useless_vec` should ignore test functions or `#[cfg(test)]`
469+
(allow_useless_vec_in_tests: bool = false),
466470
/// Lint: RESULT_LARGE_ERR.
467471
///
468472
/// The maximum size of the `Err`-variant in a `Result` returned from a function
469473
(large_error_threshold: u64 = 128),
470-
/// Lint: MUTABLE_KEY_TYPE, IFS_SAME_COND.
474+
/// Lint: MUTABLE_KEY_TYPE, IFS_SAME_COND, BORROW_INTERIOR_MUTABLE_CONST, DECLARE_INTERIOR_MUTABLE_CONST.
471475
///
472-
/// A list of paths to types that should be treated like `Arc`, i.e. ignored but
473-
/// for the generic parameters for determining interior mutability
476+
/// A list of paths to types that should be treated as if they do not contain interior mutability
474477
(ignore_interior_mutability: Vec<String> = Vec::from(["bytes::Bytes".into()])),
475478
/// Lint: UNINLINED_FORMAT_ARGS.
476479
///

src/tools/clippy/clippy_config/src/msrvs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ msrv_aliases! {
2323
1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN }
2424
1,68,0 { PATH_MAIN_SEPARATOR_STR }
2525
1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
26-
1,63,0 { ASSIGNING_CLONES }
26+
1,63,0 { CLONE_INTO }
2727
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE }
2828
1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST }
2929
1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY }

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.79"
3+
version = "0.1.80"
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"

src/tools/clippy/clippy_lints/src/assigning_clones.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ declare_clippy_lint! {
4545
/// a.clone_from(&b);
4646
/// }
4747
/// ```
48-
#[clippy::version = "1.77.0"]
48+
#[clippy::version = "1.78.0"]
4949
pub ASSIGNING_CLONES,
5050
perf,
5151
"assigning the result of cloning may be inefficient"
@@ -153,7 +153,7 @@ fn extract_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<
153153
fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallCandidate<'tcx>, msrv: &Msrv) -> bool {
154154
// For calls to .to_owned we suggest using .clone_into(), which was only stablilized in 1.63.
155155
// If the current MSRV is below that, don't suggest the lint.
156-
if !msrv.meets(msrvs::ASSIGNING_CLONES) && matches!(call.target, TargetTrait::ToOwned) {
156+
if !msrv.meets(msrvs::CLONE_INTO) && matches!(call.target, TargetTrait::ToOwned) {
157157
return false;
158158
}
159159

src/tools/clippy/clippy_lints/src/box_default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ fn given_type(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
121121
if let Some(index) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
122122
&& let Some(sig) = expr_sig(cx, path)
123123
&& let Some(input) = sig.input(index)
124-
&& !cx.typeck_results().expr_ty_adjusted(expr).boxed_ty().is_trait()
124+
&& let Some(input_ty) = input.no_bound_vars()
125125
{
126-
input.no_bound_vars().is_some()
126+
input_ty == cx.typeck_results().expr_ty_adjusted(expr)
127127
} else {
128128
false
129129
}

src/tools/clippy/clippy_lints/src/cargo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ declare_clippy_lint! {
197197
/// pedantic = { level = "warn", priority = -1 }
198198
/// similar_names = "allow"
199199
/// ```
200-
#[clippy::version = "1.76.0"]
200+
#[clippy::version = "1.78.0"]
201201
pub LINT_GROUPS_PRIORITY,
202202
correctness,
203203
"a lint group in `Cargo.toml` at the same priority as a lint"

src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,14 @@ fn apply_reductions(cx: &LateContext<'_>, nbits: u64, expr: &Expr<'_>, signed: b
4040
get_constant_bits(cx, right).map_or(0, |b| b.saturating_sub(1))
4141
})
4242
},
43-
BinOpKind::Rem | BinOpKind::BitAnd => get_constant_bits(cx, right)
43+
BinOpKind::Rem => get_constant_bits(cx, right)
4444
.unwrap_or(u64::MAX)
4545
.min(apply_reductions(cx, nbits, left, signed)),
46+
BinOpKind::BitAnd => get_constant_bits(cx, right)
47+
.unwrap_or(u64::MAX)
48+
.min(get_constant_bits(cx, left).unwrap_or(u64::MAX))
49+
.min(apply_reductions(cx, nbits, right, signed))
50+
.min(apply_reductions(cx, nbits, left, signed)),
4651
BinOpKind::Shr => apply_reductions(cx, nbits, left, signed)
4752
.saturating_sub(constant_int(cx, right).map_or(0, |s| u64::try_from(s).unwrap_or_default())),
4853
_ => nbits,

src/tools/clippy/clippy_lints/src/casts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ declare_clippy_lint! {
708708
/// let a_ref = &1;
709709
/// let a_ptr = std::ptr::from_ref(a_ref);
710710
/// ```
711-
#[clippy::version = "1.77.0"]
711+
#[clippy::version = "1.78.0"]
712712
pub REF_AS_PTR,
713713
pedantic,
714714
"using `as` to cast a reference to pointer"

src/tools/clippy/clippy_lints/src/collection_is_never_read.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
3-
use clippy_utils::visitors::for_each_expr_with_closures;
3+
use clippy_utils::visitors::{for_each_expr_with_closures, Visitable};
44
use clippy_utils::{get_enclosing_block, path_to_local_id};
55
use core::ops::ControlFlow;
6-
use rustc_hir::{Block, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
6+
use rustc_hir::{Body, ExprKind, HirId, LangItem, LetStmt, Node, PatKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::declare_lint_pass;
99
use rustc_span::symbol::sym;
@@ -77,7 +77,7 @@ fn match_acceptable_type(cx: &LateContext<'_>, local: &LetStmt<'_>, collections:
7777
|| is_type_lang_item(cx, ty, LangItem::String)
7878
}
7979

80-
fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Block<'tcx>) -> bool {
80+
fn has_no_read_access<'tcx, T: Visitable<'tcx>>(cx: &LateContext<'tcx>, id: HirId, block: T) -> bool {
8181
let mut has_access = false;
8282
let mut has_read_access = false;
8383

@@ -109,11 +109,30 @@ fn has_no_read_access<'tcx>(cx: &LateContext<'tcx>, id: HirId, block: &'tcx Bloc
109109
// traits (identified as local, based on the orphan rule), pessimistically assume that they might
110110
// have side effects, so consider them a read.
111111
if let Node::Expr(parent) = cx.tcx.parent_hir_node(expr.hir_id)
112-
&& let ExprKind::MethodCall(_, receiver, _, _) = parent.kind
112+
&& let ExprKind::MethodCall(_, receiver, args, _) = parent.kind
113113
&& path_to_local_id(receiver, id)
114114
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
115115
&& !method_def_id.is_local()
116116
{
117+
// If this "official" method takes closures,
118+
// it has read access if one of the closures has read access.
119+
//
120+
// items.retain(|item| send_item(item).is_ok());
121+
let is_read_in_closure_arg = args.iter().any(|arg| {
122+
if let ExprKind::Closure(closure) = arg.kind
123+
// To keep things simple, we only check the first param to see if its read.
124+
&& let Body { params: [param, ..], value } = cx.tcx.hir().body(closure.body)
125+
{
126+
!has_no_read_access(cx, param.hir_id, *value)
127+
} else {
128+
false
129+
}
130+
});
131+
if is_read_in_closure_arg {
132+
has_read_access = true;
133+
return ControlFlow::Break(());
134+
}
135+
117136
// The method call is a statement, so the return value is not used. That's not a read access:
118137
//
119138
// id.foo(args);

0 commit comments

Comments
 (0)