Commit graph

8677 commits

Author SHA1 Message Date
Lzu Tao
aff0e6d6d3 add uitest for indexing in unnecessary const items 2024-06-08 16:50:25 +07:00
bors
0ea88b90d8 Auto merge of #12900 - Alexendoo:no-lazy-static, r=llogiq
Remove `lazy_static` mention

I planned to replace any mention with `LazyLock` but I think `thread_local` is more appropriate here - `const`s that aren't `Sync` wouldn't be able to go in a `lazy_static`/`static LazyLock` either

Also removed a test file that was mostly commented out so wasn't testing anything

changelog: none
2024-06-07 22:54:02 +00:00
bors
d553ebef57 Auto merge of #12851 - samueltardieu:issue12846, r=y21
Add required parentheses around method receiver

Fix #12846

changelog: [`needless_bool`]: Add missing parentheses around method receiver
2024-06-07 21:27:46 +00:00
J-ZhengLi
1781333ec7 [match_same_arms]: add a test case with lifetimes 2024-06-08 00:06:20 +08:00
Alex Macleod
65af5d7b22 Remove lazy_static mention 2024-06-07 12:51:37 +00:00
bors
f990ea155e Auto merge of #12844 - Alexendoo:to-string-in-format-args, r=dswij
Fix `to_string_in_format_args` with macro call receiver

Fixes part of #12837

changelog: none
2024-06-07 09:52:17 +00:00
bors
0f87a81882 Auto merge of #12822 - Alexendoo:for-each-expr, r=dswij
Make `for_each_expr` visit closures by default, rename the old version `for_each_expr_without_closures`

A lot of the time `for_each_expr` is picked when closures should be visited so I think it makes sense for this to be the default with the alternative available for when you don't need to visit them.

The first commit renames `for_each_expr` to `for_each_expr_without_closures` and `for_each_expr_with_closures` to `for_each_expr`

The second commit switches a few uses that I caught over to include closures to fix a few bugs

changelog: none
2024-06-07 09:42:37 +00:00
bors
0b441d5ac5 Auto merge of #12877 - y21:const_host_ice, r=dswij
Handle const effects inherited from parent correctly in `type_certainty`

This fixes a (debug) ICE in `type_certainty` that happened in the [k256 crate]. (I'm sure you can also specifically construct an edge test case that will run into type_certainty false positives visible outside of debug builds from this bug)

<details>
<summary>Minimal ICE repro</summary>

```rs
use std::ops::Add;
Add::add(1_i32, 1).add(i32::MIN);
```
</details>

The subtraction here overflowed:
436675b477/clippy_utils/src/ty/type_certainty/mod.rs (L209)

... when we have something like `Add::add` where `add` fn has 0 generic params but the `host_effect_index` is `Some(2)` (inherited from the parent generics, the const trait `Add`), and we end up executing `0 - 1`.

(Even if the own generics weren't empty and we didn't overflow, this would still be wrong because it would assume that a trait method with 1 generic parameter didn't have any generics).

So, *only* exclude the "host" generic parameter if it's actually bound by the own generics

changelog: none

[k256 crate]: https://github.com/RustCrypto/elliptic-curves/tree/master/k256
2024-06-07 09:33:48 +00:00
Renato Lochetti
478d44487e
Allow manual_unwrap_or_default at useless_conversion_try tests 2024-06-06 21:44:06 +01:00
Renato Lochetti
5b63ab1131
Lint manual_unwrap_or_default for Result as well 2024-06-06 21:33:37 +01:00
Samuel Tardieu
35b2aa99f3 Add required parentheses around method receiver 2024-06-06 20:53:08 +02:00
bors
4e7f97467a Auto merge of #12827 - Alexendoo:lint-groups-priority, r=Jarcho
`lint_groups_priority`: ignore lints & groups at the same level

Fixes #12270

changelog: none
2024-06-06 12:09:58 +00:00
bors
6cfd4ac955 Auto merge of #10632 - Alexendoo:needless-maybe-sized, r=Jarcho
Add `needless_maybe_sized` lint

changelog: new lint: [`needless_maybe_sized`]

Closes #10600
2024-06-05 20:11:03 +00:00
bors
d955d0a41f Auto merge of #12891 - paultag:paultag/fix-lint-description, r=Manishearth
Fix grammer for the Safety documentation check

The original message ("unsafe function's docs miss `# Safety` section") reads quite awkwardly. I've changed it to "unsafe function's docs are missing a `# Safety` section" to have it read better.

```
changelog: [`missing_headers`]: Tweak the grammar in the lint message
```
2024-06-05 20:00:59 +00:00
bors
1105e9debe Auto merge of #12700 - Luv-Ray:overly_complex_bool_expr, r=Jarcho
[`overly_complex_bool_expr`]: Fix trigger wrongly on never type

fixes #12689

---

changelog: fix [`overly_complex_bool_expr`] triggers wrongly on never type
2024-06-05 19:47:43 +00:00
bors
bc00d7b94d Auto merge of #12845 - cookie-s:dedup-boolmethods-diags, r=Jarcho
Dedup nonminimal_bool_methods diags

Relates to #12379

Fix `nonminimal_bool` lint so that it doesn't check the same span multiple times.

`NotSimplificationVisitor` was called for each expression from `NonminimalBoolVisitor` whereas `NotSimplificationVisitor` also recursively checked all expressions.

---

changelog: [`nonminimal_bool`]: Fix duplicate diagnostics
2024-06-05 19:09:55 +00:00
Paul R. Tagliamonte
35e2027a35 Fix grammer for the Safety documentation check
The original message ("unsafe function's docs miss `# Safety` section")
reads quite awkwardly. I've changed it to "unsafe function's docs are missing
a `# Safety` section" to have it read better.

Signed-off-by: Paul R. Tagliamonte <paultag@gmail.com>
2024-06-05 14:11:56 -04:00
bors
10d1f32685 Auto merge of #12886 - GuillaumeGomez:fix-needless_character_iteration, r=blyxyas
Fix false positive for `needless_character_iteration` lint

Fixes #12879.

changelog: Fix false positive for `needless_character_iteration` lint
2024-06-05 13:12:39 +00:00
Guillaume Gomez
158b65889c Fix false positive for needless_character_iteration lint 2024-06-04 21:12:08 +02:00
y21
708ef7955d only run flop lints on inherent method calls 2024-06-03 21:42:00 +02:00
bors
4f3180adac Auto merge of #12875 - y21:deprecate_cfg_lints, r=flip1995
Deprecate `maybe_misused_cfg` and `mismatched_target_os`

All cases that these two lints would catch are now caught by cargo/rustc's own check-cfg feature.

This was previously discussed on zulip: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Deprecate.20maybe_misused_cfg.20and.20mismatched_target_os

For the most part, this PR was automated with `cargo dev deprecate`

r? `@flip1995` cc `@Urgau`

changelog: deprecate [`maybe_misused_cfg`] and [`mismatched_target_os`]
2024-06-03 08:57:34 +00:00
bors
61d3e14718 Auto merge of #12815 - GuillaumeGomez:add-needless_character_iteration, r=xFrednet
Add `needless_character_iteration` lint

Fixes #4817.

r? `@xFrednet`

changelog: Add `needless_character_iteration` lint
2024-06-03 08:09:18 +00:00
bors
568f4fc732 Auto merge of #12871 - Jacherr:issue-12768, r=blyxyas
Modify str_to_string to be machine-applicable

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

I'm not sure if there is any potential for edge cases with this - since it only ever acts on `&str` types I can't think of any, and especially since the methods do the same thing anyway.

changelog: allow `str_to_string` lint to be automatically applied
2024-06-02 21:11:06 +00:00
y21
25d40c9f6b handle parent const effects correctly in type_certainty 2024-06-01 20:10:48 +02:00
y21
f950961c42 deprecate mismatched_target_os 2024-06-01 14:11:07 +02:00
y21
4aa20d2e95 deprecate maybe_misused_cfg 2024-06-01 13:44:13 +02:00
bors
436675b477 Auto merge of #12868 - VitalikButerinEth:master, r=llogiq
chore: fix some comments

 fix some comments

----

changelog: none
2024-06-01 11:16:14 +00:00
Jacher
5d0fcfbf56 modify str_to_string to be machine-applicable 2024-06-01 09:05:27 +00:00
bors
28e887fe71 Auto merge of #12488 - Jacherr:issue-11525, r=llogiq
Disable `indexing_slicing` for custom Index impls

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

Disables `indexing_slicing` for custom Index impls, specifically any implementations that also do not have a `get` method anywhere along the deref chain (so, for example, it still lints on Vec, which has its `get` method as part of the deref chain).

Thanks `@y21` for pointing me in the right direction with a couple of handy util functions for deref chain and inherent methods, saved a headache there!

changelog: FP: Disable `indexing_slicing` for custom Index impls
2024-05-31 16:42:50 +00:00
bors
0b598b636b Auto merge of #12865 - J-ZhengLi:issue12853, r=y21
fix [`redundant_closure`] suggesting incorrect code with `F: Fn()`

fixes: #12853

---

changelog: fix [`redundant_closure`] suggesting incorrect code with `F: Fn()`
2024-05-31 15:23:39 +00:00
bors
e7efe4381a Auto merge of #12857 - WeiTheShinobi:non_canonical_impls, r=y21
fix: let non_canonical_impls skip proc marco

Fixed #12788

Although the issue only mentions `NON_CANONICAL_CLONE_IMPL`, this fix will also affect `NON_CANONICAL_PARTIAL_ORD_IMPL` because I saw
> Because of these unforeseeable or unstable behaviors, macro expansion should often not be regarded as a part of the stable API.

on Clippy Documentation and these two lints are similar, so I think it might be good, not sure if it's right or not.

---

changelog: `NON_CANONICAL_CLONE_IMPL`, `NON_CANONICAL_PARTIAL_ORD_IMPL` will skip proc marco now
2024-05-30 15:58:48 +00:00
WeiTheShinobi
1038927b47 fix: add test case, use a better conditional expression. 2024-05-30 23:40:17 +08:00
VitalikButerinEth
b92501f124 chore: fix some comments
Signed-off-by: VitalikButerinEth <csyingyu@126.com>
2024-05-30 22:53:43 +08:00
Jacher
1c117f12ea ignore generics in handling 2024-05-30 13:15:25 +00:00
Jacherr
ae59f5002d add additional testcases 2024-05-30 11:45:57 +00:00
Jacherr
e186ed2ad1 check return type of get and indexing 2024-05-30 11:45:57 +00:00
Jacherr
93b39d8910 disable indexing_slicing for custom Index impls 2024-05-30 11:45:43 +00:00
bors
03654badfd Auto merge of #12864 - tesuji:non-no-effect, r=y21
ignore array from `deref_addrof` lint

Split from https://github.com/rust-lang/rust-clippy/pull/12854

changelog: ignore array from `deref_addrof` lint

r? y21
2024-05-30 10:16:50 +00:00
Philipp Krones
89037ea18f
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-30 09:44:14 +02:00
Lzu Tao
8bd2a17dfe ignore array from deref_addrof lint
Note that semantics of repeat expr in array are the same
2024-05-30 08:34:44 +07:00
J-ZhengLi
db30f6ce9f fix [redundant_closure] suggesting incorrect code with F: Fn() 2024-05-29 16:21:59 +08:00
Lzu Tao
4dcab72c1c add test for *&[a, b,...]` 2024-05-29 02:20:49 +00:00
Oli Scherer
e3e27ba3dd Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
bors
da4b2127c0 Auto merge of #12859 - cookie-s:dedup-single-char-name-diag, r=Alexendoo
[`many_single_char_names`]: Deduplicate diagnostics

Relates to #12379

Fix `many_single_char_names` lint so that it doesn't emit diagnostics when the current level of the scope doesn't contain any single character name.

```rust
let (a, b, c, d): (i32, i32, i32, i32);
match 1 {
  1 => (),
  e => {},
}
```
produced the exact same MANY_SINGLE_CHAR_NAMES diagnostic at each of the Arm `e => {}` and the Block `{}`.

---

changelog: [`many_single_char_names`]: Fix duplicate diagnostics
2024-05-28 12:41:14 +00:00
bors
76eee82e79 Auto merge of #12823 - schvv31n:fix-iter-on-empty-collections, r=y21
Suppress `iter_on_empty_collections` if the iterator's concrete type is relied upon

changelog: fixed #12807
2024-05-27 16:18:41 +00:00
bors
7e4c1ae0b6 Auto merge of #12843 - mdm:fix-unnecessary-to-owned-println-interaction, r=y21
Fix `unnecessary_to_owned` interaction with macro expansion

fixes #12821

In the case of an unnecessary `.iter().cloned()`, the lint `unnecessary_to_owned` might suggest to remove the `&` from references without checking if such references are inside a macro expansion. This can lead to unexpected behavior or even broken code if the lint suggestion is applied blindly. See issue #12821 for an example.

This PR checks if such references are inside macro expansions and skips this part of the lint suggestion in these cases.

changelog: [`unnecessary_to_owned`]: Don't suggest to remove `&` inside macro expansion
2024-05-27 14:26:50 +00:00
Guillaume Gomez
566dfd9008 Add needless_character_iteration lint 2024-05-27 14:16:02 +02:00
Marc Dominik Migge
4a64180dd5 unnecessary_to_owned should not suggest to remove & in macro expansion 2024-05-27 12:05:18 +02:00
bors
4dd07f4e4e Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote
[perf] Delay the construction of early lint diag structs

Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666.

See individual commits for details. The first three commits are not strictly necessary.
However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement.
It's also pretty sweet on its own if I may say so myself.
2024-05-27 08:44:12 +00:00
bors
722de3b546 Auto merge of #12842 - J-ZhengLi:issue12801, r=y21
add parentheses to [`let_and_return`]'s suggestion

closes: #12801

---

changelog: suggest adding parentheses when linting [`let_and_return`] and [`needless_return`]
2024-05-27 08:04:36 +00:00