Commit graph

21470 commits

Author SHA1 Message Date
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
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
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
Catherine Flores
64250a3360
Also deploy index.html file on release (#13971)
I noticed that this was missing bf482928 while doing the release. No
harm done, as it was updated on the next push to master.

changelog: none
2025-01-10 21:10:08 +00:00
Alejandra González
579571d9cf
New lint: manual_ok_err (#13740)
changelog: [`manual_ok_err`]: new lint

Detect manual implementations of `.ok()` or `.err()`, as in

```rust
let a = match func() {
    Ok(v) => Some(v),
    Err(_) => None,
};
let b = if let Err(v) = func() {
    Some(v)
} else {
    None
};
```

which can be replaced by

```rust
let a = func().ok();
let b = func().err();
```

This pattern was detected in the wild in the Rust reimplementation of
coreutils:
https://github.com/uutils/coreutils/pull/6886#pullrequestreview-2465160137
2025-01-10 19:19:58 +00:00
Philipp Krones
8678f9cdb6
CI: rerun the changelog check on PR synchronization (#13980)
Rerunning the PR checks when a PR is synchronized (new commits added, or
force-pushed) seems to remove the changelog checks from the UI while
keeping the PR mergeable from the maintainer's interface.

This PR reruns the cheap changelog check when a PR is synchronized.

changelog: none

r? @flip1995
2025-01-10 17:47:26 +00:00
Samuel Tardieu
4a69d0d4d8 New lint: manual_ok_err 2025-01-10 18:26:01 +01:00
Samuel Tardieu
1bdee5b6b3 CI: rerun the changelog check on PR synchronization
Rerunning the PR checks when a PR is synchronized (new commits added, or
force-pushed) seems to remove the changelog checks from the UI while
keeping the PR mergeable from the maintainer's interface.

This PR reruns the cheap changelog check when a PR is synchronized.
2025-01-10 18:17:55 +01:00
Philipp Krones
fc0e65d157
Use diagnostic item instead of path for core::fmt::Debug (#13949)
This removes the last call to `LateContext::match_def_path()` in
Clippy's code. The `LateContext::match_def_path()` in the compiler
sources was only kept for Clippy's usage.

Once this PR is merged and after the rustup, I will submit one to remove
`LateContext::match_def_path()` from the compiler.

changelog: none

r? @flip1995
2025-01-10 16:45:08 +00:00
Philipp Krones
cccb006cc0
CI: check the presence of the changelog line in every pull request (#13976)
Checking it only in the merge queue leads to deferred failures once the
decision to merge has been taken already.

- [X] Testing first without changelog line
- [x] Now that that has failed, adding the changelog line and
force-pushing

changelog: none
2025-01-10 16:31:50 +00:00
Samuel Tardieu
7639e82939 CI: check the presence of the changelog line in every pull request
Checking it only in the merge queue leads to deferred failures once the
decision to merge has been taken already.
2025-01-10 17:23:10 +01:00
Alejandra González
7611dbb047
Mention existing labels at CONTRIBUTING (#13978)
At CONTRIBUTING.md there are mentioned
[`l-crash`](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aopen+label%3Al-crash)
and
[`l-bug`](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aopen%20label%3Al-bug)
labels which are never used, so correct them to
[`I-ICE`](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aopen%20label%3AI-ICE)
and
[`C-bug`](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aopen%20label%3AC-bug)

changelog: none
2025-01-10 15:13:11 +00:00
alexey semenyuk
f3b1dd636d Fix labels 2025-01-10 18:27:19 +05:00
dswij
716a3a4778
Do not intersect spans coming from different contexts (#13942)
The code should not attempt to obtain a snippet by capping the function
signature span with its identifier span without checking that they are
in the same context.

This is the only instance I could identify where placeholders were used
instead of the real snippet when running the CI lintcheck. Moreover, the
placeholders were not even used, as they snippet was obtained
prematurely.

Found in the context of #13941

changelog: none
2025-01-10 12:33:19 +00:00
Fridtjof Stoldt
5c2601af15
Do not propose to elide lifetimes if this causes an ambiguity (#13929)
Some lifetimes in function return types are not bound to concrete
content and can be set arbitrarily. Clippy should not propose to replace
them by the default `'_` lifetime if such a lifetime cannot be
determined unambigously.

I added a field to the `LifetimeChecker` and `Usage` to flag lifetimes
that cannot be replaced by default ones, but it feels a bit hacky.

Fix #13923

changelog: [`needless_lifetimes`]: remove false positives by checking
that lifetimes can indeed be elided
2025-01-10 11:58:29 +00:00
Samuel Tardieu
d8301d762f Do not intersect spans coming from different contexts
The code should not attempt to obtain a snippet by capping the
function signature span with its identifier span without checking that
they are in the same context.
2025-01-10 10:02:27 +01:00
llogiq
197d58d591
Improve needless_as_bytes to also detect str::bytes() (#13972)
I ran Clippy on some projects after upgrading to 1.84, which found a
[needless use of
`as_bytes()`](https://github.com/rust-lang/rust-clippy/pull/13437). It
made me notice that the code was also using `bytes()` needlessly in
other places. This PR improves on the `as_bytes()` lint to also lint
`bytes()`.

----

changelog: none
2025-01-09 22:33:26 +00:00
Kevin Reid
db4aac6d21
Correct version of literal_string_with_formatting_args
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.
2025-01-09 11:33:48 -08:00
Quentin Santos
d5264c7a46 Check for needless uses of str::bytes()
This builds upon the lint for `str::as_bytes()`, and also covers
needless uses of the iterator version `str::bytes()`.
2025-01-09 18:44:43 +01:00
Quentin Santos
e42e354f65 Remove needless check of returned type
We are checking that we are calling the `as_bytes()` method of `String`
or `str`. Checking that it returns a `slice()` does not add anything.
2025-01-09 18:40:33 +01:00
Philipp Krones
55c8550221
Also deploy index.html file on release 2025-01-09 18:24:02 +01:00
Philipp Krones
19e305bb57
Rustup (#13970)
r? @ghost

changelog: none
2025-01-09 17:07:59 +00:00
Philipp Krones
663892bea7
Bump Clippy version -> 0.1.86 2025-01-09 18:01:44 +01:00
Philipp Krones
bb4a259908
Bump nightly version -> 2024-01-09 2025-01-09 18:01:20 +01:00
Philipp Krones
b5bf09e57a
Merge remote-tracking branch 'upstream/master' into rustup 2025-01-09 18:00:37 +01:00
Alex Macleod
894e87cd51
Fix type suggestion for manual_is_ascii_check (#13916)
Fixes #13913 .

changelog: [`manual_is_ascii_check`]: fix type suggestions for
references

Previously it only derived `char` and `u8` types, now it should always
annotate the lambda parameter with the correct type (e.g. `&char`).

I'm quite new to Rust and this is my first contact with clippy, so I'm
open for suggetions :)
2025-01-08 13:36:11 +00:00
Samuel Tardieu
c686ffd193 Do not propose to elide lifetimes if this causes an ambiguity
Some lifetimes in function return types are not bound to concrete
content and can be set arbitrarily. Clippy should not propose to replace
them by the default `'_` lifetime if such a lifetime cannot be
determined unambigously.
2025-01-08 12:50:00 +01:00
A_A
8461d3febd Remove unnecessary string allocation 2025-01-08 07:52:09 +01:00
Matthias Krüger
11f38ade90 Rollup merge of #134989 - max-niederman:guard-patterns-hir, r=oli-obk
Lower Guard Patterns to HIR.

Implements lowering of [guard patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see the [tracking issue](#129967)) to HIR.
2025-01-07 21:39:40 +01:00
Alex Macleod
f5ca68f9db
Do not remove identity mapping if mandatory mutability would be lost (#13905)
Removing `.map(identity)` may result in invalid code if the receiver of
`map()` is an immutable binding, and the result of `map()` is used as
the receiver of a method call expecting a mutable reference.

Fix #13904

changelog: [`map_identity`]: do not lint if this would cause mandatory
mutability to be lost
2025-01-07 13:43:46 +00:00
Alex Macleod
b7b69b1354
Remove unneeded parentheses in unnecessary_map_or lint output (#13932)
When the expression is transformed into an equality, parentheses are
needed only if the resulting equality is used:

- as a receiver in a method call
- as part of a binary or unary expression
- as part of a cast

In other cases, which will be the majority, no parentheses are required.
This makes the lint suggestions cleaner.

changelog: `none`
2025-01-07 13:37:52 +00:00
Philipp Krones
4ef917796a
CI: be compatible with both Rustup pre-1.28.0 and 1.28.0 (#13944)
`rustup show active-toolchain` will no longer install the default
toolchain starting from Rustup 1.28.0, and `rustup toolchain install`
without extra arguments is not supported in Rustup pre-1.28.0.

The Rustup change and proposed solution is described in
<https://internals.rust-lang.org/t/seeking-beta-testers-for-rustup-v1-28-0/22060>.

changelog: none
2025-01-07 13:31:29 +00:00
Fridtjof Stoldt
d0d5b8a34a
Don't emit machine applicable map_flatten lint if there are code comments (#13940)
Fixes https://github.com/rust-lang/rust-clippy/issues/8528.

Similar to #13911, if there are code comments, we don't want to remove
them automatically.

changelog: Don't emit machine applicable `map_flatten` lint if there are
code comments

r? @xFrednet
2025-01-07 09:09:19 +00:00
Catherine Flores
98b9a263bc
clippy::redundant_locals is not a correctness lint (#13747)
Even its documentation says so. According to the documentation, it might
either be a "suspicious" or a "perf" lint.

changelog: [`redundant_locals`]: Reclassify as "suspicious" lint.
2025-01-07 00:50:22 +00:00
hrxi
63487dde53 clippy::redundant_locals is not a correctness lint
Even its documentation says so. According to the documentation, it might
either be a "suspicious" or a "perf" lint.
2025-01-06 22:42:11 +01:00
Manish Goregaokar
0e2505ba8f
Do not trigger missing_const_for_fn for tests (#13945)
Close #13938

changelog: [`missing_const_for_fn`]: do not trigger for tests
2025-01-06 19:47:54 +00:00
Guillaume Gomez
78225ccca8 Add regression test for #8528 2025-01-06 17:35:55 +01:00
Guillaume Gomez
891e38788a Don't emit machine applicable map_flatten lint if there are code comments 2025-01-06 17:35:55 +01:00
Catherine Flores
a9c0e22dfa
Changelog for Clippy 1.84 🧨 (#13937)
Roses are red,
Violets are blue,
Happy new year,
full of happiness and cheer!

---

### The cat of this release is lizzy nominated by @jdonszelmann:

<img height=700
src="https://github.com/user-attachments/assets/612834d0-d584-4bf3-b11e-3564456c10ee"
alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

I've also updated the template to include the text I usually use for
moves, renames, or new lints.

changelog: none

---

That's it happy new year, kings, queens, and all other royalty! ❤️
2025-01-06 01:00:22 +00:00
Samuel Tardieu
c9315bc395 Use diagnostic item instead of path for core::fmt::Debug
This removes the last call to `LateContext::match_def_path()` in
Clippy's code. The `LateContext::match_def_path()` in the compiler
sources was only kept for Clippy's usage.
2025-01-05 22:13:42 +01:00
Alexey Semenyuk
ca55534c92 Do not trigger clippy::missing_const_for_fn triggering for tests 2025-01-06 02:07:16 +05:00
Fridtjof Stoldt
ad69c65906
Only emit useless_vec suggestion if the macro does not contain code comments (#13911)
Fixes #13692.

If the `vec!` macro call contains comments, we should not provide
suggestions and let users handle it however they see fit.

changelog: Only emit `useless_vec` suggestion if the macro does not
contain code comments
2025-01-04 23:33:30 +00:00
Samuel Tardieu
12d3137560 CI: be compatible with both Rustup pre-1.28.0 and 1.28.0
`rustup show active-toolchain` will no longer install the default
toolchain starting from Rustup 1.28.0, and `rustup toolchain install`
without extra arguments is not supported in Rustup pre-1.28.0.
2025-01-04 23:12:32 +01:00
Alejandra González
54f88c3c75
[needless_continue]: lint if the last stmt in loop is continue recurisvely (#13891)
fixes: #4077

Continuation of #11546. r? @y21 if you don't mind?

changelog: [`needless_continue`] lint if the last stmt in loop is
`continue` recurisvely
2025-01-04 21:52:42 +00:00
Fridtjof Stoldt
622382b6c6
Fix year in CHANGELOG.md
copy-pasta got the better of me xD 🍝

Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
2025-01-04 22:28:51 +01:00
Jubilee
5262111eba Rollup merge of #135046 - RalfJung:rustc_box_intrinsic, r=compiler-errors
turn rustc_box into an intrinsic

I am not entirely sure why this was made a special magic attribute, but an intrinsic seems like a more natural way to add magic expressions to the language.
2025-01-04 07:57:33 -08:00