Skip to content

Commit 5315cbe

Browse files
committed
Auto merge of #127609 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? `@Manishearth`
2 parents bcf1f6d + 2ed6ed4 commit 5315cbe

File tree

191 files changed

+4147
-2494
lines changed

Some content is hidden

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

191 files changed

+4147
-2494
lines changed

src/tools/clippy/.github/workflows/lintcheck.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
- name: Run lintcheck
6060
if: steps.cache-json.outputs.cache-hit != 'true'
61-
run: ./target/debug/lintcheck --format json
61+
run: ./target/debug/lintcheck --format json --warn-all
6262

6363
- name: Upload base JSON
6464
uses: actions/upload-artifact@v4
@@ -86,7 +86,7 @@ jobs:
8686
run: cargo build --manifest-path=lintcheck/Cargo.toml
8787

8888
- name: Run lintcheck
89-
run: ./target/debug/lintcheck --format json
89+
run: ./target/debug/lintcheck --format json --warn-all
9090

9191
- name: Upload head JSON
9292
uses: actions/upload-artifact@v4

src/tools/clippy/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5236,6 +5236,7 @@ Released 2018-09-13
52365236
[`boxed_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local
52375237
[`branches_sharing_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code
52385238
[`builtin_type_shadow`]: https://rust-lang.github.io/rust-clippy/master/index.html#builtin_type_shadow
5239+
[`byte_char_slices`]: https://rust-lang.github.io/rust-clippy/master/index.html#byte_char_slices
52395240
[`bytes_count_to_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_count_to_len
52405241
[`bytes_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#bytes_nth
52415242
[`cargo_common_metadata`]: https://rust-lang.github.io/rust-clippy/master/index.html#cargo_common_metadata
@@ -5253,6 +5254,7 @@ Released 2018-09-13
52535254
[`cast_sign_loss`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_sign_loss
52545255
[`cast_slice_different_sizes`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_different_sizes
52555256
[`cast_slice_from_raw_parts`]: https://rust-lang.github.io/rust-clippy/master/index.html#cast_slice_from_raw_parts
5257+
[`cfg_not_test`]: https://rust-lang.github.io/rust-clippy/master/index.html#cfg_not_test
52565258
[`char_lit_as_u8`]: https://rust-lang.github.io/rust-clippy/master/index.html#char_lit_as_u8
52575259
[`chars_last_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_last_cmp
52585260
[`chars_next_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#chars_next_cmp
@@ -5539,6 +5541,7 @@ Released 2018-09-13
55395541
[`manual_range_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_patterns
55405542
[`manual_rem_euclid`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid
55415543
[`manual_retain`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain
5544+
[`manual_rotate`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_rotate
55425545
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
55435546
[`manual_slice_size_calculation`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_slice_size_calculation
55445547
[`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once
@@ -5587,6 +5590,7 @@ Released 2018-09-13
55875590
[`missing_assert_message`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_assert_message
55885591
[`missing_asserts_for_indexing`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_asserts_for_indexing
55895592
[`missing_const_for_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn
5593+
[`missing_const_for_thread_local`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_thread_local
55905594
[`missing_docs_in_private_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items
55915595
[`missing_enforced_import_renames`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames
55925596
[`missing_errors_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc
@@ -5701,6 +5705,7 @@ Released 2018-09-13
57015705
[`panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic
57025706
[`panic_in_result_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_in_result_fn
57035707
[`panic_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#panic_params
5708+
[`panicking_overflow_checks`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_overflow_checks
57045709
[`panicking_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#panicking_unwrap
57055710
[`partial_pub_fields`]: https://rust-lang.github.io/rust-clippy/master/index.html#partial_pub_fields
57065711
[`partialeq_ne_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#partialeq_ne_impl
@@ -5797,6 +5802,7 @@ Released 2018-09-13
57975802
[`semicolon_outside_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_outside_block
57985803
[`separated_literal_suffix`]: https://rust-lang.github.io/rust-clippy/master/index.html#separated_literal_suffix
57995804
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
5805+
[`set_contains_or_insert`]: https://rust-lang.github.io/rust-clippy/master/index.html#set_contains_or_insert
58005806
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
58015807
[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same
58025808
[`shadow_unrelated`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_unrelated

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ Suppress lints whenever the suggested change would cause breakage for other crat
348348
* [`enum_variant_names`](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names)
349349
* [`large_types_passed_by_value`](https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value)
350350
* [`linkedlist`](https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist)
351+
* [`needless_pass_by_ref_mut`](https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut)
351352
* [`option_option`](https://rust-lang.github.io/rust-clippy/master/index.html#option_option)
352353
* [`rc_buffer`](https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer)
353354
* [`rc_mutex`](https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex)
@@ -454,7 +455,7 @@ default configuration of Clippy. By default, any configuration will replace the
454455
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
455456
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
456457

457-
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DevOps", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
458+
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DevOps", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "WebGL", "WebGL2", "WebGPU", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
458459

459460
---
460461
**Affected lints:**

src/tools/clippy/clippy.toml

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
avoid-breaking-exported-api = false
22

3+
[[disallowed-methods]]
4+
path = "rustc_lint::context::LintContext::lint"
5+
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"
6+
37
[[disallowed-methods]]
48
path = "rustc_lint::context::LintContext::span_lint"
59
reason = "this function does not add a link to our documentation, please use the `clippy_utils::diagnostics::span_lint*` functions instead"

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
3131
"OCaml",
3232
"OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry",
3333
"WebGL", "WebGL2", "WebGPU",
34+
"WebP", "OpenExr", "YCbCr", "sRGB",
3435
"TensorFlow",
3536
"TrueType",
3637
"iOS", "macOS", "FreeBSD",
@@ -262,7 +263,7 @@ define_Conf! {
262263
/// arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
263264
/// ```
264265
(arithmetic_side_effects_allowed_unary: FxHashSet<String> = <_>::default()),
265-
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX, UNNECESSARY_BOX_RETURNS, SINGLE_CALL_FN.
266+
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX, UNNECESSARY_BOX_RETURNS, SINGLE_CALL_FN, NEEDLESS_PASS_BY_REF_MUT.
266267
///
267268
/// Suppress lints whenever the suggested change would cause breakage for other crates.
268269
(avoid_breaking_exported_api: bool = true),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ msrv_aliases! {
2525
1,68,0 { PATH_MAIN_SEPARATOR_STR }
2626
1,65,0 { LET_ELSE, POINTER_CAST_CONSTNESS }
2727
1,63,0 { CLONE_INTO }
28-
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE }
29-
1,59,0 { THREAD_LOCAL_INITIALIZER_CAN_BE_MADE_CONST }
28+
1,62,0 { BOOL_THEN_SOME, DEFAULT_ENUM_ATTRIBUTE, CONST_EXTERN_FN }
29+
1,59,0 { THREAD_LOCAL_CONST_INIT }
3030
1,58,0 { FORMAT_ARGS_CAPTURE, PATTERN_TRAIT_CHAR_ARRAY, CONST_RAW_PTR_DEREF }
3131
1,56,0 { CONST_FN_UNION }
3232
1,55,0 { SEEK_REWIND }

src/tools/clippy/clippy_dev/src/new_lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
273273
result.push_str(&if enable_msrv {
274274
formatdoc!(
275275
r#"
276-
use clippy_utils::msrvs::{{self, Msrv}};
276+
use clippy_config::msrvs::{{self, Msrv}};
277277
{pass_import}
278278
use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
279279
use rustc_session::impl_lint_pass;
@@ -399,7 +399,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
399399
let _: fmt::Result = writedoc!(
400400
lint_file_contents,
401401
r#"
402-
use clippy_utils::msrvs::{{self, Msrv}};
402+
use clippy_config::msrvs::{{self, Msrv}};
403403
use rustc_lint::{{{context_import}, LintContext}};
404404
405405
use super::{name_upper};

src/tools/clippy/clippy_lints/src/almost_complete_range.rs

+61-43
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_errors::Applicability;
66
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
77
use rustc_middle::lint::in_external_macro;
88
use rustc_session::impl_lint_pass;
9-
use rustc_span::Span;
109

1110
declare_clippy_lint! {
1211
/// ### What it does
@@ -41,61 +40,80 @@ impl AlmostCompleteRange {
4140
}
4241
impl EarlyLintPass for AlmostCompleteRange {
4342
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
44-
if let ExprKind::Range(Some(start), Some(end), RangeLimits::HalfOpen) = &e.kind {
45-
let ctxt = e.span.ctxt();
46-
let sugg = if let Some(start) = walk_span_to_context(start.span, ctxt)
47-
&& let Some(end) = walk_span_to_context(end.span, ctxt)
48-
&& self.msrv.meets(msrvs::RANGE_INCLUSIVE)
49-
{
50-
Some((trim_span(cx.sess().source_map(), start.between(end)), "..="))
51-
} else {
52-
None
53-
};
54-
check_range(cx, e.span, start, end, sugg);
43+
if let ExprKind::Range(Some(start), Some(end), RangeLimits::HalfOpen) = &e.kind
44+
&& is_incomplete_range(start, end)
45+
&& !in_external_macro(cx.sess(), e.span)
46+
{
47+
span_lint_and_then(
48+
cx,
49+
ALMOST_COMPLETE_RANGE,
50+
e.span,
51+
"almost complete ascii range",
52+
|diag| {
53+
let ctxt = e.span.ctxt();
54+
if let Some(start) = walk_span_to_context(start.span, ctxt)
55+
&& let Some(end) = walk_span_to_context(end.span, ctxt)
56+
&& self.msrv.meets(msrvs::RANGE_INCLUSIVE)
57+
{
58+
diag.span_suggestion(
59+
trim_span(cx.sess().source_map(), start.between(end)),
60+
"use an inclusive range",
61+
"..=".to_owned(),
62+
Applicability::MaybeIncorrect,
63+
);
64+
}
65+
},
66+
);
5567
}
5668
}
5769

5870
fn check_pat(&mut self, cx: &EarlyContext<'_>, p: &Pat) {
5971
if let PatKind::Range(Some(start), Some(end), kind) = &p.kind
6072
&& matches!(kind.node, RangeEnd::Excluded)
73+
&& is_incomplete_range(start, end)
74+
&& !in_external_macro(cx.sess(), p.span)
6175
{
62-
let sugg = if self.msrv.meets(msrvs::RANGE_INCLUSIVE) {
63-
"..="
64-
} else {
65-
"..."
66-
};
67-
check_range(cx, p.span, start, end, Some((kind.span, sugg)));
76+
span_lint_and_then(
77+
cx,
78+
ALMOST_COMPLETE_RANGE,
79+
p.span,
80+
"almost complete ascii range",
81+
|diag| {
82+
diag.span_suggestion(
83+
kind.span,
84+
"use an inclusive range",
85+
if self.msrv.meets(msrvs::RANGE_INCLUSIVE) {
86+
"..=".to_owned()
87+
} else {
88+
"...".to_owned()
89+
},
90+
Applicability::MaybeIncorrect,
91+
);
92+
},
93+
);
6894
}
6995
}
7096

7197
extract_msrv_attr!(EarlyContext);
7298
}
7399

74-
fn check_range(cx: &EarlyContext<'_>, span: Span, start: &Expr, end: &Expr, sugg: Option<(Span, &str)>) {
75-
if let ExprKind::Lit(start_token_lit) = start.peel_parens().kind
76-
&& let ExprKind::Lit(end_token_lit) = end.peel_parens().kind
77-
&& matches!(
78-
(
79-
LitKind::from_token_lit(start_token_lit),
80-
LitKind::from_token_lit(end_token_lit),
81-
),
82-
(
83-
Ok(LitKind::Byte(b'a') | LitKind::Char('a')),
84-
Ok(LitKind::Byte(b'z') | LitKind::Char('z'))
85-
) | (
86-
Ok(LitKind::Byte(b'A') | LitKind::Char('A')),
87-
Ok(LitKind::Byte(b'Z') | LitKind::Char('Z')),
88-
) | (
89-
Ok(LitKind::Byte(b'0') | LitKind::Char('0')),
90-
Ok(LitKind::Byte(b'9') | LitKind::Char('9')),
100+
fn is_incomplete_range(start: &Expr, end: &Expr) -> bool {
101+
match (&start.peel_parens().kind, &end.peel_parens().kind) {
102+
(&ExprKind::Lit(start_lit), &ExprKind::Lit(end_lit)) => {
103+
matches!(
104+
(LitKind::from_token_lit(start_lit), LitKind::from_token_lit(end_lit),),
105+
(
106+
Ok(LitKind::Byte(b'a') | LitKind::Char('a')),
107+
Ok(LitKind::Byte(b'z') | LitKind::Char('z'))
108+
) | (
109+
Ok(LitKind::Byte(b'A') | LitKind::Char('A')),
110+
Ok(LitKind::Byte(b'Z') | LitKind::Char('Z')),
111+
) | (
112+
Ok(LitKind::Byte(b'0') | LitKind::Char('0')),
113+
Ok(LitKind::Byte(b'9') | LitKind::Char('9')),
114+
)
91115
)
92-
)
93-
&& !in_external_macro(cx.sess(), span)
94-
{
95-
span_lint_and_then(cx, ALMOST_COMPLETE_RANGE, span, "almost complete ascii range", |diag| {
96-
if let Some((span, sugg)) = sugg {
97-
diag.span_suggestion(span, "use an inclusive range", sugg, Applicability::MaybeIncorrect);
98-
}
99-
});
116+
},
117+
_ => false,
100118
}
101119
}

src/tools/clippy/clippy_lints/src/assertions_on_constants.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use clippy_utils::consts::{constant_with_source, Constant, ConstantSource};
1+
use clippy_utils::consts::{constant, Constant};
22
use clippy_utils::diagnostics::span_lint_and_help;
3+
use clippy_utils::is_inside_always_const_context;
34
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
4-
use rustc_hir::{Expr, Item, ItemKind, Node};
5+
use rustc_hir::{Expr, ExprKind};
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_session::declare_lint_pass;
78
use rustc_span::sym;
@@ -42,17 +43,16 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
4243
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else {
4344
return;
4445
};
45-
let Some((Constant::Bool(val), source)) = constant_with_source(cx, cx.typeck_results(), condition) else {
46+
let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else {
4647
return;
4748
};
48-
if let ConstantSource::Constant = source
49-
&& let Node::Item(Item {
50-
kind: ItemKind::Const(..),
51-
..
52-
}) = cx.tcx.parent_hir_node(e.hir_id)
53-
{
54-
return;
49+
50+
match condition.kind {
51+
ExprKind::Path(..) | ExprKind::Lit(_) => {},
52+
_ if is_inside_always_const_context(cx.tcx, e.hir_id) => return,
53+
_ => {},
5554
}
55+
5656
if val {
5757
span_lint_and_help(
5858
cx,

0 commit comments

Comments
 (0)