Commit graph

21519 commits

Author SHA1 Message Date
lapla-cogito
ac87b0cb73
fix ICE in unnecessary_mut_passed 2025-01-23 12:40:12 +09:00
Timo
396de5748b
don't trigger needless_late_init when the first usage is in macro (#14053)
fix #13776

changelog: [`needless_late_init`]: don't trigger `needless_late_init`
when the first usage is in macro
2025-01-22 01:56:53 +00:00
lapla-cogito
26838f8552
don't trigger needless_late_init when the first usage is in macro 2025-01-22 10:44:53 +09:00
Timo
d1b5fa2416
fix: correct suggestion for significant_drop_in_scrutinee in expressions (#14019)
This PR fixes an issue with the `significant_drop_in_scrutinee`, where
the lint generates invalid Rust syntax when suggesting fixes for match
expressions that are part of larger expressions, such as in assignment
contexts. For example:

```rust
    let mutex = Mutex::new(State {});
    let _ = match mutex.lock().unwrap().foo() {
        true => 0,
        false => 1,
    };
```
would suggest:
```rust
let _ = let value = mutex.lock().unwrap().foo();
match value {
```
With this PR, it now suggests:
```rust
let value = mutex.lock().unwrap().foo();
let _ = match value {
```

closes: #13986

changelog: [`significant_drop_in_scrutinee`] Fix incorrect suggestion
for `significant_drop_in_scrutinee` lint in expression context
2025-01-21 02:28:23 +00:00
llogiq
8f1b4bb87a
New lint: unnecessary_semicolon (#14032)
This lint detects and removes the unnecessary semicolon after a `match`
or `if` statement returning `()`. It seems to be quite a common
"mistake", given the number of hits (88) we had in the Clippy sources
themselves.

The lint doesn't bother about loops, as `rustfmt` already removes the
extra semicolon. It doesn't handle blocks either, as an extra block
level, followed or not by a semicolon, is likely intentional.

I propose to put the lint in `pedantic`, as putting it in `style` seems
quite hazardous given the number of hits.

Note: there exists a `redundant-semicolon` lint in the compiler, but it
is an early lint and cannot check that the expression evaluates to `()`,
so it ignores the cases we're handling here.

----

changelog: [`unnecessary_semicolon`]: new lint
2025-01-20 17:39:37 +00:00
Timo
2280b8a099
Use clearer multipart suggestions for unnecessary_map_or lint (#13998)
A multipart suggestion will be used whenever the method call can be
replaced by another one with the first argument removed. It helps place
the new method call in context, especially when it is part of a larger
expression.

This fixes #13995 by applying a suggestion made by @y21.

r? @y21

changelog: [`unnecessary_map_or`]: better representation of suggestions
by placing them in context
2025-01-19 22:11:46 +00:00
Timo
0707fe8474
add a new lint for repeat().take() that can be replaced with repeat_n() (#13858)
close #13271

changelog: add new `manual_repeat_n` lint
2025-01-19 21:59:22 +00:00
Samuel Tardieu
3a7f50f6d3 Apply unnecessary_semicolon to Clippy sources 2025-01-19 15:34:07 +01:00
Samuel Tardieu
51b0107d28 New lint: unnecessary_semicolon 2025-01-19 15:34:07 +01:00
Alex Macleod
e692cd4b30
change literal_string_with_formatting_args lint category to nursery (#14014)
This PR changes literal_string_with_formatting_args category from
`suspicious` to `nursery` since there are thousands of false positive on
GitHub.

Closes #13989 since it's no longer problematic with such false positive
with ~~`pedantic`~~ `nursery` category.

changelog: [`literal_string_with_formatting_args` ] change category to
`nursery` from `suspicious`
2025-01-19 11:58:32 +00:00
Samuel Tardieu
7f37b2af97 Use clearer multipart suggestions for unnecessary_map_or lint
A multipart suggestion will be used whenever the method call can be
replaced by another one with the first argument removed. It helps place
the new method call in context, especially when it is part of a larger
expression.
2025-01-19 10:06:21 +01:00
anatawa12
fbf66310c1
chore: change to nursery instead 2025-01-19 12:38:59 +09:00
Alex Macleod
2220806d69
Emit missing_const_for_fn for CONST_MUT_REFS (#13839)
1.83 stabilized `CONST_MUT_REFS`, also allowing for `const fn` to mutate
through mutable references. This ensures `missing_const_for_fn` is
emitted for those cases.

changelog: [`missing_const_for_fn`]: Now suggests marking some functions
taking mutable references `const`
2025-01-18 17:52:49 +00:00
Timo
38828bf89a
Fix typo in check_clousure function name (#14025)
I noticed this because I failed to find this `check_closure` by
grepping.

changelog: none
2025-01-18 17:32:30 +00:00
Samuel Tardieu
a487c601a4 Fix typo in check_clousure function name 2025-01-18 16:08:42 +01:00
Thomas Churchman
f327640706 Emit missing_const_for_fn for CONST_MUT_REFS 2025-01-18 13:31:04 +01:00
llogiq
10045db878
Update doc wildcard_dependencies (#13810)
Currently
https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies
doc doesn't contain explanation how it should be so added more details

----

changelog: none
2025-01-17 21:30:54 +00:00
alexey semenyuk
3f4aa9bf6e Update doc wildcard_dependencies 2025-01-18 01:20:22 +05:00
Vishruth-Thimmaiah
23e602cd94
fix: correct suggestion for significant_drop_in_scrutinee in expressions
fixes: #13986
2025-01-17 23:54:42 +05:30
Alejandra González
e359e88088
fix version search in the website (#14016)
fix #14015

changelog: none
2025-01-17 13:59:58 +00:00
lapla-cogito
e307b2f0c6
fix version search in the website 2025-01-17 18:16:40 +09:00
anatawa12
ee522d8d15
change literal_string_with_formatting_args lint to pedantic 2025-01-17 15:37:48 +09:00
Fridtjof Stoldt
8d0c0eb917
Pause assignments for @xFrednet (#14005)
I'll take a short break from auto assignments. My last few weeks have
been busy and I feel like getting my inbox back in order and taking a
short breather will be the best for me.

I still plan to review the PRs I'm currently assigned to and writing the
changelogs.

Jup that's it, have a good day, who ever is reading this =^.^=

changelog: none
2025-01-15 20:16:41 +00:00
xFrednet
7485970298
Pause assignments for @xFrednet 2025-01-15 21:08:43 +01:00
lapla-cogito
9a1bbe91bc
use repeat_n() where available 2025-01-15 13:15:41 +09:00
lapla-cogito
544f71f48d
add manual_repeat_n lint 2025-01-15 13:15:35 +09:00
Manish Goregaokar
25d319d1b2
New lint useless-nonzero-new_unchecked (#13993)
changelog: [`useless-nonzero-new_unchecked`]: new lint

Close #13991

### What it does

Checks for `NonZero*::new_unchecked(<literal>)` being used in a `const`
context.

### Why is this bad?

Using `NonZero*::new_unchecked()` is an `unsafe` function and requires
an `unsafe` context. When used with an
integer literal in a `const` context, `NonZero*::new().unwrap()` will
provide the same result with identical
runtime performances while not requiring `unsafe`.

### Example
```no_run
const PLAYERS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) };
```
Use instead:
```no_run
const PLAYERS: NonZeroUsize = NonZeroUsize::new(3).unwrap();
```
2025-01-15 01:00:54 +00:00
Alex Macleod
98761e4812
Rust 1.81 and later support elision with explicit self types (#13992)
Commit 9ef6e2199c introduced a check to
ensure that Clippy doesn't consider a lifetime present in an explicit
self types as being the default for an elided output lifetime. For
example, elision did not work in the case like:

```rust
  fn func(self: &Rc<Self>, &str) -> &str { … }
```

Since Rust 1.81.0, the lifetime in the self type is now considered the
default for elision. Elision should then be suggested when appropriate.

changelog: [`needless_lifetimes`]: suggest elision of lifetimes present
in explicit self types as well

r? @Alexendoo
because of #8278
2025-01-14 22:42:23 +00:00
Alejandra González
7e83ec57c6
Suggest manual_div_ceil even when right operand is a constant (#13951)
changelog: [`manual_div_ceil`]: lint constants as well

Fix #13950
2025-01-14 19:06:32 +00:00
dswij
8c1ea9fa01
Do not look for significant drop inside .await expansion (#13985)
Temporaries created inside the expansion of `.await` will be dropped and
need no checking. Looking inside the expansion will trigger false
positives.

changelog: [`significant_drop_in_scrutinee`]: do not falsely warn for
temporaries created by `.await` expansion

Fix #13927
2025-01-14 08:56:39 +00:00
Samuel Tardieu
35dbaf8a61 New lint useless-nonzero-new_unchecked 2025-01-13 23:38:29 +01:00
Samuel Tardieu
8b7cfc75dd Rust 1.81 and later support elision with explicit self types
Commit 9ef6e2199c introduced a check to
ensure that Clippy doesn't consider a lifetime present in an explicit
self type as being the default for an elided output lifetime. For
example, elision did not work in the case like:

```rust
  fn func(self: &Rc<Self>, &str) -> &str { … }
```

Since Rust 1.81.0, the lifetime in the self type is now considered
the default for elision. Elision should then be suggested when
appropriate.
2025-01-13 23:34:19 +01:00
Samuel Tardieu
dc23fa5e6c Suggest manual_div_ceil even when right operand is a constant 2025-01-13 19:29:02 +01:00
Philipp Krones
6ab6c3c809
Select Rust edition 2024 for compiling Clippy (#13751)
The Cargo feature is no longer experimental and is enabled by default in
our nightly compiler.

changelog: Clippy now uses Rust edition 2024
2025-01-13 18:05:05 +00:00
Samuel Tardieu
a4805ff610 Select edition 2024 2025-01-13 16:55:42 +01:00
Samuel Tardieu
6c367cb83f Update mdbook to 0.4.43 2025-01-13 16:55:42 +01:00
Alejandra González
dcbe3adc4b
auto-fix slow_vector_initialization in some cases (#13947)
changelog: [`slow_vector_initialization`]: auto-fix when appropriate

I made a change for `slow_vector_initialization` lint suggestion to use
`vec!` with size and remove the unneeded `resize` (or similar one) call
in #13912, while only the former one was suggested in the previous
implementation. Now, I think this lint can be automatically fixed with
no unnecessary code in some cases. I wrote “in some cases” because if
there are comments between vector declaration and `resize`, Clippy
shouldn't apply auto-fix because the comment may informational.
2025-01-13 15:12:01 +00:00
Samuel Tardieu
0456e4d6a1 In edition 2024, gen is a reserved keyword 2025-01-13 15:59:34 +01:00
Samuel Tardieu
a73166872d In edition 2024, std::env::set_var is unsafe 2025-01-13 15:58:11 +01:00
Philipp Krones
0db64118ca
fix(adding_lints): usage of early vs late lint pass (#13955)
changelog: none

This PR fixes explaining the difference in usage between early and late
lint passes in the book.
2025-01-13 13:21:00 +00:00
Philipp Krones
dc99034fd4
Fix link to release tags (#13930)
Since we do release tag it makes more sense to refer to tags page then
empty releases page

changelog: none
2025-01-13 13:09:33 +00:00
Philipp Krones
2d8a3e8cde
Fix not found links at Book (#13935)
Some of the links are wrong since lead to non existing docs so fix them

changelog: none
2025-01-13 10:55:57 +00:00
Philipp Krones
23f1ebeea2
Fix macro name in the Book (#13958)
`define_clippy_lints` does not exist, `declare_clippy_lint` exists.

changelog: none
2025-01-13 10:54:49 +00:00
Timo
8f257c71a3
don't suggest to use cloned for Cow in unnecessary_to_owned (#13853)
fix #13624

changelog: [`unnecessary_to_owned`]: don't suggest to use `cloned` on
`Cow` in `unnecessary_to_owned`
2025-01-12 21:27:10 +00:00
Catherine Flores
d648cc9a2c
Do not trigger redundant_pub_crate in external macros (#13952)
Some widely used crates, such as `pin-project-lite`, make use of a
`pub(crate)` construct in a private module inside a public macro. This
makes unrelated project trigger the lint.

There is also an unfortunate situation for Clippy itself: when a new
version of `pin-project-lite` or similar lint-trigerring crates is
released, those lints which can be found in hundreds of occurrences in
dependent crates will change, and appear as diffs in unrelated Clippy PR
because the base lintcheck run will be cached with the ancient release
of the crates. We currently have the situation
[here](https://github.com/rust-lang/rust-clippy/actions/runs/12635410895?pr=13851#user-content-redundant-pub-crate-removed),
which 219 lints removed and 219 lints added because of a
`pin-project-lite` version change between runs, and the fact that
`redundant_pub_crate` triggers on external macros.

Also:
- Fix #10636
- Fix #12213

changelog: [`redundant_pub_crate`]: do not trigger on external macros
2025-01-12 15:15:51 +00:00
Samuel Tardieu
5f75715398 Do not trigger redundant_pub_crate in external macros 2025-01-12 09:24:04 +01:00
Catherine Flores
34d109fd26
Add new lint unneeded_struct_pattern (#13465)
Closes #13400.

changelog: [`unneeded_struct_pattern`]: Add new lint
2025-01-12 02:09:18 +00:00
Timo
a895bebcd7
add more test coverage for #11230 (#13915)
Closes #11230

changelog:  none
2025-01-11 23:28:57 +00:00
Samuel Tardieu
0b402baf15 Do not look for significant drop inside .await expansion
Temporaries created inside the expansion of `.await` will be dropped and need
no checking. Looking inside the expansion will trigger false positives.
2025-01-11 14:09:07 +01:00
Catherine Flores
ab55d3fc62
Correct version of literal_string_with_formatting_args (#13974)
It claims to be in 1.83 but in fact will not be until 1.85.

Evidence: <https://github.com/rust-lang/rust/pull/134788> is where it
was merged into rust-lang/rust, and has a milestone of 1.85.

changelog: none
2025-01-10 21:14:40 +00:00