Skip to content

Commit 91edc3e

Browse files
committed
Auto merge of #146218 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? `@Manishearth`
2 parents b3cfb8f + 75b9ee5 commit 91edc3e

File tree

202 files changed

+4536
-1641
lines changed

Some content is hidden

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

202 files changed

+4536
-1641
lines changed

src/tools/clippy/.cargo/config.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ split-debuginfo = "unpacked"
2323
rustflags = ["--remap-path-prefix", "=clippy_dev"]
2424
[profile.dev.package.lintcheck]
2525
rustflags = ["--remap-path-prefix", "=lintcheck"]
26+
27+
# quine-mc_cluskey makes up a significant part of the runtime in dogfood
28+
# due to the number of conditions in the clippy_lints crate
29+
# and enabling optimizations for that specific dependency helps a bit
30+
# without increasing total build times.
31+
[profile.dev.package.quine-mc_cluskey]
32+
opt-level = 3

src/tools/clippy/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Current stable, released 2025-08-07
3030
* Removed superseded lints: `transmute_float_to_int`, `transmute_int_to_char`,
3131
`transmute_int_to_float`, `transmute_num_to_bytes` (now in rustc)
3232
[#14703](https://github.com/rust-lang/rust-clippy/pull/14703)
33+
* Move [`uninlined_format_args`] to `pedantic` (from `style`, now allow-by-default)
34+
[#15287](https://github.com/rust-lang/rust-clippy/pull/15287)
3335

3436
### Enhancements
3537

@@ -74,6 +76,9 @@ Current stable, released 2025-08-07
7476
[#14719](https://github.com/rust-lang/rust-clippy/pull/14719)
7577
* [`unnecessary_to_owned`] fixed FP when map key is a reference
7678
[#14834](https://github.com/rust-lang/rust-clippy/pull/14834)
79+
* [`swap_with_temporary`]: fix false positive leading to different semantics
80+
being suggested, and use the right number of dereferences in suggestion
81+
[#15172](https://github.com/rust-lang/rust-clippy/pull/15172)
7782

7883
### ICE Fixes
7984

@@ -6707,6 +6712,7 @@ Released 2018-09-13
67076712
[`check-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-inconsistent-struct-field-initializers
67086713
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
67096714
[`cognitive-complexity-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#cognitive-complexity-threshold
6715+
[`const-literal-digits-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#const-literal-digits-threshold
67106716
[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros
67116717
[`disallowed-methods`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-methods
67126718
[`disallowed-names`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-names

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ The maximum cognitive complexity a function can have
485485
* [`cognitive_complexity`](https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity)
486486

487487

488+
## `const-literal-digits-threshold`
489+
The minimum digits a const float literal must have to supress the `excessive_precicion` lint
490+
491+
**Default Value:** `30`
492+
493+
---
494+
**Affected lints:**
495+
* [`excessive_precision`](https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision)
496+
497+
488498
## `disallowed-macros`
489499
The list of disallowed macros, written as fully qualified paths.
490500

@@ -555,7 +565,7 @@ default configuration of Clippy. By default, any configuration will replace the
555565
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
556566
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
557567

558-
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "PowerPC", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "NixOS", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
568+
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "InfiniBand", "RoCE", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "PowerPC", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "NixOS", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
559569

560570
---
561571
**Affected lints:**
@@ -873,15 +883,13 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
873883
* [`needless_borrow`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow)
874884
* [`non_std_lazy_statics`](https://rust-lang.github.io/rust-clippy/master/index.html#non_std_lazy_statics)
875885
* [`option_as_ref_deref`](https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref)
876-
* [`option_map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or)
877886
* [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr)
878887
* [`question_mark`](https://rust-lang.github.io/rust-clippy/master/index.html#question_mark)
879888
* [`redundant_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names)
880889
* [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes)
881890
* [`repeat_vec_with_capacity`](https://rust-lang.github.io/rust-clippy/master/index.html#repeat_vec_with_capacity)
882891
* [`same_item_push`](https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push)
883892
* [`seek_from_current`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_from_current)
884-
* [`seek_rewind`](https://rust-lang.github.io/rust-clippy/master/index.html#seek_rewind)
885893
* [`to_digit_is_some`](https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some)
886894
* [`transmute_ptr_to_ref`](https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref)
887895
* [`tuple_array_conversions`](https://rust-lang.github.io/rust-clippy/master/index.html#tuple_array_conversions)

src/tools/clippy/clippy.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ lint-commented-code = true
66

77
[[disallowed-methods]]
88
path = "rustc_lint::context::LintContext::lint"
9-
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"
9+
reason = "this function does not add a link to our documentation; please use the `clippy_utils::diagnostics::span_lint*` functions instead"
1010

1111
[[disallowed-methods]]
1212
path = "rustc_lint::context::LintContext::span_lint"
13-
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"
13+
reason = "this function does not add a link to our documentation; please use the `clippy_utils::diagnostics::span_lint*` functions instead"
1414

1515
[[disallowed-methods]]
1616
path = "rustc_middle::ty::context::TyCtxt::node_span_lint"
17-
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead"
17+
reason = "this function does not add a link to our documentation; please use the `clippy_utils::diagnostics::span_lint_hir*` functions instead"

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
3333
"GPLv2", "GPLv3",
3434
"GitHub", "GitLab",
3535
"IPv4", "IPv6",
36+
"InfiniBand", "RoCE",
3637
"ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript",
3738
"PowerPC", "WebAssembly",
3839
"NaN", "NaNs",
@@ -569,6 +570,9 @@ define_Conf! {
569570
/// The maximum cognitive complexity a function can have
570571
#[lints(cognitive_complexity)]
571572
cognitive_complexity_threshold: u64 = 25,
573+
/// The minimum digits a const float literal must have to supress the `excessive_precicion` lint
574+
#[lints(excessive_precision)]
575+
const_literal_digits_threshold: usize = 30,
572576
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
573577
///
574578
/// Use the Cognitive Complexity lint instead.
@@ -775,15 +779,13 @@ define_Conf! {
775779
needless_borrow,
776780
non_std_lazy_statics,
777781
option_as_ref_deref,
778-
option_map_unwrap_or,
779782
ptr_as_ptr,
780783
question_mark,
781784
redundant_field_names,
782785
redundant_static_lifetimes,
783786
repeat_vec_with_capacity,
784787
same_item_push,
785788
seek_from_current,
786-
seek_rewind,
787789
to_digit_is_some,
788790
transmute_ptr_to_ref,
789791
tuple_array_conversions,

src/tools/clippy/clippy_lints/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ url = "2.2"
2727
[dev-dependencies]
2828
walkdir = "2.3"
2929

30+
[lints.rust.unexpected_cfgs]
31+
level = "warn"
32+
check-cfg = ['cfg(bootstrap)']
33+
3034
[package.metadata.rust-analyzer]
3135
# This crate uses #[feature(rustc_private)]
3236
rustc_private = true

src/tools/clippy/clippy_lints/src/assertions_on_result_states.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use clippy_utils::macros::{PanicExpn, find_assert_args, root_macro_call_first_no
33
use clippy_utils::source::snippet_with_context;
44
use clippy_utils::ty::{has_debug_impl, is_copy, is_type_diagnostic_item};
55
use clippy_utils::usage::local_used_after_expr;
6-
use clippy_utils::{is_expr_final_block_expr, path_res, sym};
6+
use clippy_utils::{path_res, sym};
77
use rustc_errors::Applicability;
88
use rustc_hir::def::Res;
9-
use rustc_hir::{Expr, ExprKind};
9+
use rustc_hir::{Expr, ExprKind, Node};
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_middle::ty::{self, Ty};
1212
use rustc_session::declare_lint_pass;
@@ -77,17 +77,20 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
7777
_ => return,
7878
};
7979
span_lint_and_then(cx, ASSERTIONS_ON_RESULT_STATES, macro_call.span, message, |diag| {
80-
let semicolon = if is_expr_final_block_expr(cx.tcx, e) { ";" } else { "" };
8180
let mut app = Applicability::MachineApplicable;
82-
diag.span_suggestion(
83-
macro_call.span,
84-
"replace with",
85-
format!(
86-
"{}.{replacement}(){semicolon}",
87-
snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0
88-
),
89-
app,
90-
);
81+
let recv = snippet_with_context(cx, recv.span, condition.span.ctxt(), "..", &mut app).0;
82+
83+
// `assert!` doesn't return anything, but `Result::unwrap(_err)` does, so we might need to add a
84+
// semicolon to the suggestion to avoid leaking the type
85+
let sugg = match cx.tcx.parent_hir_node(e.hir_id) {
86+
// trailing expr of a block
87+
Node::Block(..) => format!("{recv}.{replacement}();"),
88+
// already has a trailing semicolon
89+
Node::Stmt(..) => format!("{recv}.{replacement}()"),
90+
// this is the last-resort option, because it's rather verbose
91+
_ => format!("{{ {recv}.{replacement}(); }}"),
92+
};
93+
diag.span_suggestion(macro_call.span, "replace with", sugg, app);
9194
});
9295
}
9396
}

src/tools/clippy/clippy_lints/src/async_yields_async.rs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_hir_and_then;
2-
use clippy_utils::source::snippet;
2+
use clippy_utils::is_expr_async_block;
3+
use clippy_utils::source::walk_span_to_context;
4+
use clippy_utils::sugg::Sugg;
35
use clippy_utils::ty::implements_trait;
46
use rustc_errors::Applicability;
5-
use rustc_hir::{Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath};
7+
use rustc_hir::{
8+
Block, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, QPath,
9+
};
610
use rustc_lint::{LateContext, LateLintPass};
711
use rustc_session::declare_lint_pass;
812

@@ -87,31 +91,37 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
8791
let expr_ty = typeck_results.expr_ty(body_expr);
8892

8993
if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {
90-
let return_expr_span = match &body_expr.kind {
91-
// XXXkhuey there has to be a better way.
92-
ExprKind::Block(block, _) => block.expr.map(|e| e.span),
93-
ExprKind::Path(QPath::Resolved(_, path)) => Some(path.span),
94-
_ => None,
94+
let (return_expr, return_expr_span) = match &body_expr.kind {
95+
ExprKind::Block(Block { expr: Some(e), .. }, _) => (*e, e.span),
96+
ExprKind::Path(QPath::Resolved(_, path)) => (body_expr, path.span),
97+
_ => return,
9598
};
96-
if let Some(return_expr_span) = return_expr_span {
97-
span_lint_hir_and_then(
98-
cx,
99-
ASYNC_YIELDS_ASYNC,
100-
body_expr.hir_id,
101-
return_expr_span,
102-
"an async construct yields a type which is itself awaitable",
103-
|db| {
104-
db.span_label(body_expr.span, "outer async construct");
105-
db.span_label(return_expr_span, "awaitable value not awaited");
106-
db.span_suggestion(
107-
return_expr_span,
108-
"consider awaiting this value",
109-
format!("{}.await", snippet(cx, return_expr_span, "..")),
110-
Applicability::MaybeIncorrect,
111-
);
112-
},
113-
);
99+
100+
let return_expr_span = walk_span_to_context(return_expr_span, expr.span.ctxt()).unwrap_or(return_expr_span);
101+
let mut applicability = Applicability::MaybeIncorrect;
102+
let mut return_expr_snip =
103+
Sugg::hir_with_context(cx, return_expr, expr.span.ctxt(), "..", &mut applicability);
104+
if !is_expr_async_block(return_expr) {
105+
return_expr_snip = return_expr_snip.maybe_paren();
114106
}
107+
108+
span_lint_hir_and_then(
109+
cx,
110+
ASYNC_YIELDS_ASYNC,
111+
body_expr.hir_id,
112+
return_expr_span,
113+
"an async construct yields a type which is itself awaitable",
114+
|db| {
115+
db.span_label(body_expr.span, "outer async construct");
116+
db.span_label(return_expr_span, "awaitable value not awaited");
117+
db.span_suggestion(
118+
return_expr_span,
119+
"consider awaiting this value",
120+
format!("{return_expr_snip}.await"),
121+
applicability,
122+
);
123+
},
124+
);
115125
}
116126
}
117127
}

0 commit comments

Comments
 (0)