Commit graph

23260 commits

Author SHA1 Message Date
llogiq
151a045fdd
clean-up SourceFileRange::as_str (#15401)
changelog: none
2025-08-03 16:56:11 +00:00
Ada Alakbarova
2d8d45e201
use ? for brevity 2025-08-03 17:16:28 +02:00
Ada Alakbarova
3b907eada7
use parens for clearer formatting
the first and second lines now each represent one approach to getting a
`source`
2025-08-03 17:16:28 +02:00
Jason Newcomb
88bcf1ca19
fix option-if-let-else lint (#15394)
some simple twists
Fixes rust-lang/rust-clippy#15002
Fixes rust-lang/rust-clippy#15379

changelog: [`option_if_let_else`]: Don't remove raw pointer derefs in
suggestions
changelog: [`option_if_let_else`]: Don't suggest passing argless
functions to `Result::map_or_else`
2025-08-03 06:55:48 +00:00
Jason Newcomb
fa09b86bfc
Simplify boolean expression in manual_assert (#15368)
Fixes rust-lang/rust-clippy#15359

changelog: [`manual_assert`]: simplify boolean expression
2025-08-03 05:41:51 +00:00
Zihan
8f6b43dd65
fix: option_if_let_else don't suggest argless function for Result::map_or_else
closes rust-clippy/issues/15002

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-02 16:58:18 -04:00
Zihan
b8c16e47f4
fix: option_if_let_else keep deref op if the inner expr is a raw pointer
closes rust-clippy/issues/15379

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-02 13:07:11 -04:00
Timo
e8185ec091
Extend implicit_clone to handle to_string calls (#14177)
Put another way, merge `string_to_string` into `implicit_clone`, as
suggested here:
https://github.com/rust-lang/rust-clippy/issues/14173#issuecomment-2645846915

Note: [I
wrote](b8913894a1)
this comment:
6cdb7f68c3/clippy_lints/src/methods/implicit_clone.rs (L43-L45)

Here is the context for why I wrote it:
https://github.com/rust-lang/rust-clippy/pull/7978#discussion_r769128853

Regardless, it's probably time for the comment to go away. Extending
`implicit_clone` to handle `to_string` calls yields many hits within
Clippy's codebase.

changelog: extend `implicit_clone` to handle `to_string` calls
2025-08-02 11:41:00 +00:00
Timo
ffcd12946e
{flat_,}map_identity: recognize (tuple) struct de- and restructuring (#15261)
Follow-up of rust-lang/rust-clippy#15229, as described in
https://github.com/rust-lang/rust-clippy/pull/15229#issuecomment-3050279790
-- it turned out to be not that difficult after all!

changelog: [`map_identity`,`flat_map_identity`]: also recognize (tuple)
struct de- and resctructuring

r? @y21
2025-08-02 11:37:12 +00:00
Samuel Tardieu
e42586d495
fix: let_with_type_underscore don't eat closing paren in let (i): _ = 0; (#15386)
Apparently, one can surround a pattern with an arbitrary number of
parens, and the resulting `Pat` won't include the span of those parens.
And the previous approach extended the to-be-deleted span all the way to
the end of `Pat`'s span, so it included the closing paren.

I think the new approach is more robust anyway, since all we care to
remove (besides the `_`) is the `:`, so we search just for that.

~This does leave one extra whitespace in one of the test cases, but I'd
say let rustfmt handle that.~ fixed in the third commit

changelog: [`let_with_type_underscore`]: don't eat closing paren in `let
(i): _ = 0;`

fixes https://github.com/rust-lang/rust-clippy/issues/15377
2025-08-02 07:53:32 +00:00
Ada Alakbarova
0f98da7c5c
fix: let_with_type_underscore don't eat closing paren in let (i): _ = 0;
add failing tests

fix

also remove whitespace before `:`
2025-08-02 09:48:12 +02:00
Samuel Tardieu
cde155d1c1
Optimize broken_links by 99.77% (#15385)
We were calling an expensive functions lots of times resulting in 12
million instructions for `broken_links`, the doc lint optimization is
not over yet...

Now the instruction count for `broken_links` is at a healthy 27
thousand. This improvement is a difference of 1.5% in the total analysis
time for `tokio`.

changelog:[`broken_links`]: Optimize by 99.77%
2025-08-02 07:30:04 +00:00
blyxyas
01d960f645 Optimize broken_links by 99.77% 2025-08-02 01:59:48 +02:00
dswij
94b703588e
Do not specialize for if_chain any longer (#15362)
Now that `if let` chains have been introduced, the `if_chain` external
crate is no longer necessary. Dropping special support for it also
alleviates the need to keep the crate as a dependency in tests.

This is a cleanup PR.

changelog: none
2025-08-01 15:52:00 +00:00
Ada Alakbarova
eea4d6dc3c
{flat_,}map_identity: recognize (tuple) struct de- and restructuring
base check

same fields different struct

reordered fields

different paths to the same struct

same for tuple structs

style: use `zip`-the-function all over the place

makes the code a bit more concise by removing the need for explicit
`.iter()`

style: move precondition checking to the match guard

the match arms above put the "sanity" checks in the guard, and call only
`check_pat` in the body. With this commit, the (tuple) struct cases
follow that convention as well. Well, almost -- I think the ident check
belongs to the second category of checks, so I put it in the body as
well

misc: use `None` in the pattern directly

this'll probably be marginally faster thanks to the equality check being
now structural

move the tests to the right file
2025-08-01 11:24:44 +02:00
Alejandra González
fab7eab7fb
Output lintcheck summary HTML markdown in order (#15371)
The data in the table needs to be in the same order as the headings.

changelog: none

Fixes rust-lang/rust-clippy#15370
2025-07-31 12:37:06 +00:00
Samuel Tardieu
e295a7d9f9
Simplify boolean expression in manual_assert 2025-07-30 20:11:04 +02:00
Jason Newcomb
3c54672d1a
Optimize some usages of !! and -- in suggestions (#15366)
When an expression is made of a `!` or `-` unary operator which does not
change the type of the expression, use a new variant in `Sugg` to denote
it. This allows replacing an extra application of the same operator by
the removal of the original operator instead.

Some suggestions will now be shown as `x` instead of `!!x`. Right now,
no suggestion seems to produce `--x`.

changelog: none
2025-07-30 17:35:10 +00:00
Alejandra González
445d41909e
Fix iter_on_single_items FP on function pointers and let stmts (#15013)
Closes rust-lang/rust-clippy#14981

changelog: [`iter_on_single_items`] fix FP on function pointers and let
stmts
2025-07-30 16:42:12 +00:00
Samuel Tardieu
18e8ac3778
chore: fix some minor issues in comments (#15372)
fix some minor issues in comments

changelog:none
2025-07-30 08:01:10 +00:00
Samuel Tardieu
436efbba90
Fix min_ident_chars: ignore on trait impl. (#15275)
fixes rust-lang/rust-clippy#13396

changelog: [`min_ident_chars`]: ignore lint when implementing a trait,
to respect [`renamed_function_params`]
2025-07-30 07:57:34 +00:00
houpo-bob
64276e688c chore: fix some minor issues in comments
Signed-off-by: houpo-bob <houpocun@outlook.com>
2025-07-30 15:49:56 +08:00
Samuel Tardieu
c57876242d
Output lintcheck summary HTML markdown in order
The data in the table needs to be in the same order as the headings.
2025-07-30 09:49:27 +02:00
Tom Webber
e8db4aa470 Fix min_ident_chars: add trait/impl awareness 2025-07-30 07:10:07 +02:00
Samuel Tardieu
642bec7617
Optimize some usages of double unary operators in suggestions
When an expression is made of a `!` or `-` unary operator which does not
change the type of the expression, use a new variant in `Sugg` to denote
it. This allows replacing an extra application of the same operator by
the removal of the original operator instead.

Also, when adding a unary operator to a suggestion, do not enclose the
operator argument in parentheses if it starts with a unary operator
itself unless it is a binary operation (including `as`), because in this
case parentheses are required to not bind the lhs only.

Some suggestions will now be shown as `x` instead of `!!x`. Right now,
no suggestion seems to produce `--x`.
2025-07-30 00:34:26 +02:00
Alejandra González
c7dd98c809
Do not autofix comments containing bare CR (#15175)
When a bare CR is present in a four slashes comment, keep triggering the
lint but do not issue a fix suggestion as bare CRs are not supported in
doc comments. An extra note is added to the diagnostic to warn the user
about it.

I have put the test in a separate file to make it clear that the bare CR
is not a formatting error.

Fixes rust-lang/rust-clippy#15174

changelog: [`four_forward_slashes`]: warn about bare CR in comment, and
do not propose invalid autofix
2025-07-29 17:05:13 +00:00
Alejandra González
b7cc5c45bd
Fix search_is_some suggests wrongly inside macro (#15135)
Closes rust-lang/rust-clippy#15102

changelog: [`search_is_some`] fix wrong suggestions inside macro
2025-07-29 16:31:55 +00:00
dswij
7b3bd5bc8c
Fix typo in internal error message (#15363)
changelog: none

@rustbot label +P-low +A-infra
2025-07-28 17:12:59 +00:00
Samuel Tardieu
431f95ec85
Fix typo in internal error message 2025-07-28 17:32:40 +02:00
Samuel Tardieu
4f1044a5a6
Do not specialize for if_chain any longer
Now that `if let` chains have been introduced, the `if_chain` external
crate is no longer necessary. Dropping special support for it also
alleviates the need to keep the crate as a dependency in tests.
2025-07-28 17:26:38 +02:00
Alex Macleod
d73a6b797f
Do not treat NixOS as a Pascal-cased identifier (#15361)
changelog: [`doc_markdown`]: do not treat NixOS as a Pascal-cased
identifier

Fixes rust-lang/rust-clippy#15360
2025-07-28 14:53:08 +00:00
Samuel Tardieu
a55517ff4b
Fix cast-lossless should not suggest when casting type is from macro input (#15358)
Closes rust-lang/rust-clippy#15348

The span of the `as` expr is also incorrect, but I believe it is not a
bug from Clippy.

changelog: [`cast-lossless`] fix wrong suggestions when casting type is
from macro input
2025-07-28 14:11:10 +00:00
yanglsh
938e79fdac fix: cast-lossless should not suggest when casting type is from macro input 2025-07-28 21:45:40 +08:00
Samuel Tardieu
18a13b15fe
Do not treat NixOS as a Pascal-cased identifier 2025-07-28 15:25:46 +02:00
dswij
f4f579f4ac
Fix match_single_binding wrongly handles scope (#15060)
Closes rust-lang/rust-clippy#15018
Closes rust-lang/rust-clippy#15269

Continuation of rust-lang/rust-clippy#15017

changelog: [`match_single_binding`] fix wrong handling of scope
2025-07-28 12:10:42 +00:00
Samuel Tardieu
4bfb6d3fb5
Fix typo non_std_lazy_statics.rs (#15357)
Changes `MaybeIncorret` to `MaybeIncorrect`.

And since this is part of a doc comment, it might as well be a link.

changelog: none
2025-07-27 13:34:57 +00:00
Samuel Moelius
9339d8cac3
Fix typo non_std_lazy_statics.rs
Changes `MaybeIncorret` to `MaybeIncorrect`.

And since this is part of a doc comment, it might as well be a link.

changelog: none
2025-07-27 08:55:33 -04:00
llogiq
887b500e23
Fix let_unit_value suggests wrongly for format macros (#15085)
Closes rust-lang/rust-clippy#15061

changelog: [`let_unit_value`] fix wrong suggestions for format macros
2025-07-27 12:23:29 +00:00
Timo
3174c05949
fix: unnecessary_map_or don't add parens if the parent expr comes f… (#15345)
…rom a macro

changelog: [`unnecessary_map_or`]: don't add parens if the parent expr
comes from a macro

fixes rust-lang/rust-clippy#14714
2025-07-27 12:15:17 +00:00
Timo
f126db47bc
Fix empty_structs_with_brackets suggests wrongly on generics (#15355)
Closes rust-lang/rust-clippy#15349

changelog: [`empty_structs_with_brackets`] fix wrong suggestions on
generics
2025-07-27 12:00:08 +00:00
Ada Alakbarova
81fc22753e
fix: unnecessary_map_or don't add parens if the parent expr comes from a macro 2025-07-27 13:54:47 +02:00
yanglsh
c78f3aedfc fix: empty_structs_with_brackets suggests wrongly on generics 2025-07-27 15:13:34 +08:00
Timo
651ca3372b
Detect prefixed attributes as duplicated (#15212)
Fix `duplicated_attributes` lint to detect prefixed attributes like
`clippy::lint_name`.
Fixes rust-lang/rust-clippy#14942

changelog: [`duplicated_attributes`]: detect duplicated prefixed
attributes
2025-07-26 19:07:12 +00:00
llogiq
f9ab9d0217
fix ip_constant when call wrapped in extra parens (#15339)
changelog: [`ip_constant`]: fix suggestion when call is inside
parentheses like `(Ipv4Addr::new(127, 0, 0, 1))`

Very similar to the fix in
https://github.com/rust-lang/rust-clippy/pull/15191
2025-07-26 15:23:47 +00:00
Samuel Moelius
e910c0e7e6 Deprecate string_to_string 2025-07-26 06:31:14 -04:00
Samuel Tardieu
03978193a5
Get myself back on assignment rotation (#15346)
changelog: none
2025-07-25 20:57:03 +00:00
Samuel Tardieu
03986e640c
Get myself back on assignment rotation 2025-07-25 22:51:47 +02:00
Philipp Krones
1db89a1b1c
Rustup (#15341)
r? @ghost

changelog: none
2025-07-25 13:14:01 +00:00
Philipp Krones
d0fa808df5
Fix if_same_then_else with if let conditions
Apparently they are no longer split 1 LHS + rest RHS
2025-07-25 15:08:50 +02:00
Philipp Krones
31baffd6ee
Bump nightly version -> 2025-07-25 2025-07-25 15:08:44 +02:00