Commit graph

12062 commits

Author SHA1 Message Date
alexey semenyuk
64c4cf1cba
Fix version for ref_option 2024-10-20 14:43:32 +05:00
bors
5678531c6d Auto merge of #13564 - GnomedDev:fix-manualbits-in-macro, r=blyxyas
Stop linting manual_bits in any macro invoke

Closes #13563.

changelog: [`manual_bits`] No longer lints in macro-generated code
2024-10-19 14:09:28 +00:00
bors
f2f0175eb2 Auto merge of #13543 - GnomedDev:symbol-comparisons, r=y21
Add internal lint to check for slow symbol comparisons

See the conversation on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Checking.20a.20Symbol.20is.20equal.20to.20a.20string.20literal).

changelog: none
2024-10-18 23:20:38 +00:00
GnomedDev
a739cc3abe
Stop linting manual_bits in any macro invoke 2024-10-18 21:41:05 +01:00
Philipp Krones
4d5eaa0344
Bump Clippy version -> 0.1.84 2024-10-18 13:25:50 +02:00
Philipp Krones
224d1e323a
Merge remote-tracking branch 'upstream/master' into rustup 2024-10-18 13:25:37 +02:00
bors
dae1be90ee Auto merge of #13525 - xFrednet:changelog-1-82, r=dswij
Changelog for Clippy 1.82 ✈️

```
Roses are red,
Violets are blue,
EuroRust in Austria,
    RustConf in Canada.
```

---

### The cat of this release is *Racka*:

<img height=500 src="https://github.com/user-attachments/assets/e5e3cc95-6fc3-4214-aab0-4f26e0967ae5" alt="The cats of this Clippy release" />

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

---

changelog: none
2024-10-17 11:13:09 +00:00
Anastasis Georgoulas
48636259df Correct typo in lint description 2024-10-15 22:47:04 +01:00
Asuna
ac81f176a8 Change the category of manual_is_power_of_two to pedantic 2024-10-15 21:27:46 +02:00
GnomedDev
b62d2624ac
Use path_res instead of lowering hir::Ty to ty::Ty 2024-10-15 17:06:21 +01:00
GnomedDev
42511a3ffa
Add lint for unnecessary lifetime bounded &str return 2024-10-15 17:06:21 +01:00
xFrednet
fcf46466ce
Move too_long_first_doc_paragraph to nursery
See: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/too_long_first_doc_paragraph.20to.20nursery.3F/near/476448239
2024-10-15 17:08:53 +02:00
Michael Goulet
360d86e9ec Move trait bound modifiers into hir::PolyTraitRef 2024-10-14 09:20:38 -04:00
bors
f444012c4c Auto merge of #13454 - samueltardieu:push-ymnkzlqloptz, r=xFrednet
Use correct std/core prefix in lint output

changelog: none

I was waiting for #13452 to be merged before sending this one. `std` is used instead of `core` when appropriate in messages.
2024-10-14 13:12:22 +00:00
bors
43e99e54fa Auto merge of #13541 - xFrednet:0-module-name-rep, r=blyxyas
Move `clippy::module_name_repetitions` to `restriction` (from `pedantic`)

Rational:
- Too pedantic IMO, I use `#[warn(pedantic)]` in my personal projects, but then always allow this lint. The fact that we had a few `#[expect(clippy::module_name_repetitions)]` also underlines this point IMO
- STD doesn't do this either. Examples:
  - std::vec::Vec
  - std::collections::vec_deque::VecDequeue
- #7666 commonly ignored

---

changelog: Move [`module_name_repetitions`] to `restriction` (from `pedantic`)
[#13541](https://github.com/rust-lang/rust-clippy/pull/13541)
2024-10-13 23:39:55 +00:00
GnomedDev
dedc380df9
Apply fixes from lint 2024-10-13 21:03:38 +01:00
bors
6a281e9a73 Auto merge of #13487 - Coekjan:fix-slice-size-calc-on-ref-ref, r=dswij
Fix lint `manual_slice_size_calculation` when a slice is ref more than once

When a slice is ref more than once, current suggestion given by `manual_slice_size_calculation` is wrong. For example:

```rs
let s: &[i32] = &[1, 2][..];
let ss: &&[i32] = &s;  // <-----

let _ = size_of::<i32>() * ss.len();
```

clippy now suggests:

```patch
- let _ = size_of::<i32>() * ss.len();
+ let _ = size_of_val(ss);
```

However, this can result in calculating the size of `&[i32]`, instead of `[i32]` (this wrong suggestion also leads to `size_of_ref` warning: https://rust-lang.github.io/rust-clippy/master/index.html#/size_of_ref )

Now I am sending this PR to fix this bug, so that clippy will suggest (some deref added):

```patch
- let _ = size_of::<i32>() * ss.len();
+ let _ = size_of_val(*ss);
```

As I am not familiar with current clippy code-base, please correct me if I am not doing well or I can do it better :)

changelog: [`manual_slice_size_calculation`]: fix a bug when a slice is ref more than once.
2024-10-13 15:49:30 +00:00
GnomedDev
6b1779b0ee
Add lint to check for slow symbol comparisons 2024-10-13 16:36:22 +01:00
bors
f883e28e3d Auto merge of #13542 - blyxyas:fix-implicit_saturating_sub, r=y21
[`implicit_saturating_sub`] Fix suggestion with a less volatile approach

Related to #13533, such and obvious mistake got pass my watch, quite embarassing :/

Revert #13533 and implement a more robust solution.

Revert "Fix span issue on `implicit_saturating_sub`
This reverts commit 140a1275f2.

changelog: [`lint_name`]: Fix suggestion for `if {} else if {} else {}` cases

r? `@y21`
2024-10-13 15:24:05 +00:00
bors
236751d093 Auto merge of #13540 - GnomedDev:create-dir-single-arg, r=y21
Check MethodCall/Call arg count earlier or at all

This gets rid of a bunch of possible panic spots, as well as bailing out earlier for optimisation reasons.

I started doing this because I saw that a significant amount of time was being spent in the `create_dir` restriction lint when running clippy with `perf`, but this also helps with robustness.

changelog: none
2024-10-13 13:34:48 +00:00
GnomedDev
ef1db3f502 Check MethodCall/Call arg count earlier or at all 2024-10-13 11:24:47 +01:00
bors
04849bd7d9 Auto merge of #13510 - alex-semenyuk:cleanup_const_float_classify, r=llogiq
Cleanup `const_float_classify`

As mentioned at #13508 `const_float_classify` has been stabilized recently in https://github.com/rust-lang/rust/pull/130157 and can be cleanup

Close #13508

changelog: [none]
2024-10-13 09:17:14 +00:00
Samuel Tardieu
46a0770102 Use correct std/core prefix in lint output 2024-10-13 10:48:27 +02:00
bors
c71f0bebd2 Auto merge of #13334 - nyurik:ascii-str-eq, r=xFrednet
Add manual_ignore_cast_cmp lint

```rust
// bad
fn compare(a: &str, b: &str) -> bool {
    a.to_ascii_lowercase() == b.to_ascii_lowercase()
    || a.to_ascii_lowercase() == "abc"
}

// good
fn compare(a: &str, b: &str) -> bool {
   a.eq_ignore_ascii_case(b)
   || a.eq_ignore_ascii_case("abc")
}
```

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

changelog: New lint: [`manual_ignore_case_cmp`] `perf`
[#13334](https://github.com/rust-lang/rust-clippy/pull/13334)

Closes #13204
2024-10-13 07:34:38 +00:00
Matthias Krüger
b1c468422a Rollup merge of #131277 - ismailarilik:handle-potential-query-instability-lint-for-clippy, r=xFrednet
Handle `clippy` cases of `rustc::potential_query_instability` lint

This PR removes `#![allow(rustc::potential_query_instability)]` line from [`src/tools/clippy/clippy_lints/src/lib.rs`](https://github.com/rust-lang/rust/blob/master/src/tools/clippy/clippy_lints/src/lib.rs#L30) and converts `FxHash{Map,Set}` types into `FxIndex{Map,Set}` to suppress lint errors.

A somewhat tracking issue: https://github.com/rust-lang/rust/issues/84447
2024-10-12 23:00:57 +02:00
bors
55f6029baa Auto merge of #13444 - kpreid:fix-8524-private-rep, r=blyxyas
`module_name_repetitions`: don't warn if the item is in a private module.

Fixes <https://github.com/rust-lang/rust-clippy/issues/8524>.

There is still a warning (as there should be) if the item is reexported by name, but not by glob; that would require further work to examine the names in the glob, and I haven't looked into that.

Credit to `@Centri3` for suggesting approximately this simple fix in <https://github.com/rust-lang/rust-clippy/issues/8524#issuecomment-1729036149>. However, per later comment <https://github.com/rust-lang/rust-clippy/issues/8524#issuecomment-2035836495>, I am not making it configuration-dependent, but *always* checking public items in public modules only.

changelog: [`module_name_repetitions`]: don't warn if the item is in a private module.
2024-10-12 16:46:31 +00:00
blyxyas
2b562dece6 Fix suggestion with a less volatile approach
Revert "Fix span issue on `implicit_saturating_sub`"
This reverts commit 140a1275f2.
2024-10-12 17:43:06 +02:00
xFrednet
8b075fc634
Move clippy::module_name_repetitions to restriction (from pedantic)
Rational:
- Too pedantic IMO, it's often better to have fine grained modules and
  then rexport stuff instead of one gigantic file
- STD doesn't do this either. Examples:
  - std::vec::Vec
  - std::collections::vec_deque::VecDequeue
- rust-clippy#7666 commonly ignored
2024-10-12 12:03:24 +02:00
Manish Goregaokar
42723dc9df Mark unnecessary_first_then_check and byte_char_slices as Applicable 2024-10-11 12:20:07 -07:00
bors
b85f632607 Auto merge of #13528 - zvavybir:master, r=Alexendoo
Improved wording of or_fun_call lint

The current wording (e.g. ``use of `ok_or` followed by a function call``) is potentially confusing (at least it confused me) by suggesting that the function that follows the (in this case) `ok_or` is the problem and not the function that is an argument to it.

The code in my program that triggered the confusing message is the following:
```rust
let file_id = buf
    .lines()
    .next()
    .ok_or((
        InternalError::ProblemReadingFromInbox,
        anyhow!("No first line in inbox response ({file:?}): {buf:?}"),
    ))
    .html_context(stream, lang)?;
```
I thought that `html_context` was the problem and that I should do something along the following lines:
```rust
let file_id = buf
    .lines()
    .next()
    .ok_or_else(
        (
            InternalError::ProblemReadingFromInbox,
            anyhow!("No first line in inbox response ({file:?}): {buf:?}"),
        ),
        html_context(stream, lang),
    )?
```
This is of course wrong.  My confusion was only cleared up through the help message indicating what I should try instead.

If someone has a better idea of a replacement wording (currently e.g. ``` function call inside of `ok_or` ```), I'm all ears.

changelog: none
2024-10-11 15:01:07 +00:00
bors
8125cd5c2a Auto merge of #13359 - blyxyas:declare_clippy_macro, r=Alexendoo
Turn declare_clippy_lint into a declarative macro

Ease of development, and hopefully compile times (the dependencies are still there because of ui-test). The procedural macro was doing just some very basic processing (like assigning a lint level to each category), so it didn't have a reason to stay IMO

changelog: None
2024-10-11 14:10:01 +00:00
bors
47903dbf97 Auto merge of #13532 - y21:issue13531, r=Alexendoo
Only emit `manual_c_str_literals` in >= Edition 2021

Fixes #13531

changelog: none
2024-10-11 12:47:38 +00:00
bors
05f3793392 Auto merge of #13534 - GnomedDev:fix-large-stack-arrays-nested-item, r=flip1995
Fix large_stack_arrays triggering when nesting const items

Fixes #13529.

r? `@flip1995`

changelog: [`large_stack_arrays`]: No longer triggers in static/const context when using nested items
2024-10-11 09:04:46 +00:00
bors
14c05c974c Auto merge of #13533 - blyxyas:fix-implicit_saturating_sub, r=dswij
Fix span issue on `implicit_saturating_sub`

Fixes #13524

changelog: [`implicit_saturating_sub`]: Fix span issue on else blocks
2024-10-11 06:25:08 +00:00
GnomedDev
87b4c1ffb7
Fix large_stack_arrays triggering when nesting const items 2024-10-10 22:01:46 +01:00
blyxyas
140a1275f2 Fix span issue on implicit_saturating_sub
Fixes #13524
2024-10-10 19:10:04 +02:00
Alexey Semenyuk
cb19f23c79 Clean up const_float_classify leftovers 2024-10-10 22:08:45 +05:00
y21
2b86ffc57e only emit manual_c_str_literals in >= edition2021 2024-10-10 18:08:40 +02:00
bors
806a9dfddd Auto merge of #13464 - y21:issue13458, r=flip1995
Don't warn on proc macro generated code in `needless_return`

Fixes #13458
Fixes #13457
Fixes #13467
Fixes #13479
Fixes #13481
Fixes #13526
Fixes #13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
2024-10-10 11:34:13 +02:00
bors
8e60f143d8 Auto merge of #13464 - y21:issue13458, r=flip1995
Don't warn on proc macro generated code in `needless_return`

Fixes #13458
Fixes #13457
Fixes #13467
Fixes #13479
Fixes #13481
Fixes #13526
Fixes #13486

The fix is unfortunately a little more convoluted than just simply adding a `is_from_proc_macro`. That check *does*  fix the issue, however it also introduces a bunch of false negatives in the tests, specifically when the returned expression is in a different syntax context, e.g. `return format!(..)`.

The proc macro check builds up a start and end pattern based on the HIR nodes and compares it to a snippet of the span, however that would currently fail for `return format!(..)` because we would have the patterns `("return", <something inside of the format macro>)`, which doesn't compare equal. So we now return an empty string pattern for when it's in a different syntax context.

"Hide whitespace" helps a bit for reviewing the proc macro detection change

changelog: none
2024-10-10 09:17:20 +00:00
Matthias Kaak
8c46c498d9 Improved wording of or_fun_call lint
Signed-off-by: Matthias Kaak <zvavybir@zvavybir.eu>
2024-10-10 08:05:41 +00:00
xFrednet
33018b46f4
Update version attribute for 1.81 lints 2024-10-09 19:04:20 +02:00
bors
1f8f982f22 Auto merge of #13504 - samueltardieu:needless-raw-strings, r=Alexendoo
Check for needless raw strings in `format_args!()` template as well

changelog: [`needless_raw_strings`, `needless_raw_string_hashes`]: check `format_args!()` template as well

Fix #13503
2024-10-09 01:35:08 +00:00
bors
d9c8d976cb Auto merge of #13512 - samueltardieu:issue-13511, r=xFrednet
`infinite_loop`: continuing an outer loop leaves the inner loop

changelog: [`infinite_loop`]: detect a `continue` targeting an outer loop

Fix #13511
2024-10-08 08:49:07 +00:00
Samuel Tardieu
36c31db705 Apply updated needless_raw_strings to Clippy sources 2024-10-07 18:29:25 +02:00
Samuel Tardieu
5e78c15caa raw_strings: handle format template as well 2024-10-07 18:29:24 +02:00
bors
b013e69692 Auto merge of #13496 - y21:issue10619, r=Alexendoo
Show interior mutability chain in `mutable_key_type`

Fixes #10619

Just ran into this myself and I definitely agree it's not very nice to have to manually go through all the types involved to figure out why this happens and to evaluate if this is really a problem (knowing if the field of a struct is something that a hash impl relies on), so this changes the lint to emit notes for each step involved.

changelog: none
2024-10-07 15:32:34 +00:00
Samuel Tardieu
99ce411ed6 infinite_loop: continuing an outer loop leaves the inner loop 2024-10-06 19:19:27 +02:00
bors
1c9e5d0e5c Auto merge of #13513 - samueltardieu:push-zvvzytrovulq, r=y21
Style: do not defensively use `saturating_sub()`

Using `saturating_sub()` here in code which cannot fail brings a false sense of security. If for any reason a logic error was introduced and caused `self.loop_depth` to reach 0 before being decremented, using `saturating_sub(1)` would silently mask the programming error instead of panicking loudly as it should (at least in dev profile).

changelog: none
2024-10-06 17:15:53 +00:00
Samuel Tardieu
af6816c5b6 infinite_loop: do not defensively use saturating_sub()
Using `saturating_sub()` here in code which cannot fail brings a false
sense of security. If for any reason a logic error was introduced and
caused `self.loop_depth` to reach 0 before being decremented, using
`saturating_sub(1)` would silently mask the programming error instead of
panicking loudly as it should (at least in dev profile).
2024-10-06 18:52:24 +02:00