Commit graph

20971 commits

Author SHA1 Message Date
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
Nicholas Nethercote
5a8943649a Remove ResultsCursor::contains.
It's hardly worth it, and it needs to be removed so that
`GenKillAnalysis` can be removed.
2024-10-14 16:35:28 +11: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
979e297189
Update book 2024-10-13 21:17:03 +01:00
GnomedDev
a650692f8d
Add test 2024-10-13 21:03:39 +01: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
Trevor Gross
ea48cf362c Rollup merge of #131120 - tgross35:stabilize-const_option, r=RalfJung
Stabilize `const_option`

This makes the following API stable in const contexts:

```rust
impl<T> Option<T> {
    pub const fn as_mut(&mut self) -> Option<&mut T>;
    pub const fn expect(self, msg: &str) -> T;
    pub const fn unwrap(self) -> T;
    pub const unsafe fn unwrap_unchecked(self) -> T;
    pub const fn take(&mut self) -> Option<T>;
    pub const fn replace(&mut self, value: T) -> Option<T>;
}

impl<T> Option<&T> {
    pub const fn copied(self) -> Option<T>
    where T: Copy;
}

impl<T> Option<&mut T> {
    pub const fn copied(self) -> Option<T>
    where T: Copy;
}

impl<T, E> Option<Result<T, E>> {
    pub const fn transpose(self) -> Result<Option<T>, E>
}

impl<T> Option<Option<T>> {
    pub const fn flatten(self) -> Option<T>;
}
```

The following functions make use of the unstable `const_precise_live_drops` feature:

- `expect`
- `unwrap`
- `unwrap_unchecked`
- `transpose`
- `flatten`

Fixes: <https://github.com/rust-lang/rust/issues/67441>
2024-10-12 21:38:35 -05:00
Trevor Gross
3c43a60d06 Stabilize const_option
This makes the following API stable in const contexts:

    impl<T> Option<T> {
        pub const fn as_mut(&mut self) -> Option<&mut T>;
        pub const fn expect(self, msg: &str) -> T;
        pub const fn unwrap(self) -> T;
        pub const unsafe fn unwrap_unchecked(self) -> T;
        pub const fn take(&mut self) -> Option<T>;
        pub const fn replace(&mut self, value: T) -> Option<T>;
    }

    impl<T> Option<&T> {
        pub const fn copied(self) -> Option<T>
        where T: Copy;
    }

    impl<T> Option<&mut T> {
        pub const fn copied(self) -> Option<T>
        where T: Copy;
    }

    impl<T, E> Option<Result<T, E>> {
        pub const fn transpose(self) -> Result<Option<T>, E>
    }

    impl<T> Option<Option<T>> {
        pub const fn flatten(self) -> Option<T>;
    }

The following functions make use of the unstable
`const_precise_live_drops` feature:

- `expect`
- `unwrap`
- `unwrap_unchecked`
- `transpose`
- `flatten`

Fixes: <https://github.com/rust-lang/rust/issues/67441>
2024-10-12 17:07:13 -04: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
bors
48e98ec68d Auto merge of #13537 - Manishearth:applicable, r=xFrednet
Mark unnecessary_first_then_check and byte_char_slices as Applicable

I don't really see situations where this isn't Applicable that aren't weird edge cases where the lint should be disabled.

changelog: none
2024-10-11 22:25:00 +00: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
6f1def79dd Auto merge of #13269 - GuillaumeGomez:rewrite-lints-page, r=Alexendoo
Rewrite lints page

This PR has multiple goals:

* Make lints page to work without needing a web server by removing the json file.
* Prepare the field to also make the page work with JS (not done in this PR but should be straightforward).
* Remove angular dependency.

r? `@Alexendoo`

changelog: make lint page work without web server
2024-10-11 14:18:54 +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
f5cc292830 Auto merge of #131045 - compiler-errors:remove-unnamed_fields, r=wesleywiser
Retire the `unnamed_fields` feature for now

`#![feature(unnamed_fields)]` was implemented in part in #115131 and #115367, however work on that feature has (afaict) stalled and in the mean time there have been some concerns raised (e.g.[^1][^2]) about whether `unnamed_fields` is worthwhile to have in the language, especially in its current desugaring. Because it represents a compiler implementation burden including a new kind of anonymous ADT and additional complication to field selection, and is quite prone to bugs today, I'm choosing to remove the feature.

However, since I'm not one to really write a bunch of words, I'm specifically *not* going to de-RFC this feature. This PR essentially *rolls back* the state of this feature to "RFC accepted but not yet implemented"; however if anyone wants to formally unapprove the RFC from the t-lang side, then please be my guest. I'm just not totally willing to summarize the various language-facing reasons for why this feature is or is not worthwhile, since I'm coming from the compiler side mostly.

Fixes #117942
Fixes #121161
Fixes #121263
Fixes #121299
Fixes #121722
Fixes #121799
Fixes #126969
Fixes #131041

Tracking:
* https://github.com/rust-lang/rust/issues/49804

[^1]: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Unnamed.20struct.2Funion.20fields
[^2]: https://github.com/rust-lang/rust/issues/49804#issuecomment-1972619108
2024-10-11 13:11:13 +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
5840f78c6c Auto merge of #13530 - blyxyas:back-from-burnout, r=blyxyas
Back from burnout

This reverts commit 5ea7044d72. I needed some time free from reviewing to focus on the Project Goal and myself.

Now I'm much better, and we can continue reviewing!

I hope that I can approve this myself 😅

changelog: none
2024-10-10 12:42:58 +00:00
blyxyas
2acc0c37da Revert "Temporarily remove myself from reviewer rotation"
This reverts commit 5ea7044d72.
I'm back from burnout, we're ready again!
2024-10-10 14:12:35 +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
731c473fd9
Changelog for Clippy 1.82 ✈️ 2024-10-09 19:04:21 +02: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
Eric Holk
c038c3030b Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
bors
6f4bf9057a Auto merge of #13329 - RalfJung:git-commit-rerun, r=Alexendoo,flip1995
rustc_tools_util: rerun when git commit changes

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

changelog: none
2024-10-07 17:36:04 +00:00
Philipp Krones
fba7ea7e97
Bump rust-tools-util version in Clippy Cargo.toml 2024-10-07 19:32:18 +02:00
Philipp Krones
65fdfb835c
Update README and CHANGELOG 2024-10-07 19:23:50 +02:00
Ralf Jung
eb6c346137
rustc_tools_util: bump version 2024-10-07 19:23:50 +02:00
Ralf Jung
9f7a09021d
rustc_tools_util: rerun when git commit changes 2024-10-07 19:23:50 +02: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