Skip to content

Clippy subtree update #144449

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 150 commits into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
96ae10e
Document changing `clippy::msrv` with a feature gate
samueltardieu Mar 18, 2025
e236bfc
Add a note to `incompatible_msrv` to suggest feature gating the MSRV
samueltardieu Mar 18, 2025
f2d4973
Use public `core` items for testing
samueltardieu Mar 18, 2025
205e313
Do not warn about feature-enabled items
samueltardieu Mar 18, 2025
e3ec0d2
Check MSRV for any entity, not just function and method calls
samueltardieu Mar 18, 2025
68ea461
Add TODO for const stability MSRV checking
samueltardieu Mar 18, 2025
d66e4f6
Restrict the cases where Clippy proposes to switch range types
samueltardieu Mar 17, 2025
15fc993
Refactor `range_plus_one` and `range_minus_one` lints
samueltardieu Apr 15, 2025
07e2d96
Fix expect_fun_call producing invalid suggestions
sethdusek Jun 24, 2025
ba4253b
Fix capacity overflow in `single_match` with deref patterns
notriddle Jun 24, 2025
5f49cf8
fix: `unused_trait_names` FP when `as` name is from macro input
profetia Jun 1, 2025
e0d9cfb
Remove `unused_trait_names`'s support inside macros
profetia Jun 18, 2025
08f5eba
Mark unsuffixed type literals are type uncertain by default
samueltardieu Mar 28, 2025
83148cb
Do not always consider parameters of closures as type-certain
samueltardieu Jul 3, 2025
a8ab02c
Fix several issues with `manual_is_multiple_of`
samueltardieu Jul 3, 2025
9d7637b
clippy: conditions are no longer wrapped in `DropTemps`
dianne Jun 30, 2025
cc9d96c
precommit test
klensy Jun 18, 2025
addf309
also lint method calls inside map_or first arg
klensy Jun 18, 2025
86a1496
dogfood: fix few lint issues
klensy Jun 18, 2025
a743efc
Fix few typos
alex-semenyuk Jul 5, 2025
6b6f35e
Add uninlined_format_args example: `:?` formatting
AljoschaMeyer Jul 8, 2025
b1d1762
Reduce clippy lints page size
GuillaumeGomez Jul 9, 2025
24a4ad5
feat(lexer): Allow including frontmatter with 'tokenize'
epage Jul 9, 2025
823ee8a
Cleanup feature_freeze
alex-semenyuk Jul 6, 2025
4e614bf
Merge commit 'cdbbf3afda0b1bf51568b368f629b1d828507f98' into clippy-s…
flip1995 Jul 10, 2025
e30313c
fix `legacy_numeric_constants` suggestion when call is wrapped in parens
ComputerDruid Jun 18, 2025
ae6416a
add extra legacy_numeric_constants test cases
samueltardieu Jul 10, 2025
88ee494
cleanup legacy_numeric_constants
ComputerDruid Jul 10, 2025
37ddd9f
refactor legacy_numeric_constants to check calls instead of paths
samueltardieu Jul 10, 2025
9457d64
refactor legacy_numeric_constants to use multipart suggestion
samueltardieu Jul 10, 2025
e29e353
Cleanup feature_freeze workflow (#15231)
blyxyas Jul 10, 2025
4dcaa80
Fix few typos (#15218)
llogiq Jul 10, 2025
df5a0ee
or_fun_call: lint method calls inside map_or first arg (#15074)
llogiq Jul 10, 2025
a745e2c
fix(arithmetic_side_effects): don't warn on `NonZeroU*.get() - 1`
ada4a Jul 9, 2025
b5e701e
`arithmetic_side_effects`: don't warn on `NonZeroU*.get() - 1` (#15238)
blyxyas Jul 10, 2025
488f4dd
fix `legacy_numeric_constants` suggestion when call is wrapped in par…
samueltardieu Jul 11, 2025
a1844ec
Rollup merge of #143708 - epage:pretty, r=compiler-errors
matthiaskrgr Jul 11, 2025
e2270bb
Reduce clippy lints page size (#15235)
samueltardieu Jul 11, 2025
d5b10f0
Use `$RUSTC` instead of `rustc` to get version if var is available
samueltardieu Jul 11, 2025
1d1b97d
fix false negative of `expect_used`
relaxcn Jul 11, 2025
093b6e5
Fix approx_const for some new cases
teofr Jul 9, 2025
3d7188d
Add `uninlined_format_args` example for `{:?}` (#15228)
dswij Jul 12, 2025
0cc6061
clippy: fix test filtering when TESTNAME is empty
RalfJung Jul 12, 2025
2ecbf82
fix clippy_test_deps workspace handling
RalfJung Jul 12, 2025
4154387
Use `Ty::is_fn` instead of manually matching on `TyKind`
ada4a Jun 20, 2025
e610584
`{flat_,}map_identity`: also recognize `|[x, y]| [x, y]`
ada4a Jul 7, 2025
3c3ee9b
`{flat_,}map_identity`: recognize `|[x, y]| [x, y]` as an identity fu…
y21 Jul 12, 2025
7e2d26f
Fix `approx_const` for some new cases (#15236)
blyxyas Jul 12, 2025
3187aa7
Fix clippy & rustdoc-json
JonathanBrouwer Jul 11, 2025
519ad87
Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot
bors Jul 13, 2025
41510cc
Rollup merge of #143825 - RalfJung:clippy-test-filter, r=llogiq
matthiaskrgr Jul 13, 2025
9d96404
fix: `manual_abs_diff` suggests wrongly behind refs
profetia Jul 13, 2025
de43d8c
Remove hir::AssocItemKind.
cjgillot Jul 13, 2025
8510965
Retire hir::*ItemRef.
cjgillot Jul 2, 2025
b4fc33a
Lint: Improve manual_is_variant_and to support equality comparison
krikera Jul 9, 2025
6f2567d
Update manual_is_variant_and documentation to include equality compar…
blyxyas Jul 13, 2025
901ab5b
fix: `manual_assert` suggests wrongly for macros
profetia Jul 13, 2025
434fb31
Auto merge of #143357 - cjgillot:no-assoc-item-kind, r=compiler-errors
bors Jul 13, 2025
cffeac7
Auto merge of #143779 - JonathanBrouwer:automatically_derived_parser,…
bors Jul 14, 2025
461572a
Merge from rustc
Jul 14, 2025
43f1891
Fix `manual_abs_diff` suggests wrongly behind refs (#15265)
Jarcho Jul 14, 2025
d9acd91
fix false negative of `expect_used` (#15253)
Jarcho Jul 14, 2025
ba947c5
Fix `manual_assert` suggests wrongly for macros (#15264)
samueltardieu Jul 14, 2025
1c64211
Fix manual is multiple of (#15205)
Jarcho Jul 14, 2025
06e6927
`ineffective_open_options`: refactor, don't use `method_call`
Jarcho Jul 14, 2025
75c330b
Fix `ptr_arg` suggests changes when it's actually better not to bother
immersum Jun 22, 2025
ff1ae2b
Reword mismatched-lifetime-syntaxes text based on feedback
shepmaster Jul 10, 2025
fcd064d
expect_fun_call: only lint const fn's if they're not inside a const c…
sethdusek Jul 14, 2025
104e265
`ineffective_open_options`: don't subtract a constant `BytePos`
Jarcho Jul 14, 2025
8d6de0b
Fix expect_fun_call producing invalid suggestions (#15122)
samueltardieu Jul 14, 2025
fdf37fc
`ineffective_open_options`: remove `method_call` use (#15271)
samueltardieu Jul 14, 2025
7796773
`useless_conversion`: move all the impl to the same lint pass
Jarcho Jul 14, 2025
f4b827a
Auto merge of #143745 - flip1995:clippy-subtree-update, r=Manishearth
bors Jul 14, 2025
ba8da7a
`useless_conversion`: move all the impl to the same lint pass (#15274)
samueltardieu Jul 14, 2025
bfc4d17
Add more tests, clean up code
notriddle Jul 14, 2025
c20faa0
fix `needless_for_each` suggests wrongly for macros
relaxcn Jul 15, 2025
7823aac
Merge from rustc
Jul 15, 2025
0bf4d5a
fix suggestion causes error of `needless_for_each` (#15262)
Jarcho Jul 15, 2025
016e534
gh-pages: reduce page size by skipping spaces
klensy Jul 15, 2025
e1be062
gh-pages: reduce page size by skipping spaces (#15278)
samueltardieu Jul 15, 2025
fc44198
Use `Ty::is_fn` instead of manually matching on `TyKind` (#15089)
Alexendoo Jul 15, 2025
038295a
fix: `filter_map_bool_then` wrongly showed macro definition in sugges…
profetia Jun 13, 2025
ae1d3ae
Use `$RUSTC` instead of `rustc` to get version if var is available (#…
flip1995 Jul 15, 2025
413f8db
future-incompat lints: don't link to the nightly edition-guide version
dianne Jul 16, 2025
21943a9
Don't trigger `unused_trait_names` in macros (#14947)
flip1995 Jul 16, 2025
b49e360
`unsafe_derive_deserialize`: do not consider `pin!()` as `unsafe`
samueltardieu Jun 25, 2025
ad97abc
`unsafe_derive_deserialize`: do not consider `pin!()` as `unsafe` (#1…
samueltardieu Jul 16, 2025
32263f5
Move `uninlined_format_args` to `pedantic`
Alexendoo Jul 16, 2025
39a1d52
Get myself off assignment rotation
samueltardieu Jul 16, 2025
041a0f6
Get myself off assignment rotation (#15288)
samueltardieu Jul 16, 2025
8d941d2
fix: `never_loop` forget to remove break in suggestion
profetia Jun 16, 2025
df529eb
fix: `ptr_as_ptr` suggests wrongly with turbo fish
profetia Jul 16, 2025
786330e
Fix `ptr_arg` suggests changes when it's actually better not to bothe…
Jarcho Jul 16, 2025
2a4c83d
Move `uninlined_format_args` to `pedantic` (#15287)
dswij Jul 16, 2025
e113e66
Propose to exchange ranges only when it is safe to do so (#14432)
Jarcho Jul 16, 2025
c0dc3b6
Various improvements to the `incompatible_msrv` lint (#14433)
Jarcho Jul 16, 2025
ed176b7
Fix `ptr_as_ptr` suggests wrongly with turbo fish (#15289)
llogiq Jul 16, 2025
b7caf75
Improve path segment joining.
nnethercote May 27, 2025
0e66490
Rollup merge of #143922 - nnethercote:join_path, r=petrochenkov
fmease Jul 17, 2025
a6be68a
Rollup merge of #143914 - shepmaster:mismatched-lifetime-syntaxes-rew…
matthiaskrgr Jul 17, 2025
11bfeca
Warn about types not meeting MSRV
samueltardieu Jul 16, 2025
19f8c50
parse `const trait Trait`
fee1-dead Jul 13, 2025
e62e27b
Warn about types not meeting MSRV (#15296)
Jarcho Jul 17, 2025
167ac05
Warn about `const` instability wrt MSRV
samueltardieu Jul 16, 2025
11e3ae3
Auto merge of #143879 - fee1-dead-contrib:push-lrlpoouyqqry, r=fmease
bors Jul 17, 2025
e81009d
Include ErrorGuaranteed in StableSince::Err.
cjgillot Jul 16, 2025
b2c4e6d
fix: ignore pattern_type_mismatch when external macro owns the match
kristof-mattei Jul 17, 2025
1df3b96
Fix `empty_with_brackets` span handling.
Jarcho Jul 18, 2025
cca924b
Simplify `must_use_candidate` spans.
Jarcho Jul 18, 2025
ae8ff77
Warn about `const` instability wrt MSRV (#15297)
Jarcho Jul 18, 2025
5acb1d4
Fix `empty_with_brackets` span handling (#15311)
dswij Jul 19, 2025
048a64a
Remove unused option fir LEVEL_FILTERS_DEFAULT
alex-semenyuk Jul 19, 2025
6cf00e9
fix: `needless_range_loop` FP on array literals
profetia Jul 19, 2025
b916841
Remove unused option `None` for `LEVEL_FILTERS_DEFAULT` (#15315)
Alexendoo Jul 19, 2025
f85cdbb
Simplify `must_use_candidate` spans (#15310)
Alexendoo Jul 19, 2025
17968e7
Fix `needless_range_loop` FP on array literals (#15314)
llogiq Jul 19, 2025
fd7076b
Fix `filter_map_bool_then` wrongly suggests macro definitions (#15048)
Alexendoo Jul 19, 2025
75811df
fix: `missing_inline_in_public_items` FP on functions with `extern`
profetia Jul 19, 2025
72243f4
Fix `missing_inline_in_public_items` FP on functions with `extern` (#…
y21 Jul 19, 2025
6543a09
Fix `never_loop` forget to remove `break` in suggestion (#15064)
blyxyas Jul 20, 2025
56de455
Fix capacity overflow in `single_match` with deref patterns (#15124)
blyxyas Jul 20, 2025
1b88319
fix: `if_then_some_else_none` FP when require type coercion
profetia Jul 13, 2025
b738d96
Improve Help Message in `large_enum_variant to satisfy` `#[no_std]`
lkshayb Jul 10, 2025
c8e333c
Fixed issue #15192 (#15241)
y21 Jul 20, 2025
257b024
Unquerify maybe_unused_trait_imports.
cjgillot Jul 3, 2025
0b16881
fix: ignore pattern_type_mismatch when external macro owns the match …
dswij Jul 20, 2025
50f36c0
clippy: make tests work in stage 1
RalfJung Jul 16, 2025
92111dc
Fix false positive in useless_attribute with redundant_imports
krikera Jul 21, 2025
d4dea4b
Fix false positive in useless_attribute with redundant_imports (#15318)
y21 Jul 21, 2025
bebae76
fix: `module_name_repetitions` FP on exported macros
profetia Jul 21, 2025
9738031
Rollup merge of #144027 - RalfJung:clippy, r=Mark-Simulacrum
jieyouxu Jul 21, 2025
3ed170f
Rollup merge of #143373 - cjgillot:bare-unused-trait-imports, r=petro…
matthiaskrgr Jul 22, 2025
6a87804
fix: `unused_async` FP on function with `todo!`
profetia Jul 18, 2025
e07a4ee
Ports `#[macro_use]` and `#[macro_escape]` to the new attribute parsi…
JonathanBrouwer Jul 12, 2025
b2c8c02
Fix `unused_async` FP on function with `todo!` (#15308)
Alexendoo Jul 23, 2025
8ad5c67
Fix `module_name_repetitions` FP on exported macros (#15319)
blyxyas Jul 23, 2025
ddf9b37
Remove useless lifetime parameter.
cjgillot Jul 3, 2025
55be3c2
Remove "Known problems" section for `clippy::redundant_closure`
alex-semenyuk Jul 24, 2025
5cd24d7
Correct help message for `arc_with_non_send_sync`
marv7000 Jul 24, 2025
7d5833f
Correct help message for `arc_with_non_send_sync` (#15332)
y21 Jul 24, 2025
49e0ae0
Rollup merge of #144014 - dianne:edition-guide-links, r=estebank
fmease Jul 24, 2025
98205e6
Fix `if_then_some_else_none` FP when require type coercion (#15267)
blyxyas Jul 24, 2025
e85b1dd
Remove "Known problems" section for `clippy::redundant_closure` (#15331)
dswij Jul 25, 2025
c98e60a
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 25, 2025
d64eb62
Update .gitignore
flip1995 Jul 25, 2025
31baffd
Bump nightly version -> 2025-07-25
flip1995 Jul 25, 2025
d0fa808
Fix if_same_then_else with if let conditions
flip1995 Jul 25, 2025
1db89a1
Rustup (#15341)
flip1995 Jul 25, 2025
a0b18b3
Merge commit '1db89a1b1ca87f24bf22d0bad21d14b2d81b3e99' into clippy-s…
flip1995 Jul 25, 2025
9660038
Allow approx-constant in `x clippy library`
flip1995 Jul 25, 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
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const IGNORED_RULES_FOR_STD_AND_RUSTC: &[&str] = &[
"too_many_arguments",
"needless_lifetimes", // people want to keep the lifetimes
"wrong_self_convention",
"approx_constant", // libcore is what defines those
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this is the right fix 🤔

];

fn lint_args(builder: &Builder<'_>, config: &LintConfig, ignored_rules: &[&str]) -> Vec<String> {
Expand Down
36 changes: 23 additions & 13 deletions src/tools/clippy/.github/workflows/feature_freeze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,26 @@ jobs:
# of the pull request, as malicious code would be able to access the private
# GitHub token.
steps:
- name: Check PR Changes
id: pr-changes
run: echo "::set-output name=changes::${{ toJson(github.event.pull_request.changed_files) }}"

- name: Create Comment
if: steps.pr-changes.outputs.changes != '[]'
run: |
# Use GitHub API to create a comment on the PR
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENT="**Seems that you are trying to add a new lint!**\nWe are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to September 18 and focusing on bugfixes.\nThanks a lot for your contribution, and sorry for the inconvenience.\nWith ❤ from the Clippy team\n\n@rustbot note Feature-freeze\n@rustbot blocked\n@rustbot label +A-lint\n"
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST $COMMENT_URL -d "{\"body\":\"$COMMENT\"}"
- name: Add freeze warning comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
COMMENT=$(echo "**Seems that you are trying to add a new lint!**\n\
\n\
We are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to September 18 and [focusing on bugfixes](https://github.com/rust-lang/rust-clippy/issues/15086).\n\
\n\
Thanks a lot for your contribution, and sorry for the inconvenience.\n\
\n\
With ❤ from the Clippy team.\n\
\n\
@rustbot note Feature-freeze\n\
@rustbot blocked\n\
@rustbot label +A-lint"
)
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Content-Type: application/vnd.github.raw+json" \
-X POST \
--data "{\"body\":\"${COMMENT}\"}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments"
2 changes: 2 additions & 0 deletions src/tools/clippy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ out

# Generated by Cargo
*Cargo.lock
!/clippy_test_deps/Cargo.lock
/target
/clippy_lints/target
/clippy_lints_internal/target
/clippy_utils/target
/clippy_dev/target
/lintcheck/target
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::utils::{
walk_dir_no_dot_or_target,
};
use itertools::Itertools;
use rustc_lexer::{TokenKind, tokenize};
use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize};
use std::fmt::Write;
use std::fs;
use std::io::{self, Read};
Expand Down Expand Up @@ -92,7 +92,7 @@ fn fmt_conf(check: bool) -> Result<(), Error> {
let mut fields = Vec::new();
let mut state = State::Start;

for (i, t) in tokenize(conf)
for (i, t) in tokenize(conf, FrontmatterAllowed::No)
.map(|x| {
let start = pos;
pos += x.len;
Expand Down
33 changes: 26 additions & 7 deletions src/tools/clippy/clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ impl LateLintPass<'_> for ApproxConstant {
impl ApproxConstant {
fn check_known_consts(&self, cx: &LateContext<'_>, span: Span, s: symbol::Symbol, module: &str) {
let s = s.as_str();
if s.parse::<f64>().is_ok() {
if let Ok(maybe_constant) = s.parse::<f64>() {
for &(constant, name, min_digits, msrv) in &KNOWN_CONSTS {
if is_approx_const(constant, s, min_digits) && msrv.is_none_or(|msrv| self.msrv.meets(cx, msrv)) {
if is_approx_const(constant, s, maybe_constant, min_digits)
&& msrv.is_none_or(|msrv| self.msrv.meets(cx, msrv))
{
span_lint_and_help(
cx,
APPROX_CONSTANT,
Expand All @@ -112,18 +114,35 @@ impl ApproxConstant {

impl_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);

fn count_digits_after_dot(input: &str) -> usize {
input
.char_indices()
.find(|(_, ch)| *ch == '.')
.map_or(0, |(i, _)| input.len() - i - 1)
}

/// Returns `false` if the number of significant figures in `value` are
/// less than `min_digits`; otherwise, returns true if `value` is equal
/// to `constant`, rounded to the number of digits present in `value`.
/// to `constant`, rounded to the number of significant digits present in `value`.
#[must_use]
fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {
fn is_approx_const(constant: f64, value: &str, f_value: f64, min_digits: usize) -> bool {
if value.len() <= min_digits {
// The value is not precise enough
false
} else if constant.to_string().starts_with(value) {
// The value is a truncated constant
} else if f_value.to_string().len() > min_digits && constant.to_string().starts_with(&f_value.to_string()) {
// The value represents the same value
true
} else {
let round_const = format!("{constant:.*}", value.len() - 2);
// The value is a truncated constant

// Print constant with numeric formatting (`0`), with the length of `value` as minimum width
// (`value_len$`), and with the same precision as `value` (`.value_prec$`).
// See https://doc.rust-lang.org/std/fmt/index.html.
let round_const = format!(
"{constant:0value_len$.value_prec$}",
value_len = value.len(),
value_prec = count_digits_after_dot(value)
);
value == round_const
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use clippy_utils::diagnostics::span_lint_and_note;
use clippy_utils::is_cfg_test;
use rustc_attr_data_structures::AttributeKind;
use rustc_hir::{
Attribute, FieldDef, HirId, IsAuto, ImplItemId, Item, ItemKind, Mod, OwnerId, QPath, TraitItemId, TyKind,
Variant, VariantData,
Attribute, FieldDef, HirId, ImplItemId, IsAuto, Item, ItemKind, Mod, OwnerId, QPath, TraitItemId, TyKind, Variant,
VariantData,
};
use rustc_middle::ty::AssocKind;
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::ty::AssocKind;
use rustc_session::impl_lint_pass;
use rustc_span::Ident;

Expand Down Expand Up @@ -469,13 +469,14 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
/// This is implemented here because `rustc_hir` is not a dependency of
/// `clippy_config`.
fn convert_assoc_item_kind(cx: &LateContext<'_>, owner_id: OwnerId) -> SourceItemOrderingTraitAssocItemKind {
let kind = cx.tcx.associated_item(owner_id.def_id).kind;

#[allow(clippy::enum_glob_use)] // Very local glob use for legibility.
use SourceItemOrderingTraitAssocItemKind::*;

let kind = cx.tcx.associated_item(owner_id.def_id).kind;

match kind {
AssocKind::Const{..} => Const,
AssocKind::Type {..}=> Type,
AssocKind::Const { .. } => Const,
AssocKind::Type { .. } => Type,
AssocKind::Fn { .. } => Fn,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync {
diag.note(format!(
"`Arc<{arg_ty}>` is not `Send` and `Sync` as `{arg_ty}` is {reason}"
));
diag.help("if the `Arc` will not used be across threads replace it with an `Rc`");
diag.help("if the `Arc` will not be used across threads replace it with an `Rc`");
diag.help(format!(
"otherwise make `{arg_ty}` `Send` and `Sync` or consider a wrapper type such as `Mutex`"
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
| sym::unused_braces
| sym::unused_import_braces
| sym::unused_imports
| sym::redundant_imports
)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ fn get_const_name_and_ty_name(

pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
// We allow casts from any function type to any function type.
match cast_to.kind() {
ty::FnDef(..) | ty::FnPtr(..) => return,
_ => { /* continue to checks */ },
if cast_to.is_fn() {
return;
}

if let ty::FnDef(def_id, generics) = cast_from.kind()
Expand Down
33 changes: 15 additions & 18 deletions src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::Ty;

use super::{FN_TO_NUMERIC_CAST, utils};

Expand All @@ -13,23 +13,20 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
return;
};

match cast_from.kind() {
ty::FnDef(..) | ty::FnPtr(..) => {
let mut applicability = Applicability::MaybeIncorrect;
if cast_from.is_fn() {
let mut applicability = Applicability::MaybeIncorrect;

if to_nbits >= cx.tcx.data_layout.pointer_size().bits() && !cast_to.is_usize() {
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability);
span_lint_and_sugg(
cx,
FN_TO_NUMERIC_CAST,
expr.span,
format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
"try",
format!("{from_snippet} as usize"),
applicability,
);
}
},
_ => {},
if to_nbits >= cx.tcx.data_layout.pointer_size().bits() && !cast_to.is_usize() {
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability);
span_lint_and_sugg(
cx,
FN_TO_NUMERIC_CAST,
expr.span,
format!("casting function pointer `{from_snippet}` to `{cast_to}`"),
"try",
format!("{from_snippet} as usize"),
applicability,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::Ty;

use super::FN_TO_NUMERIC_CAST_ANY;

pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, cast_from: Ty<'_>, cast_to: Ty<'_>) {
// We allow casts from any function type to any function type.
match cast_to.kind() {
ty::FnDef(..) | ty::FnPtr(..) => return,
_ => { /* continue to checks */ },
if cast_to.is_fn() {
return;
}

if let ty::FnDef(..) | ty::FnPtr(..) = cast_from.kind() {
if cast_from.is_fn() {
let mut applicability = Applicability::MaybeIncorrect;
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::Expr;
use rustc_lint::LateContext;
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::Ty;

use super::{FN_TO_NUMERIC_CAST_WITH_TRUNCATION, utils};

Expand All @@ -12,23 +12,20 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
let Some(to_nbits) = utils::int_ty_to_nbits(cx.tcx, cast_to) else {
return;
};
match cast_from.kind() {
ty::FnDef(..) | ty::FnPtr(..) => {
let mut applicability = Applicability::MaybeIncorrect;
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability);
if cast_from.is_fn() {
let mut applicability = Applicability::MaybeIncorrect;
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability);

if to_nbits < cx.tcx.data_layout.pointer_size().bits() {
span_lint_and_sugg(
cx,
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
expr.span,
format!("casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value"),
"try",
format!("{from_snippet} as usize"),
applicability,
);
}
},
_ => {},
if to_nbits < cx.tcx.data_layout.pointer_size().bits() {
span_lint_and_sugg(
cx,
FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
expr.span,
format!("casting function pointer `{from_snippet}` to `{cast_to}`, which truncates the value"),
"try",
format!("{from_snippet} as usize"),
applicability,
);
}
}
}
16 changes: 13 additions & 3 deletions src/tools/clippy/clippy_lints/src/casts/ptr_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use clippy_utils::source::snippet_with_applicability;
use clippy_utils::sugg::Sugg;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, Mutability, QPath, TyKind};
use rustc_hir_pretty::qpath_to_string;
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::sym;
use rustc_span::{Span, sym};

use super::PTR_AS_PTR;

Expand Down Expand Up @@ -74,7 +73,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) {

let (help, final_suggestion) = if let Some(method) = omit_cast.corresponding_item() {
// don't force absolute path
let method = qpath_to_string(&cx.tcx, method);
let method = snippet_with_applicability(cx, qpath_span_without_turbofish(method), "..", &mut app);
("try call directly", format!("{method}{turbofish}()"))
} else {
let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app);
Expand All @@ -96,3 +95,14 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) {
);
}
}

fn qpath_span_without_turbofish(qpath: &QPath<'_>) -> Span {
if let QPath::Resolved(_, path) = qpath
&& let [.., last_ident] = path.segments
&& last_ident.args.is_some()
{
return qpath.span().shrink_to_lo().to(last_ident.ident.span);
}

qpath.span()
}
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ impl CognitiveComplexity {
FnKind::ItemFn(ident, _, _) | FnKind::Method(ident, _) => ident.span,
FnKind::Closure => {
let header_span = body_span.with_hi(decl.output.span().lo());
#[expect(clippy::range_plus_one)]
if let Some(range) = header_span.map_range(cx, |_, src, range| {
let mut idxs = src.get(range.clone())?.match_indices('|');
Some(range.start + idxs.next()?.0..range.start + idxs.next()?.0 + 1)
Expand Down
16 changes: 3 additions & 13 deletions src/tools/clippy/clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_config::Conf;
use clippy_utils::diagnostics::{span_lint, span_lint_and_note, span_lint_and_then};
use clippy_utils::higher::has_let_expr;
use clippy_utils::source::{IntoSpan, SpanRangeExt, first_line_of_span, indent_of, reindent_multiline, snippet};
use clippy_utils::ty::{InteriorMut, needs_ordered_drop};
use clippy_utils::visitors::for_each_expr_without_closures;
Expand All @@ -11,7 +12,7 @@ use clippy_utils::{
use core::iter;
use core::ops::ControlFlow;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Node, Stmt, StmtKind, intravisit};
use rustc_hir::{Block, Expr, ExprKind, HirId, HirIdSet, LetStmt, Node, Stmt, StmtKind, intravisit};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::TyCtxt;
use rustc_session::impl_lint_pass;
Expand Down Expand Up @@ -189,24 +190,13 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste<'tcx> {
}
}

/// Checks if the given expression is a let chain.
fn contains_let(e: &Expr<'_>) -> bool {
match e.kind {
ExprKind::Let(..) => true,
ExprKind::Binary(op, lhs, rhs) if op.node == BinOpKind::And => {
matches!(lhs.kind, ExprKind::Let(..)) || contains_let(rhs)
},
_ => false,
}
}

fn lint_if_same_then_else(cx: &LateContext<'_>, conds: &[&Expr<'_>], blocks: &[&Block<'_>]) -> bool {
let mut eq = SpanlessEq::new(cx);
blocks
.array_windows::<2>()
.enumerate()
.fold(true, |all_eq, (i, &[lhs, rhs])| {
if eq.eq_block(lhs, rhs) && !contains_let(conds[i]) && conds.get(i + 1).is_none_or(|e| !contains_let(e)) {
if eq.eq_block(lhs, rhs) && !has_let_expr(conds[i]) && conds.get(i + 1).is_none_or(|e| !has_let_expr(e)) {
span_lint_and_note(
cx,
IF_SAME_THEN_ELSE,
Expand Down
Loading
Loading