Commit graph

20436 commits

Author SHA1 Message Date
xFrednet
0532104247
Migrating restriction lints to span_lint_and_then (e -> i) 2024-08-03 10:18:15 +02:00
xFrednet
a9d72c7107
Migrating restriction lints to span_lint_and_then (a -> d) 2024-08-03 10:18:05 +02:00
bors
1ea827fa03 Auto merge of #13115 - tesuji:rm-dup-peels, r=dswij
Remove duplicated `peel_middle_ty_refs`

TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?

changelog: none
2024-08-03 07:32:30 +00:00
bors
1aa686b9c0 Auto merge of #13126 - apoisternex:issue12751, r=dswij
Fix [`redundant_slicing`] when the slice is behind a mutable reference

Fixes #12751

changelog: Fix [`redundant_slicing`] when the slice is behind a mutable reference and a immutable reference is expected.
2024-08-03 07:23:58 +00:00
bors
2fc74a3931 Auto merge of #13108 - tesuji:fix_redundant_closure, r=xFrednet
Fix `redundant_closure` false positive with closures has return type contains  `'static`

Fix #13073 .

Please enable "ignore white-space change" settings in github UI for easy reviewing.

HACK: The third commit contains a hack to check if a type `T: 'static` when `fn() -> U where U: 'static`.
I don't have a clean way to check for it.

changelog: [`redundant_closure`] Fix false positive with closures has return type contains  `'static`
2024-08-01 07:55:37 +00:00
bors
5542309895 Auto merge of #13195 - GuillaumeGomez:fix-false-positive-13183, r=Manishearth
Fix false positive for `missing_backticks` in footnote references

Fixes #13183.

changelog: Fix false positive for `missing_backticks` in footnote references
2024-07-31 16:06:27 +00:00
Guillaume Gomez
edca73003b Fix false positive for missing_backticks in footnote references 2024-07-31 17:27:53 +02:00
bors
ea06fa326d Auto merge of #13177 - GuillaumeGomez:fix-broken-list-lints-config, r=xFrednet
Fix broken list for lints config

Follow-up of #13166.

Finally figured out that it was a transformation and not the source that was the problem. It now looks like this:

![Screenshot from 2024-07-29 16-29-10](https://github.com/user-attachments/assets/4b89b3fe-8f85-47b8-8d9a-505badeaeac4)

r? `@xFrednet`

changelog: none
2024-07-31 11:11:39 +00:00
bors
c6f45df3c1 Auto merge of #13181 - Alexendoo:implicit-hasher-suggestion, r=llogiq
Use a single multipart suggestion for `implicit_hasher`

The second commit individually shows the diagnostic change

----

changelog: none
2024-07-30 20:02:53 +00:00
bors
8f3cfb4974 Auto merge of #13182 - Alexendoo:remove-allows, r=Manishearth
Remove some miscellaneous `#[allow]`s

Some were unneeded, others were removed by fixing/removing the thing they allow

changelog: none
2024-07-30 02:34:26 +00:00
bors
accf6868ee Auto merge of #13178 - GuillaumeGomez:clippy-lints-page-improvement, r=Alexendoo
Add possibility to focus on search input using keyboard

This PR adds the possibility to focus on the search input with `S` or `/` like in rustdoc and `mdbook` and `docs.rs` (unification++). Pressing escape will blur it.

r? `@Alexendoo`

changelog: Add possibility to focus on search input using keyboard
2024-07-29 19:58:12 +00:00
Alex Macleod
943a8e0646 Remove some miscellaneous #[allow]s 2024-07-29 19:57:39 +00:00
Guillaume Gomez
63174792c2 Add possibility to focus on search input using keyboard 2024-07-29 21:55:36 +02:00
Alex Macleod
33b16d31c2 implicit_hasher: use a single multipart suggestion 2024-07-29 17:56:27 +00:00
Alex Macleod
79783e95ad Fix implicit_hasher test not compiling 2024-07-29 17:44:57 +00:00
bors
834b691a9f Auto merge of #13174 - y21:if_let_mutex_multi_mutex, r=llogiq
Emit `if_let_mutex` in presence of other mutexes

Currently (master, not nightly nor stable) `if_let_mutex` does not emit a warning here:
```rs
let m1 = Mutex::new(10);
let m2 = Mutex::new(());

if let 100..=200 = *m1.lock().unwrap() {
  m2.lock();
} else {
  m1.lock();
}
```
It currently looks for the first call to `.lock()` on *any* mutex receiver inside of the if/else body, and only later (outside of the visitor) checks that the receiver matches the mutex in the scrutinee. That means that in cases like the above, it finds the `m2.lock()` expression, stops the visitor, fails the check that it's the same mutex (`m2` != `m1`) and then does not look for any other `.lock()` calls.

So, just make the receiver check also part of the visitor so that we only stop the visitor when we also find the right receiver.

The first commit has the actual changes described here. The sceond one just unnests all the `if let`s

----

changelog: none
2024-07-29 17:41:34 +00:00
bors
53420926ae Auto merge of #13179 - GuillaumeGomez:clean-up-lints-page-js, r=Alexendoo
Clean up clippy lints page JS source code

Just a small cleanup for the lints page JS source code.

r? `@Alexendoo`

changelog: Clean up clippy lints page JS source code
2024-07-29 15:04:30 +00:00
Guillaume Gomez
957a301083 Clean up clippy lints page JS source code 2024-07-29 16:49:56 +02:00
Guillaume Gomez
712e8f4f48 Fix broken list for lints config 2024-07-29 16:30:59 +02:00
bors
3b64ca95a9 Auto merge of #13173 - Jarcho:conf_order, r=xFrednet
Misc changes to `clippy_config`

Contains part of #13084

Changes include:
* Sort config list and each configs lint list.
* Add default text for the two configs that were missing it.
* Switch the lint list in the configs to an attribute.
* Make `dev fmt` sort the config list.

r? `@xFrednet`

changelog: none
2024-07-29 13:19:01 +00:00
bors
f7db8952e6 Auto merge of #13176 - shenyifu:master, r=Manishearth
Fix fix under loop may dropping loop label when applying fix.

changelog: [`explicit_counter_loop`]: fix label drop
changelog: [`for_kv_map`]: add label drop test
2024-07-29 10:38:25 +00:00
shenyifu
38a3462037 Fix fix under loop may dropping loop label when applying fix. 2024-07-29 17:43:03 +08:00
y21
61dcf6cfe0 inline a bunch of if lets into a single let chain 2024-07-28 18:28:24 +02:00
y21
1a1c978f8e [if_let_mutex]: make the mutex check part of the expr visitor 2024-07-28 18:27:53 +02:00
bors
668b659b47 Auto merge of #13166 - GuillaumeGomez:fix-clippy-doc, r=xFrednet
Fix display of configs in clippy doc page

Fixes https://github.com/rust-lang/rust-clippy/issues/13051.

It was simply some empty lines missing between configs. With this fix it looks like expected:

![image](https://github.com/user-attachments/assets/89c609b4-e24a-4f4a-91c1-3b49fc83584c)

r? `@xFrednet`

changelog: Fix display of configs in clippy doc page
2024-07-28 08:45:28 +00:00
Jason Newcomb
78a750e890 Sort the config list using dev fmt 2024-07-28 00:55:46 -04:00
Jason Newcomb
1d06ad5599 Mark the lints for each config via an attribute instead of a doc comment.. 2024-07-28 00:55:46 -04:00
Jason Newcomb
7422202ca5 Add missing default values 2024-07-27 23:34:16 -04:00
Jason Newcomb
7a25ead416 Remove unneeded parens in config macro 2024-07-27 19:23:23 -04:00
Jason Newcomb
84dc56923b Add docs for await_holding_invalid_types 2024-07-27 18:17:26 -04:00
Jason Newcomb
a54e3130ca alphabetize the config fields 2024-07-27 18:10:56 -04:00
bors
236c8c782b Auto merge of #13159 - Alexendoo:missing-trait-methods-stable-order, r=dswij
`missing_trait_methods`: lint methods in definition order

Lintcheck for #13157 showed a bunch of changes for `missing_trait_methods`

This is because `values_sorted` was sorting the entries by the key's [`DefPathHash`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.DefPathHash.html), this is stable for a given compiler but can change across versions

changelog: none
2024-07-27 15:32:18 +00:00
bors
d20be39c7f Auto merge of #13149 - jusexton:issue-13123, r=dswij
Fix while_let_on_iterator dropping loop label when applying fix.

Loop label was not persisted when displaying help and was therefore producing broken rust code when applying fixes.

Solution was to store the `ast::Label` when creating a `higher::WhileLet` from an expression and add the label name to the lint suggestion and diagnostics.

---

Fixes: https://github.com/rust-lang/rust-clippy/issues/13123

changelog: [`while_let_on_iterator`]: Fix issue dropping loop label when displaying help and applying fixes.
2024-07-27 15:23:21 +00:00
bors
92768eeac4 Auto merge of #13053 - nyurik:rename-set_contains_or_insert, r=llogiq
Add `BTreeSet` detection to the `set_contains_or_insert` lint

* Detect `BTreeSet::contains` + `BTreeSet::insert` usage in the same way as with the `HashSet`.
CC: `@lochetti` `@bitfield`

----

changelog: [`set_contains_or_insert`]: Handle `BTreeSet` in addition to `HashSet`
2024-07-27 11:48:24 +00:00
bors
1ec502569e Auto merge of #13168 - Alexendoo:std-instead-of-core-msrv, r=Manishearth
Make `std_instead_of_core` somewhat MSRV aware

For #13158, this catches some things e.g. `core::net` and the recently stable `core::error` but not things moved individually like `UnwindSafe`, as far as I can see the version for those isn't easily available

Beta nominating since ideally we'd get this change in the same version as `core::error` becomes stable

cc `@kpreid`

changelog: none
2024-07-27 02:55:15 +00:00
Yuri Astrakhan
9964b4e053 Add BTreeSet to set_contains_or_insert
* Detect `BTreeSet::contains` + `BTreeSet::insert` usage in the same way as with the `HashSet`.
2024-07-26 22:52:07 -04:00
bors
6713631b0f Auto merge of #13165 - riyueguang:master, r=Jarcho
chore: fix some comments

fix some comments

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: none
2024-07-26 17:37:20 +00:00
bors
479491ebce Auto merge of #13130 - nyurik:ref-lints, r=Centri3
Avoid ref when using format!

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).

Inlining format args prevents accidental `&` misuse.

See also https://github.com/rust-lang/rust/issues/112156

changelog: none
2024-07-26 17:21:30 +00:00
Alex Macleod
84e36e6ce5 Make std_instead_of_core somewhat MSRV aware 2024-07-26 16:08:03 +00:00
Guillaume Gomez
b5fa6e28d4 Fix display of configs in clippy doc page 2024-07-26 14:23:46 +02:00
bors
3504145753 Auto merge of #13164 - flip1995:ui-test-bump, r=Alexendoo
Bump ui_test version -> 0.25

r? `@Alexendoo`

cc `@GuillaumeGomez`

changelog: none
2024-07-26 11:30:01 +00:00
Alex Macleod
10fb062c48 missing_trait_methods: lint methods in definition order 2024-07-26 11:25:06 +00:00
riyueguang
8ca8ed9b07 chore: fix some comments
Signed-off-by: riyueguang <rustruby@outlook.com>
2024-07-26 17:51:22 +08:00
Philipp Krones
82b44345a5
Bump ui_test version -> 0.25 2024-07-26 11:40:27 +02:00
bors
345c94c98f Auto merge of #13144 - xFrednet:07797-restriction-and-then-what, r=y21
Make restriction lint's use `span_lint_and_then` (i -> p)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

brother PR of: https://github.com/rust-lang/rust-clippy/pull/13136

changelog: none
2024-07-26 07:44:21 +00:00
xFrednet
90c19635fd
Make restriction lint's use span_lint_and_then (n -> p) 2024-07-26 09:41:38 +02:00
bors
533c377950 Auto merge of #12473 - Kobzol:assigning-clones-deref, r=Alexendoo
Fix handling of `Deref` in `assigning_clones`

The `assigning_clones` lint had a special case for producing a bit nicer code for mutable references:
```rust
fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) {
    *mut_thing = Clone::clone(ref_thing);
}
//v
fn clone_function_lhs_mut_ref(mut_thing: &mut HasCloneFrom, ref_thing: &HasCloneFrom) {
    Clone::clone_from(mut_thing, ref_thing);
}
```
However, this could [break](https://github.com/rust-lang/rust-clippy/issues/12437) when combined with `Deref`.

This PR removes the special case, so that the generated code should work more generally. Later we can improve the detection of `Deref` and put the special case back in a way that does not break code.

Fixes: https://github.com/rust-lang/rust-clippy/issues/12437

r? `@blyxyas`

changelog: [`assigning_clones`]: change applicability to `Unspecified` and fix a problem with `Deref`.
2024-07-25 20:31:29 +00:00
Jakub Beránek
e9852cc7c9
Only apply dereference-removing special case for actual references 2024-07-25 22:20:59 +02:00
bors
062b66d45c Auto merge of #12892 - meithecatte:needless-borrows-mutrefs, r=xFrednet
needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in #12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, #12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus #12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes #12856

changelog: none
2024-07-25 18:48:27 +00:00
bors
c7cfe7f5e2 Auto merge of #13156 - y21:for_each_expr_visitor_refactor, r=xFrednet
Remove unnecessary `res` field in `for_each_expr` visitors

Small refactor in the `for_each_expr*` visitors. This should not change anything functionally.

Instead of storing the final value `Option<B>` in the visitor and setting it to `Some` when we get a `ControlFlow::Break(B)` from the closure, we can just directly return it from the visitor itself now that visitors support that.

cc #12829 and https://github.com/rust-lang/rust-clippy/pull/12830#discussion_r1627882827

changelog: none
2024-07-25 17:51:02 +00:00