Commit graph

22047 commits

Author SHA1 Message Date
Manish Goregaokar
48ce25ea0e
Add MSRV check for question_mark (#14436)
changelog: [`question_mark`]: Now respects the [`msrv`] configuration
2025-03-19 15:56:45 +00:00
Alejandra González
31497d68fb
fix: option_if_let_else FP when value partially moved (#14209)
fixes #13964

The lint `option_map_unwrap_or` used to have a similar issue in #10579,
so I borrowed its solution to fix this one.

changelog: [`option_if_let_else`]: fix FP when value partially moved
2025-03-19 15:34:53 +00:00
Jan Verbeek
d793c0abfa Add MSRV check for question_mark 2025-03-19 09:33:58 +01:00
Alex Macleod
a422d9e68c
fix: bad indent in doc comments (#14419)
TLDR
```diff
- ///    01234
+ ///     01234
     12345
```

Sometimes, in doc comments, there are 3 spaces + 1 instead of 4 spaces +
1.
To make it coherent with the rest of the clippy codebase, I `fd -t f -X
sed -E -i 's,///\s{4}(\S),/// \1,g'` and manually verified and fixed the
relevant part of code that had bad indentation.

### Example

```rs
/// fn a() {
///    01234
/// }
```
Becomes
```rs
/// fn a() {
///     01234
/// }
```

changelog: none
2025-03-18 13:59:53 +00:00
Alex Macleod
d443f38f73
Reinstate single_match/single_match_else lints with comments (#14420)
Commit efe3fe9b8c removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.

changelog: [`single_match`, `single_match_else`]: reinstate lint when
comments are inside the `match` but do not autofix the code

Fix #14418
2025-03-18 12:45:19 +00:00
Alejandra González
ea30a09fe1
Leave assignments for now (#14428)
I love this project but I (again) don't have the time nor energy at the
moment. Will go through my current assignments over time and still
review occasionally.

PS: sorry about the branch on upstream!
changelog: none
2025-03-18 12:29:56 +00:00
Philipp Krones
a07e887e24
Improve string_to_string lint in case it is in a map call (#14396)
Fixes https://github.com/rust-lang/rust-clippy/issues/14175.

There are two "big" cases to handle: `.map(|x| x.to_string())` and
`.map(String::to_string)`. If the closure has more than one expression,
we should not suggest `.cloned()`.

changelog: Improve `string_to_string` lint in case it is in a map call

r? @samueltardieu
2025-03-18 10:29:10 +00:00
Guillaume Gomez
269b913bfd Better handle blocks with just one expression 2025-03-18 11:09:20 +01:00
Catherine Flores
b057ba4622
Leave assignments for now
I love this project but I (again) don't have the time nor energy at the moment. Will go through my current assignments over time and still review occasionally.
2025-03-17 22:34:44 -05:00
Samuel Tardieu
a1bdc191ba Reinstate single_match/single_match_else lints with comments
Commit efe3fe9b8c removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.
2025-03-17 16:14:14 +01:00
yanglsh
a3865b1a3d fix: option_if_let_else FP when value partially moved 2025-03-17 14:36:29 +08:00
Alejandra González
4800557857
question_mark: avoid incorrect suggestion when ref binding used (#14158)
changelog: [`question_mark`]: avoid incorrect suggestion when `ref`
binding used

Fixes #13417
2025-03-16 23:25:26 +00:00
tk
b23fcb0147 fix: bad indent in doc comments
Sometimes, in doc comments, there are 3 spaces + 1 instead of 4 spaces + 1.
To make it coherent with the rest of the clippy codebase, I `fd -t f -X sed -E -i 's,///    (\S),///     \1,g'` and manually verified and fixed the relevant part of code that had bad indentation.
2025-03-16 19:36:09 +01:00
Alex Macleod
775a5c2712
fix incorrect suggestions related to parentheses in needless_return (#14094)
close #12157

`needless_return` sometimes makes incorrect suggestions by omitting
necessary enclosing parentheses. This PR resolves the issue by using
`clippy_utils::sugg::Sugg`.

changelog: [`needless_return`]: now makes correct suggestions which
require enclosing parentheses
2025-03-16 15:03:14 +00:00
Fridtjof Stoldt
1617a2e519
Remove @xFrednet from docs 👋 (#14415)
Cleaning up the last few loose ends. To everyone reading this: I hope
you have a beautiful day!

changelog: none

r? @ghost
2025-03-16 14:52:51 +00:00
Fridtjof Stoldt
3c7dfacf44
new lint: doc_comment_double_space_linebreaks (#12876)
Fixes https://github.com/rust-lang/rust-clippy/issues/12163

I decided to initially make this a restriction lint because it felt a
bit niche and opinionated to be a warn-by-default style lint. It may be
appropriate as a style lint if the standard or convention *is* to use
`\` as doc comment linebreaks - not sure if they are!

The wording on the help message could be improved, as well as the name
of the lint itself since it's a bit wordy - suggestions welcome.

This lint works on both `///` and `//!` doc comments.

changelog: new lint: `doc_comment_double_space_linebreaks`
2025-03-16 14:44:02 +00:00
xFrednet
9845b100ec
Remove @xFrednet from docs 👋 2025-03-16 15:19:49 +01:00
Michael Howell
4e9caa3985 question_mark: suggest as_ref/as_mut if ref binding is used 2025-03-15 15:59:24 -07:00
Alex Macleod
5c031d1f6a
Fix from_over_into lint suggesting invalid code (#14409)
fixes [#112502](https://github.com/rust-lang/rust/issues/112502)

changelog: [`from_over_into`]: fix invalid code suggestion when self
parameter has type annotation
2025-03-15 01:31:30 +00:00
KonaeAkira
9c897a20ae Simplify implementation 2025-03-15 00:37:44 +01:00
KonaeAkira
4a324c9dff Fix from_over_into lint suggesting invalid code 2025-03-15 00:05:32 +01:00
KonaeAkira
da910b14e2 Add failing from_over_into test case 2025-03-15 00:00:01 +01:00
Philipp Krones
f85331f4d1
Explain is_from_proc_macro and proc_macros auxiliary crate in the book (#14398)
This comes up every now and then in PRs, so I think it would be good if
we had an explanation in a central place that we can link to.

changelog: none
2025-03-13 14:23:13 +00:00
Alex Macleod
c07fd4824a
Update copyright year (#14399)
Update copyright year

changelog: none
2025-03-13 13:36:31 +00:00
Guillaume Gomez
0e4b6c8124 Make string_to_string emit a suggestion when cloned can be used 2025-03-13 11:46:02 +01:00
Catherine Flores
18061e2c42
incompatible_msrv: lint function calls with any argument count (#14216)
The lint for function calls was previously restricted to functions
taking exactly one argument. This was not documented.

Generalizing the lint to an arbitrary number of arguments in the
function call requires special casing some macro expansions from the
standard library. Macros such as `panic!()` or `assert_eq!()` exist
since Rust 1.0.0, but modern stdlib expand those macros into calls to
functions introduced in later Rust versions. While it is desirable to
lint code inside macros, using MSRV-incompatible functions coming from
`core` in macro expansions has been special-cased to not trigger this
lint.

Also, code coming from compiler desugaring may contain function calls
(for example, `a..=b` is now desugared into `RangeInclusive::new(a, b)`.
Those should not be linted either as the compiler is allowed to use
unstable function calls.

Fix #14212

changelog: [`incompatible_msrv`]: lint function calls with any argument
count
2025-03-13 04:11:42 +00:00
Alexey Semenyuk
559f23e1f2 Update copyright year 2025-03-13 02:01:16 +05:00
Guillaume Gomez
0ffc6cf097 Add ui test for string_to_string in map calls 2025-03-12 19:59:27 +01:00
Guillaume Gomez
21601fd042 Improve string_to_string lint in case it is in a map call 2025-03-12 19:59:27 +01:00
y21
44094e5148 explain is_from_proc_macro in the book 2025-03-12 18:25:25 +01:00
Philipp Krones
72540726b1
needless_pass_by_value: reference the innermost Option content (#14392)
If types such as `Option<Option<String>>` are not used by value, then
`Option<Option<&String>>` will be suggested, instead of
`Option<&Option<String>>`.

changelog: [`needless_pass_by_value`]: suggest using a reference on the
innermost `Option` content

fix #14375
2025-03-12 16:07:47 +00:00
Samuel Tardieu
417d4e6210 needless_pass_by_value: make verbose suggestion
This reduces the number of snippet manipulations, and shows the new
reference in context.
2025-03-12 13:50:04 +01:00
Philipp Krones
0730678e26
Make annotations mandatory for internal ui tests (#14393)
Last part of https://github.com/rust-lang/rust-clippy/pull/11421.

Now all ui tests require annotations.

The change in `ui_test` is to add `ICE:` errors.

changelog: Make internals ui tests annotations mandatory

r? @flip1995
2025-03-12 11:01:24 +00:00
Guillaume Gomez
092a20ec11 Update lint_message_convention test to allow clippy "help" message 2025-03-12 11:41:26 +01:00
Guillaume Gomez
ec8c0b3755 Make annotations mandatory for internal ui tests 2025-03-12 11:32:40 +01:00
Guillaume Gomez
e4d3b0a072 Update produce_ice so its error can be checked in ui tests 2025-03-12 11:32:27 +01:00
Guillaume Gomez
cfc743226e Update ui_test version to 0.29.2 2025-03-12 11:29:54 +01:00
Samuel Tardieu
35e6057e71 needless_pass_by_value: reference the innermost Option content
If types such as `Option<Option<String>>` are not used by value, then
`Option<Option<&String>>` will be suggested, instead of
`Option<&Option<String>>`.
2025-03-12 06:57:25 +01:00
Alex Macleod
714c64c7a1
fix: unnecessary_safety_comment FP on desugared assign (#14371)
Closes #13039

changelog: [`unnecessary_safety_comment`]: fix FP on desugared assign
2025-03-12 02:27:43 +00:00
Philipp Krones
8f280ff813
Add missing tests annotations for ui-internal (#14388)
Follow-up of https://github.com/rust-lang/rust-clippy/pull/11421.

I can't yet make the annotations mandatory because there is an issue
with `tests/ui-internal/custom_ice_message.rs`: the error message is not
emitted as JSON, meaning that we can't match it with `ui_test`. I need
to check if it's a bug in rustc or if `ui_test` needs to handle this
case somehow.

changelog: Add missing tests annotations for `ui-internal`

r? @flip1995
2025-03-11 16:10:14 +00:00
Guillaume Gomez
cb9682b628 Add missing tests annotations for ui-internal 2025-03-11 16:35:11 +01:00
Philipp Krones
a5bc316445
add macos-latest as a CI target (#14342)
r? flip1995

changelog: none
2025-03-11 13:35:56 +00:00
Philipp Krones
a25cbd50ca
Improve needless_pass_by_value suggestion (#13880)
Fixes https://github.com/rust-lang/rust-clippy/issues/13744.

A simple check to check if the type is an `Option` allows to improve the
suggestion.

changelog: Improve `needless_pass_by_value` suggestion
2025-03-10 15:48:43 +00:00
yanglsh
97275d523c fix: unnecessary_safety_comment FP on desugared assign 2025-03-10 12:36:37 +08:00
Timo
819f3c7c67
arbitrary_source_item_ordering: Make alphabetic ordering in module item groups optional (#13718)
From feedback to the `arbitrary_source_item_ordering` lint after its
inclusion in clippy 1.82, making alphabetic ordering within module item
groups has turned out to be the most requested improvement. With this
improvement, it is possible to make the lint perform certain top-level
structural checks on modules (e.g. use statements and module inclusions
at the top), but still leaving everything else up to the developer.

Implements parts of the suggestions from #13675. A catch-all-group is
still to be implemented.

changelog: [`arbitrary_source_item_ordering`]: Make alphabetic ordering
in module item groups optional (off by default)
2025-03-09 20:25:30 +00:00
Manish Goregaokar
3d775b3963
docs: Add documentation to json.rs module (#14383)
Add top-level documentation comments to improve code readability and
maintainability in the json.rs module.
- Add module-level documentation describing JSON serialization and diff
functionality
- Document LintJson struct
- Add function-level documentation to explain purpose and behavior
- Document missing constants and structs

changelog: none
2025-03-09 17:41:43 +00:00
Alex Macleod
7bae269e3a
fix broken theme CSS links in the website (#14379)
Currently, some parts of the
[website](https://rust-lang.github.io/rust-clippy/master/index.html)'s
CSS are not being applied. This seems to be due to a broken link to the
originally referenced CSS. I suspect
https://github.com/rust-lang/mdBook/pull/1368.

changelog: none
2025-03-09 14:33:57 +00:00
Turtel216
184feee826 Fix key function description 2025-03-09 16:29:07 +02:00
Turtel216
8dd65e4098 Add documentation to json.rs module 2025-03-09 16:03:12 +02:00
lapla-cogito
ab21f716fc
fix broken CSS links 2025-03-09 21:01:59 +09:00