Commit graph

8870 commits

Author SHA1 Message Date
bors
51c5eee9e6 Auto merge of #12945 - Jarcho:octal_escape, r=Alexendoo
Rework `octal_escapes`

Main changes are not doing UTF-8 decoding, noting each occurrence as an individual lint emission, and narrowing the span to point to the escape itself.

changelog: none
2024-06-17 20:12:43 +00:00
bors
0625183e28 Auto merge of #12903 - Jarcho:issue_12284, r=y21
Fix ICE in `upper_case_acronyms`

fixes #12284

The logic has been rewritten to avoid allocations. The old version allocated multiple vecs and strings for each identifier. The new logic allocates a single string only when the lint triggers.

This also no longer lints on strings which don't start with an uppercase letter (e.g. `something_FOO`).

changelog: none
2024-06-17 15:45:38 +00:00
Jason Newcomb
4b16e265a7 Rework octal_escapes. 2024-06-16 22:36:24 -04:00
Jason Newcomb
22710f33a8 Add lint manual_inspect 2024-06-16 18:33:43 -04:00
kyle oneill
3405ce3bca Add field_scoped_visibility_modifiers lint 2024-06-16 15:54:48 -04:00
AurelienFT
51c6630d4f Change MSRV check for manual_pattern_char_comparison only for pattern arrays 2024-06-15 21:52:42 +02:00
AurelienFT
63388cbab8 add MSRV for manual_pattern_char_comparison 2024-06-15 21:45:35 +02:00
bors
0dc265ff82 Auto merge of #12756 - y21:assigning_clones_lifetimes, r=Alexendoo
Avoid emitting `assigning_clones` when cloned data borrows from the place to clone into

Fixes #12444
Fixes #12460
Fixes #12749
Fixes #12757
Fixes #12929

I think the documentation for the function should describe what- and how this is fixing the issues well.
It avoids emitting a warning when the data being cloned borrows from the place to clone into, which is information that we can get from `PossibleBorrowerMap`. Unfortunately, it is a tiny bit tedious to match on the MIR like that and I'm not sure if this is possibly relying a bit too much on the exact MIR lowering for assignments.

Things left to do:
- [x] Handle place projections (or verify that they work as expected)
- [x] Handle non-`Drop` types

changelog: [`assigning_clones`]: avoid warning when the suggestion would lead to a borrow-check error
2024-06-15 18:25:42 +00:00
DaniPopes
82f0dc95a0
[missing_const_for_fn]: add machine-applicable suggestion 2024-06-14 14:43:08 +02:00
Esteban Küber
fa9274c99b Tweak output of import suggestions
When both `std::` and `core::` items are available, only suggest the
`std::` ones. We ensure that in `no_std` crates we suggest `core::`
items.

Ensure that the list of items suggested to be imported are always in the
order of local crate items, `std`/`core` items and finally foreign crate
items.

Tweak wording of import suggestion: if there are multiple items but they
are all of the same kind, we use the kind name and not the generic "items".

Fix #83564.
2024-06-13 20:22:21 +00:00
bors
ba347f9815 Auto merge of #126398 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Updates `Cargo.lock` with Clippy version bump.
2024-06-13 16:17:56 +00:00
Philipp Krones
3bff119f63 Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
Waffle Lapkin
c3d463333f Fixup clippy tests
Don't depend on the fact that `!` falls back to `()` and so panic-ish things
can be used in `-> impl ImplementedForUnit` functions
2024-06-13 12:24:31 +02:00
Philipp Krones
cc63143bbf
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-13 12:24:08 +02:00
bors
aaade2d12d Auto merge of #12855 - tesuji:fix-author-lint, r=Jarcho
Fix typos of author lint

changelog: none
2024-06-11 22:49:18 +00:00
bors
38d12a9bc0 Auto merge of #12681 - y21:issue12677, r=Jarcho
Let `qualify_min_const_fn` deal with drop terminators

Fixes #12677

The `method_accepts_droppable` check that was there seemed overly conservative.
> Returns true if any of the method parameters is a type that implements `Drop`.
> The method can't be made const then, because `drop` can't be const-evaluated.

Accepting parameters that implement `Drop` should still be fine as long as the parameter isn't actually dropped, as is the case in the linked issue where the droppable is moved into the return place. This more accurate analysis ("is there a `drop` terminator") is already done by `qualify_min_const_fn` [here](f5e250180c/clippy_utils/src/qualify_min_const_fn.rs (L298)), so I don't think this additional check is really necessary?

Fixing the other, second case in the linked issue was only slightly more involved, since `Vec::new()` is a function call that has the ability to panic, so there must be a `drop()` terminator for cleanup, however we should be able to freely ignore that. [Const checking ignores cleanup blocks](https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382-L388), so we should, too?

r? `@Jarcho`

----

changelog: [`missing_const_for_fn`]: continue linting on fns with parameters implementing `Drop` if they're not actually dropped
2024-06-11 22:38:52 +00:00
AurelienFT
c86b19f1ef Add lint to check manual pattern char comparison and merge its code with single_char_pattern lint 2024-06-11 21:56:14 +02:00
bors
9ddea51a73 Auto merge of #12912 - lochetti:fix_12824, r=dswij
Don't lint indexing_slicing lints on proc macros

This pr fixes https://github.com/rust-lang/rust-clippy/issues/12824

Even though the issue mentions the indexing case only, it was easy to apply the fix to the slicing case as well.

changelog: [`out_of_bounds_indexing`, `indexing_slicing`]: Don't lint on procedural macros.
2024-06-11 15:27:36 +00:00
bors
87c895ad83 Auto merge of #12915 - belyakov-am:lint/single_char_add_str, r=xFrednet
Handle single chars with `to_string()` for `single_char_add_str`

Add support for single chars / literals with `to_string()` call for `push_str()` and `insert_str()`.

changelog: [`single_char_add_str`]: handle single chars with `to_string()` call

Closes #12775
2024-06-11 11:08:45 +00:00
Renato Lochetti
f7515ae905
Don't lint indexing_slicing lints on proc macros 2024-06-10 09:08:56 +01:00
Artem Belyakov
55344c84a5 Handle single chars with to_string() for single_char_add_str 2024-06-09 21:01:00 +03:00
clubby789
5acc25e700 Update icu4x dependencies 2024-06-09 07:47:42 +01:00
Renato Lochetti
70ca9a1e7e
Lint manual_unwrap_or for it let cases 2024-06-08 14:39:03 +01:00
Lzu Tao
2855a876a7 fix typos of author lint 2024-06-08 12:31:49 +00:00
Lzu Tao
a0234b4e8b Ignore non ExprKind::{Path,Lit) inside const context
- remove now dead code in ASSERTIONS_ON_CONSTANTS
  cc #11966
- Partially revert "ignore `assertions-on-constants` in const contexts"
  This reverts commit c7074de420a2192fb40d3f2194a20dd0d1b65cc6.
2024-06-08 18:44:40 +07:00
Lzu Tao
ac600282a0 ignore assertions-on-constants in const contexts 2024-06-08 16:50:25 +07:00
Lzu Tao
e18b27aa2a add uitest for issue 12816 2024-06-08 16:50:25 +07:00
Lzu Tao
2c61b45576 do not lint on indexing inside const contexts 2024-06-08 16:50:25 +07:00
Lzu Tao
aff0e6d6d3 add uitest for indexing in unnecessary const items 2024-06-08 16:50:25 +07:00
bors
48686adf48 Auto merge of #12805 - Alexendoo:blocks-in-conditions-closures, r=dswij
Don't lint blocks in closures for blocks_in_conditions

Seemed like an outlier for the lint which generally caught only the syntactically confusing cases, it lints blocks in closures but excludes closures passed to iterator methods, this changes it to ignore closures in general

changelog: none
2024-06-08 09:45:22 +00:00
Jason Newcomb
059eaf1386 Fix ICE in upper_case_acronyms and remove most of the string allocations. 2024-06-08 00:00:32 -04:00
León Orell Valerian Liehr
fe6f332193 Rollup merge of #125951 - slanterns:error_in_core_stabilization, r=Amanieu
Stabilize `error_in_core`

Closes: https://github.com/rust-lang/rust/issues/103765.

`@rustbot` label: +T-libs-api

r? libs-api
2024-06-08 04:25:44 +02: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
y21
973f318514 qualify_min_const_fn: ignore cleanup bbs 2024-06-07 20:56:22 +02:00
y21
6fdf295664 let qualify_min_const_fn deal with drop checks 2024-06-07 20:56:22 +02: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
Alex Macleod
b21ee38fa9 Don't lint blocks in closures for blocks_in_conditions 2024-06-07 11:21:38 +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
bors
127f3e18c1 Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errors
Revert: create const block bodies in typeck via query feeding

as per the discussion in https://github.com/rust-lang/rust/pull/125806#discussion_r1622563948

It was a mistake to try to shoehorn const blocks and some specific anon consts into the same box and feed them during typeck. It turned out not simplifying anything (my hope was that we could feed `type_of` to start avoiding the huge HIR matcher, but that didn't work out), but instead making a few things more fragile.

reverts the const-block-specific parts of https://github.com/rust-lang/rust/pull/124650

`@bors` rollup=never had a small perf impact previously

fixes https://github.com/rust-lang/rust/issues/125846

r? `@compiler-errors`
2024-06-07 09:08:59 +00:00
Oli Scherer
abd011638d Revert "Create const block DefIds in typeck instead of ast lowering"
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-07 08:33:58 +00:00
Slanterns
246d4fe791 bless std_instead_of_core 2024-06-07 08:37:05 +08:00
Renato Lochetti
478d44487e
Allow manual_unwrap_or_default at useless_conversion_try tests 2024-06-06 21:44:06 +01:00
Rémy Rakic
5ea5f6351e Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco"
This reverts commit 57dad1d75e562ff73051c1c43b07eaf65c7dbd74, reversing
changes made to 36316df9fe6c3e246153fe6e78967643cf08c148.
2024-06-06 20:39:54 +00: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
Maja Kądziołka
c6cc160ec6
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
2024-06-06 17:04:12 +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
f67f72695a Merge commit 'c9139bd546d9cd69df817faeab62c5f9b1a51337' into clippy-subtree-update 2024-05-30 10:49:05 +02: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
Vadim Petrochenkov
d38920f677 ast: Revert a breaking attribute visiting order change 2024-05-29 21:55:24 +03: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
J-ZhengLi
03306b6ab6 suggest adding parentheses when linting [let_and_return] and [needless_return] 2024-05-27 11:49:10 +08:00
cookie-s
7110f471d3
[many_single_char_names]: Deduplicate diagnostics 2024-05-26 22:56:23 -04:00
WeiTheShinobi
c53cea90ad fix: let non_canonical_impls skip proc marco 2024-05-26 18:59:40 +08:00
bors
5aae5f6ae6 Auto merge of #12740 - lrh2000:sig-drop, r=blyxyas
`significant_drop_in_scrutinee`: Trigger lint only if lifetime allows early significant drop

I want to argue that the following code snippet should not trigger `significant_drop_in_scrutinee` (https://github.com/rust-lang/rust-clippy/issues/8987). The iterator holds a reference to the locked data, so it is expected that the mutex guard must be alive until the entire loop is finished.
```rust
use std::sync::Mutex;

fn main() {
    let mutex_vec = Mutex::new(vec![1, 2, 3]);
    for number in mutex_vec.lock().unwrap().iter() {
        dbg!(number);
    }
}
```

However, the lint should be triggered when we clone the vector. In this case, the iterator does not hold any reference to the locked data.
```diff
-     for number in mutex_vec.lock().unwrap().iter() {
+     for number in mutex_vec.lock().unwrap().clone().iter() {
```

Unfortunately, it seems that regions on the types of local variables are mostly erased (`ReErased`) in the late lint pass. So it is hard to tell if the final expression has a lifetime relevant to the value with a significant drop.

In this PR, I try to make a best-effort guess based on the function signatures. To avoid false positives, no lint is issued if the result is uncertain. I'm not sure if this is acceptable or not, so any comments are welcome.

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

changelog: [`significant_drop_in_scrutinee`]: Trigger lint only if lifetime allows early significant drop.

r? `@flip1995`
2024-05-25 13:11:21 +00:00
bors
5d10538fb4 Auto merge of #12809 - GuillaumeGomez:missing-backticks-fix, r=y21
Correctly handle closing parens in `missing_backticks` doc lint

Fixes #12795.

changelog: Correctly handle closing parens in `doc_markdown` lint
2024-05-25 12:03:07 +00:00
cookie-s
93a77f2812
[nonminimal_bool]: Deduplicate diagnostics 2024-05-24 20:27:12 -04:00
Hamir Mahal
17cc0a3a7d
feat: auto-fix for bare URLs in doc comments 2024-05-24 14:30:42 -07:00
Alex Macleod
95b295d976 Fix to_string_in_format_args with macro call receiver 2024-05-24 19:27:39 +00:00
Jakob Schwarz
7f30b20b28
fulfill expectations in check_partial_eq_without_eq
changelog: fulfill expectations in [derive_partial_eq_without_eq]
2024-05-24 08:44:41 +02:00
León Orell Valerian Liehr
0c653d9f91 Remove LintDiagnostic::msg
* instead simply set the primary message inside the lint decorator functions
* it used to be this way before [#]101986 which introduced `msg` to prevent
  good path delayed bugs (which no longer exist) from firing under certain
  circumstances when lints were suppressed / silenced
* this is no longer necessary for various reasons I presume
* it shaves off complexity and makes further changes easier to implement
2024-05-23 04:08:35 +02:00
Ruihan Li
6641f9f6e1 Track lifetime on values with significant drop 2024-05-23 00:37:02 +08:00
bors
05c4053628 Auto merge of #12398 - WeiTheShinobi:bug-lint-numbered_fields, r=Manishearth
bug fix: lint numbered_fields message error

fixes #12367

changelog: [`numbered_fields`]: fix macro expand message error.
2024-05-22 15:50:46 +00:00
WeiTheShinobi
038f6179d7 bug fix: lint numbered_fields message error 2024-05-22 15:26:32 +08:00
schvv31n
7439ecb07c Added check for type unification with the iter 2024-05-21 22:21:33 +01:00
bors
ea535c97d5 Auto merge of #12804 - B14CK313:master, r=y21
fulfill expectations in `check_unsafe_derive_deserialize`

The utility function `clippy_utils::fulfill_or_allowed` is not used because using it would require to move the check for allowed after the check iterating over all inherent impls of the type, doing possibly unnecessary work.
Instead, `is_lint_allowed` is called as before, but additionally, once certain that the lint should be emitted, `span_lint_hir_and_then` is called instead of `span_lint_and_help` to also fulfill expectations.

Note: as this is my first contribution, please feel free to nitpick or request changes. I am happy to adjust the implementation.

fixes: #12802

changelog: fulfill expectations in [`unsafe_derive_deserialize`]
2024-05-21 19:05:36 +00:00
Philipp Krones
4363278c73 Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into clippy-subtree-update 2024-05-21 10:39:30 -07:00
Guillaume Gomez
4f98cc6d55 Correctly handle closing parens in missing_backticks doc lint 2024-05-21 14:55:30 +02:00
bors
2efebd2f0c Auto merge of #12765 - yusufraji:while-float, r=llogiq
Add new lint `while_float`

This PR adds a nursery lint that checks for while loops comparing floating point values.

changelog:
```
changelog: [`while_float`]: Checks for while loops comparing floating point values.
```

Fixes #758
2024-05-21 11:36:31 +00:00
Michael Goulet
ca1337a7bc Remove a clippy test that doesn't apply anymore 2024-05-20 19:21:38 -04:00
schvv31n
b31625cdc7 Accounted for possible extra layers before the consuming parent expr 2024-05-20 21:27:30 +01:00
Alex Macleod
9e5523e8c4 lint_groups_priority: ignore lints & groups at the same level 2024-05-20 19:44:55 +00:00
schvv31n
9d311b5c2b initial fix 2024-05-19 21:41:13 +01:00
Alex Macleod
68e7356b7e Switch to for_each_expr in some lints 2024-05-19 16:47:02 +00:00
Michael Howell
b5cf8b8277 doc_lazy_continuation: do not warn on End events
This avoids event spans that would otherwise cause crashes, since an
End's span covers the range of the tag (which will be earlier than the
line break within the tag).
2024-05-18 16:19:41 -07:00
blyxyas
ae547e3000 Fix typos (taking into account review comments) 2024-05-18 18:12:18 +02:00
bors
680256f3ce Auto merge of #12813 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: None
2024-05-16 21:28:33 +00:00
Philipp Krones
c200dad300
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-16 14:20:56 -07:00
bors
5459429f92 Auto merge of #12803 - wutchzone:panic-in-tests, r=y21
Add configuration option for ignoring `panic!()` in tests

```
changelog: [`panic`]: Now can be disabled in tests with the `allow-panic-in-tests` option
```

I often find myself using `panic!(…)` in tests a lot, where I often do something like:

```rust
match enam {
  Enam::A => …,
  Enam::B => …,
  _ => panic!("This should not happen at all."),
}
```
I think this patch should go nicely with already existing `allow-unwrap-in-tests` and `allow-expect-in-tests`.
2024-05-16 21:13:34 +00:00
Jakob Schwarz
1b6c91628e
add test for #[expect]ing unsafe_derive_deserialize
Adding `#![feature(lint_reasons)]` to the top of the file
also changed the line numbers in the expected error output.
2024-05-16 19:54:43 +02:00
Daniel Sedlak
c342a61564 Add configuration option for ignoring panic!() in tests 2024-05-16 05:45:56 +00:00
bors
caad063933 Auto merge of #12713 - J-ZhengLi:issue8864, r=y21
make sure the msrv for `const_raw_ptr_deref` is met when linting [`missing_const_for_fn`]

fixes: #8864

---

changelog: make sure the msrv for `const_ptr_deref` is met when linting [`missing_const_for_fn`]
2024-05-15 21:29:34 +00:00
bors
e669d97494 Auto merge of #12706 - pacak:less-aggressive-needless-borrows, r=dswij
less aggressive needless_borrows_for_generic_args

Current implementation looks for significant drops, that can change the behavior, but that's not enough - value might not have a `Drop` itself but one of its children might have it.

A good example is passing a reference to `PathBuf` to `std::fs::File::open`. There's no benefits to pass `PathBuf` by value, but since `clippy` can't see `Drop` on `Vec` several layers down it complains forcing pass by value and making it impossible to use the same name later.

New implementation only looks at copy values or values created in place     so existing variable will never be moved but things that take a string reference created and value is created inplace `&"".to_owned()` will make it to suggest to use `"".to_owned()` still.

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

changelog: [`needless_borrows_for_generic_args`]: avoid moving variables
2024-05-15 15:51:27 +00:00
bors
a9b5c8ca81 Auto merge of #12790 - c410-f3r:blah, r=dswij
Fix #12760

Fix #12760

```
changelog: [missing_panics_doc]: Ignore panics in compile time
```
2024-05-15 15:40:36 +00:00
J-ZhengLi
1b7fc5f5aa add some msrv checks in is_min_const_fn 2024-05-15 16:38:57 +08:00
Alex Macleod
9d790d6407 Don't lint path statements in no_effect 2024-05-14 17:22:56 +00:00
bors
a86378086b Auto merge of #12794 - J-ZhengLi:issue9251, r=blyxyas
improve [`match_same_arms`] messages, enable rustfix test

closes: #9251

don't worry about the commit size, most of them are generated

---

changelog: improve [`match_same_arms`] lint messages
2024-05-14 08:42:23 +00:00
J-ZhengLi
dc5b99b3b6 improve [match_same_arms] messages, enable rustfix test 2024-05-14 00:10:45 +02:00
bors
d6991abc5a Auto merge of #12764 - lrh2000:ignore-place, r=blyxyas
`significant_drop_in_scrutinee`: Fix false positives due to false drops of place expressions

Place expressions do not really create temporaries, so they will not create significant drops. For example, the following code snippet is quite good (#8963):
```rust
fn main() {
    let x = std::sync::Mutex::new(vec![1, 2, 3]);
    let x_guard = x.lock().unwrap();
    match x_guard[0] {
        1 => println!("1!"),
        x => println!("{x}"),
    }
    drop(x_guard); // Some "usage"
}
```

Also, the previous logic thinks that references like `&MutexGuard<_>`/`Ref<'_, MutexGuard<'_, _>>` have significant drops, which is simply not true, so it is fixed together in this PR.

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

changelog: [`significant_drop_in_scrutinee`]: Fix false positives due to false drops of place expressions.

r? `@blyxyas`
2024-05-13 13:19:48 +00:00
Caio
12ec009f5a Fix #12760 2024-05-12 21:59:45 -03:00
y21
9747c80644 new lint: macro_metavars_in_unsafe 2024-05-12 17:03:30 +02:00
bors
7cfb9a0d6f Auto merge of #11540 - J-ZhengLi:issue11443, r=xFrednet
add new lint that disallow renaming parameters in trait functions

fixes: #11443
fixes: #486

changelog: add new lint [`renamed_function_params`]

Note that the lint name is not final, because I have a bad reputation in naming things, and I don't trust myself.
2024-05-12 14:21:22 +00:00
J-ZhengLi
46659acdbd add configuration to allow skipping on some certain traits & collect metadata 2024-05-12 22:13:17 +08:00
bors
9b446c7ff8 Auto merge of #12787 - J-ZhengLi:issue127311, r=blyxyas
make [`from_str_radix_10`] skip constant context

fixes: #12731

---

changelog: make [`from_str_radix_10`] skip constant context
2024-05-12 14:03:55 +00:00
bors
2b34abc887 Auto merge of #12730 - Alexendoo:lint-groups-workspace-priority, r=xFrednet
Lint direct priority conflicts in `[workspace.lints]`

Partially addresses #12729

This still doesn't do any workspace resolution stuff, so it will not catch any virtual workspaces or conflicts from inherited definitions. But while we're parsing the `Cargo.toml` we might as well check the workspace definitions if we find them

changelog: none
2024-05-12 13:45:47 +00:00
bors
412b69158b Auto merge of #12620 - Nilstrieb:dupattr, r=xFrednet
Handle `rustc_on_unimplemented` in duplicated_attributes

```rust
#[rustc_on_unimplemented(
    on(
        _Self = "&str",
        label = "`a"
    ),
    on(
        _Self = "alloc::string::String",
        label = "a"
    ),
)]
```

The lint treats this as a repetition because `rustc_on_unimplemented:🔛:label` appears twice, but that's ok.

Fixes #12619

changelog: [`duplicated_attributes`]: fix handling of `rustc_on_unimplemented`
2024-05-12 13:35:02 +00:00
bors
0e5bded17e Auto merge of #12770 - notriddle:notriddle/doc-lazy-continuation, r=llogiq
Add new lint `doc_lazy_continuation`

changelog: [`doc_lazy_continuation`]: add lint that warns on so-called "lazy paragraph continuations"

This is a follow-up for https://github.com/rust-lang/rust/pull/121659, since most cases of unintended block quotes are lazy continuations. The lint is designed to be more generally useful than that, though, because it will also catch unintended list items and unintended block quotes that didn't coincidentally hit a pulldown-cmark bug.

The second commit is the result of running `cargo dev dogfood --fix`, and manually fixing anything that seems wrong. NOTE: this lint's suggestions should never change the parser's interpretation of the markdown, but in many cases, it seems that doc comments in clippy were written without regard for this feature of Markdown (which, I suppose, is why this lint should exist).
2024-05-11 10:55:25 +00:00
J-ZhengLi
904c99c163 make [from_str_radix_10] skip constant context 2024-05-11 15:37:31 +08:00
y21
60508f546a deal with non-Drop types and add a test case for projections 2024-05-10 00:37:59 +02:00
y21
20d1bb1867 [assigning_clones]: bail out when the source borrows from target 2024-05-10 00:37:59 +02:00
bors
baf2a23840 Auto merge of #12783 - shanretoo:fix-assigning-clones, r=blyxyas
fix: use hir_with_context to produce correct snippets for assigning_clones

The `assigning_clones` lint is producing wrong output when the assignment is a macro call.
Since Applicability level `Unspecified` will never be changed inside `hir_with_applicability`, so it is safe here to replace `hir_with_applicability` with `hir_with_context` to generate snippets of the macro call instead of the expansion.

fixes #12776

changelog: [`assigning_clones`]: use `hir_with_context` to produce correct snippets
2024-05-09 21:38:05 +00:00
bors
5a28d8f01e Auto merge of #12650 - cocodery:issue/12098, r=xFrednet
fix false positive in Issue/12098 because lack of consideration of mutable caller

fixes [Issue#12098](https://github.com/rust-lang/rust-clippy/issues/12098)

In issue#12098, the former code doesn't consider the caller for clone is mutable, and suggests to delete clone function.

In this change, we first get the inner caller requests for clone,
and if it's immutable, the following code will suggest deleting clone.

If it's mutable, the loop will check whether a borrow check violation exists,
if exists, the lint should not execute, and the function will directly return;
otherwise, the following code will handle this.

changelog: [`clippy::unnecessary_to_owned`]: fix false positive
2024-05-09 17:41:49 +00:00
shanretoo
99a42bab30 fix wrong suggestions of assigning_clones when the assignment is a macro call 2024-05-09 09:29:18 +08:00
Markus Reiter
d32629891a Use generic NonZero. 2024-05-08 21:37:55 +02:00
Markus Reiter
7ad336f3a8 Simplify clippy lint. 2024-05-08 21:37:54 +02:00
roife
362ef42b68 fix: merge multiple suggestions into a single multi-span suggestion in needless_late_init 2024-05-08 13:44:22 +08:00
cocodery
a8c35cbbda Check inner caller for clone and judge whether they are mutable
if immutbale -> lint delete redudant clone
if mutable   -> lint check whether clone is needed
2024-05-07 16:07:13 +08:00
J-ZhengLi
40ec760572 fix doc test failure;
apply review suggestions by @Centri3:
use multi suggestion;
change output message format;
add macro expansion check & tests;
2024-05-07 10:49:02 +08:00
J-ZhengLi
28d5115067 add new lint that disallow renaming parameters in trait functions 2024-05-07 10:49:02 +08:00
Michael Howell
f3dd31e214 Add lint for markdown lazy paragraph continuations
This is a follow-up for https://github.com/rust-lang/rust/pull/121659,
since most cases of unintended block quotes are lazy continuations.
The lint is designed to be more generally useful than that, though,
because it will also catch unintended list items and unintended
block quotes that didn't coincidentally hit a pulldown-cmark bug.
2024-05-06 16:31:21 -07:00
bors
befb659145 Auto merge of #12755 - 9999years:useless-attribute, r=xFrednet,GuillaumeGomez
Allow more attributes in `clippy::useless_attribute`

Fixes #12753
Fixes #4467
Fixes #11595
Fixes #10878

changelog: [`useless_attribute`]: Attributes allowed on `use` items now include `ambiguous_glob_exports`, `hidden_glob_reexports`, `dead_code`, `unused_braces`, and `clippy::disallowed_types`.
2024-05-06 20:38:51 +00:00
Yusuf Raji
c9ea0ae502 Lint while loops with float comparison 2024-05-06 00:04:00 +02:00
Ruihan Li
509ca90bf1 Ignore significant drops of place expressions 2024-05-06 00:30:41 +08:00
Michael Baikov
79a14dea86 less aggressive needless_borrows_for_generic_args
Current implementation looks for significant drops, that can change the
behavior, but that's not enough - value might not have a Drop itself but
one of its children might have it.

A good example is passing a reference to `PathBuf` to `std::fs::File::open`.
There's no benefits to pass `PathBuf` by value, but since clippy can't
see `Drop` on `Vec` several layers down it complains forcing pass by
value and making it impossible to use the same name later.

New implementation only looks at copy values or values created inplace
so existing variable will never be moved but things that take a string
reference created and value is created inplace `&"".to_owned()` will
make it to suggest to use `"".to_owned()` still.

Fixes https://github.com/rust-lang/rust-clippy/issues/12454
2024-05-05 12:08:38 -04:00
bors
28002514d5 Auto merge of #12742 - Alexendoo:assigning-clones-nested-late-init, r=dswij
Don't lint assigning_clones on nested late init locals

Fixes #12741

changelog: none
2024-05-04 19:36:06 +00:00
Ross Smyth
68a6cbfc6c Update clippy tests for stable exclusive_range 2024-05-02 19:42:37 -04:00
Rebecca Turner
db0cbbacb7
useless_attribute: allow ambiguous_glob_exports
Closes https://github.com/rust-lang/rust-clippy/issues/10878
2024-05-02 14:48:18 -07:00
Rebecca Turner
96e69d9b43
useless_attribute: allow hidden_glob_reexports
Closes https://github.com/rust-lang/rust-clippy/issues/11595
2024-05-02 14:48:11 -07:00
Rebecca Turner
e9761bdc01
useless_attribute: allow dead_code
Closes https://github.com/rust-lang/rust-clippy/issues/4467
2024-05-02 11:57:56 -07:00
Rebecca Turner
17d2ab8f62
useless_attribute: allow unused_braces 2024-05-02 11:56:05 -07:00
Rebecca Turner
8d8c0bfb0e
useless_attribute: allow clippy::disallowed_types
Closes https://github.com/rust-lang/rust-clippy/issues/12753
2024-05-02 11:55:11 -07:00
Ruihan Li
a032189503 Fix significant drop detection 2024-05-03 00:02:18 +08:00
Philipp Krones
80c6f8ff7b Merge commit '20b085d500dfba5afe0869707bf357af3afe20be' into clippy-subtree-update 2024-05-02 17:26:44 +02:00
bors
20b085d500 Auto merge of #12745 - y21:collapsible_match_or_pat, r=llogiq
Suggest collapsing nested or patterns if the MSRV allows it

Nested `or` patterns have been stable since 1.53, so we should be able to suggest `Some(1 | 2)` if the MSRV isn't set below that.

This change adds an msrv check and also moves it to `matches/mod.rs`, because it's also needed by `redundant_guards`.

changelog: [`collapsible_match`]: suggest collapsing nested or patterns if the MSRV allows it
2024-05-02 12:57:59 +00:00
bors
a2bd02b57e Auto merge of #12515 - bend-n:🦀, r=llogiq
fix `for x in y unsafe { }`

fixes #12514

----

changelog: [`needless_for_each`]: unsafe block in for loop body suggestion
2024-05-02 12:36:42 +00:00
bors
1325425589 Auto merge of #12748 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-05-02 12:26:02 +00:00
Philipp Krones
e8492355a3
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-02 14:21:00 +02:00
Oliver Scherer
dcfc3b5de1 Bump ui_test to 0.23 2024-05-02 12:44:40 +02:00
y21
790fb9396a check for matches! macro directly in redundant_guards 2024-05-02 05:05:26 +02:00
y21
272413f458 allow or patterns for a high enough MSRV in collapsible_match 2024-05-02 04:45:45 +02:00
Nilstrieb
b10be16702 Handle rustc_on_unimplemented in duplicated_attributes 2024-05-01 17:57:23 +02:00
bors
852a64f875 Auto merge of #11988 - J-ZhengLi:issue11324, r=Alexendoo
fix suggestion error for [`manual_is_ascii_check`] with missing type

fixes: #11324
fixes: #11776

changelog: improve [`manual_is_ascii_check`] to suggest labeling type in closure, fix FP with type generics, and improve linting on ref expressions.
2024-05-01 13:54:24 +00:00
Alex Macleod
c313ef51df Don't lint assigning_clones on nested late init locals 2024-05-01 12:22:50 +00:00
bors
a7f66baaf1 Auto merge of #12687 - Alexendoo:box-default-generic-fn, r=xFrednet
Don't suggest `Box::default()` in functions with differing generics

Fixes #12684

changelog: none
2024-05-01 12:02:17 +00:00
bors
4bee9788a8 Auto merge of #124398 - klensy:trailing-ws, r=compiler-errors
tests: remove some trailing ws

Cleans one more case of trailing whitespace in tests.
2024-04-30 00:42:32 +00:00
bors
4261e0b28d Auto merge of #12734 - y21:issue12733, r=Manishearth
suppress `readonly_write_lock` for underscore-prefixed bindings

Fixes #12733

Unsure if there's a better way to prevent this kind of false positive but this is the one that made most sense to me.
In my experience, prefixing bindings with an underscore is the usual way to name variables that aren't used and that exist purely for executing drop code at the end of the scope.

-------

changelog: suppress [`readonly_write_lock`] for underscore-prefixed bindings
2024-04-29 22:40:30 +00:00
Ulążka Mateusz
71db2d1451 [type_complexity]: Fix duplicate errors 2024-04-29 22:32:36 +02:00
y21
f0beaedf83 suppress readonly_write_lock for underscore-prefixed bindings 2024-04-29 17:30:01 +02:00
bors
0fc9a65b8f Auto merge of #12694 - J-ZhengLi:issue11783, r=dswij
check if closure as method arg has read access in [`collection_is_never_read`]

fixes: #11783

---

changelog: fix [`collection_is_never_read`] misfires when use `retain` for iteration
2024-04-29 14:09:05 +00:00
J-ZhengLi
cbdc36aa09 skip warning when generic evolved;
suggest explicit type when its inferred in closure
2024-04-29 13:38:45 +08:00
bors
e68fcb0973 Auto merge of #12725 - llogiq:allow-useless-test-vecs, r=blyxyas
configurably allow `useless_vec` in tests

This adds a `àllow-useless-vec-in-test` configuration which, when set to `true` will allow the `useless_vec` lint in `#[test]` functions and code within `#[cfg(test)]`. It also moves a `is_in_test` helper to `clippy_utils`.

---

changelog: configurably allow [`useless_vec`] in test code
2024-04-28 20:10:33 +00:00
Andre Bogus
87efce4fa2 configurably allow useless_vec in tests
This adds a `àllow-useless-vec-in-test` configuration which, when set
to `true` will allow the `useless_vec` lint in `#[test]` functions and
code within `#[cfg(test)]`. It also moves a `is_in_test` helper to
`clippy_utils`.
2024-04-28 22:07:56 +02:00
Alex Macleod
fa8f4b88cb Lint direct priority conflicts in [lints.workspace] 2024-04-28 14:16:19 +00:00
Mats Macke
0b1f09e6f7 Fixed reduction of & in cast_possible_truncation
Fixed formatting

Added tests for issue #12721

Checking for reduction on RHS
2024-04-28 16:01:33 +02:00
bors
c6bf9548d5 Auto merge of #12624 - J-ZhengLi:issue12586, r=xFrednet
fix [`large_stack_arrays`] linting in `vec` macro

fixes: #12586

this PR also adds a wrapper function `matching_root_macro_call` to `clippy_utils::macros`, considering how often that same pattern appears in the codebase.

(I'm always very indecisive towards naming, so, if anyone have better idea of how that function should be named, feel free to suggest it)

---

changelog: fix [`large_stack_arrays`] linting in `vec` macro; add `matching_root_macro_call` to clippy_utils
2024-04-27 09:30:20 +00:00
klensy
a8e0bcb336 clippy: bless tests 2024-04-27 10:54:35 +03:00
Vadim Petrochenkov
ec9ddc7b7a ast: Generalize item kind visiting
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-25 22:49:58 +03:00
bors
9162bbf5ac Auto merge of #12702 - Luv-Ray:non_canonical_partial_ord_impl, r=Manishearth
[`non_canonical_partial_ord_impl`]: Fix emitting warnings which conflict with `needless_return`

fixes #12683

---

changelog: fix [`non_canonical_partial_ord_impl`] emitting warnings which conflict with `needless_return`
2024-04-24 17:25:34 +00:00
Gary Guo
7d9f970d4e Fix and bless clippy tests 2024-04-24 13:12:33 +01:00
Oli Scherer
3fc9537624 Error on using yield without also using #[coroutine] on the closure
And suggest adding the `#[coroutine]` to the closure
2024-04-24 08:05:29 +00:00
Luv-Ray
107e44b76f [non_canonical_partial_ord_impl]: Fix emitting warnings which conflict with needless_return 2024-04-24 10:54:08 +08:00
forcedebug
d55e5b4500 chore: fix some typos in comments
Signed-off-by: forcedebug <forcedebug@outlook.com>
2024-04-23 20:31:26 +08:00
Matthias Krüger
53b5056977 Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwco
Disallow ambiguous attributes on expressions

This implements the suggestion in [#15701](https://github.com/rust-lang/rust/issues/15701#issuecomment-2033124217) to disallow ambiguous outer attributes on expressions. This should resolve one of the concerns blocking the stabilization of `stmt_expr_attributes`.
2024-04-23 12:10:26 +02:00
bors
7fcaa60efd Auto merge of #12692 - c410-f3r:arrrr, r=Manishearth
[arithmetic_side_effects] Fix #12318

Fix #12318

changelog: [arithmetic_side_effects]: Consider method calls that correspond to arithmetic symbols
2024-04-22 18:52:03 +00:00
bors
fc6dfeb1bf Auto merge of #11852 - rust-lang:single-char-pattern-ascii-only, r=xFrednet
reduce `single_char_pattern` to only lint on ascii chars

This should mostly fix the `single_char_pattern` lint, because with a single byte, the optimizer will usually see through the char-to-string-expansion and single loop iteration. This fixes #11675 and #8111.

Update: As per the meeting on November 28th, 2023, we voted to also downgrade the lint to pedantic.

---

changelog: downgrade [`single_char_pattern`] to `pedantic`
2024-04-22 13:29:35 +00:00
Luv-Ray
334bab2c25 [overly_complex_bool_expr]: Fix trigger wrongly on never type 2024-04-21 19:53:47 +08:00
bors
c642d0cab6 Auto merge of #12696 - smoelius:fix-is_test_module_or_function, r=Alexendoo
Fix `is_test_module_or_function`

The rustdoc comment for `is_test_module_or_function` states: 2795a60189/clippy_utils/src/lib.rs (L2561-L2566)

Given `item`, the function calls `is_in_test_function` with `item.hir_id()`. However, `is_in_test_function` considers only `item`'s parents, not `item` itself. This PR fixes the problem.

The `test_with_disallowed_name` test fails without the fix, but passes once applied.

changelog: none
2024-04-20 15:06:02 +00:00
bors
8eafeeb47a Auto merge of #12691 - Alexendoo:ignore-interior-mutability-indirect, r=llogiq
Rework interior mutability detection

Replaces the existing interior mutability detection, the two main changes being

- It now follows references/pointers e.g. `struct S(&Cell)`
  - `mutable_key_type` ignores pointers as it did before
- The `ignore_interior_mutability` config now applies to types containing the ignored type, e.g. `http::HeaderName`

Fixes https://github.com/rust-lang/rust-clippy/issues/7752
Fixes https://github.com/rust-lang/rust-clippy/issues/9776
Fixes https://github.com/rust-lang/rust-clippy/issues/9801

changelog: [`mutable_key_type`], [`declare_interior_mutable_const`]: now considers types that have references to interior mutable types as interior mutable
2024-04-20 13:54:55 +00:00
Samuel Moelius
898baf81cd Add test_with_disallowed_name 2024-04-20 01:16:30 +00:00
Quinn Sinclair
206b1a1ac9 Threadlocal_initializer_can_be_made_const will not trigger for unreachable initializers
This commit introduces a check to ensure that the lint won't trigger when the initializer is
unreachable, such as:

```
thread_local! {
    static STATE: Cell<usize> = panic!();
}
```

This is achieved by looking at the unpeeled initializer expression and ensuring that the parent
macro is not `panic!()`, `todo!()`, `unreachable!()`, `unimplemented!()`.

fixes #12637

changelog: [`threadlocal_initializer_can_be_made_const`] will no longer trigger on `unreachable` macros.
2024-04-19 23:21:33 +02:00