Commit graph

7796 commits

Author SHA1 Message Date
bors
eb0df1d4f4 Auto merge of #11454 - samueltardieu:issue-11403, r=Centri3
Ignore wildcards in function arguments and local bindings

Fix #11403

changelog: none
2023-09-05 12:01:31 +00:00
Samuel Tardieu
2f5c445c0b Ignore wildcards in function arguments and local bindings 2023-09-04 17:18:33 +02:00
Samuel Tardieu
822c7df545 Add ui_test error annotations in existing tests 2023-09-04 17:05:03 +02:00
y21
cf10690ad4 check that the receiver type satisfies bounds 2023-09-04 16:34:57 +02:00
y21
e34e49f7ff useless_conversion: don't lint if ty param has multiple bounds 2023-09-04 16:20:38 +02:00
Urgau
a86e758228 Adjust clippy tests with new rustc help suggestion for lints 2023-09-04 14:22:02 +02:00
bors
bcf856bfb3 Auto merge of #11375 - J-ZhengLi:issue11246, r=Centri3
fix fp when [`undocumented_unsafe_blocks`] not able to detect comment on globally defined const/static variables

fixes: #11246

changelog: fix detection on global variables for [`undocumented_unsafe_blocks`]
2023-09-04 09:47:45 +00:00
J-ZhengLi
438f934f1c suggest passing function instead of calling it in [option_if_let_else] 2023-09-04 16:15:45 +08:00
bors
da882f0a5a Auto merge of #11455 - digama0:never_loop3, r=Centri3,dswij
skip `todo!()` in  `never_loop`

As promised in #11450, here is an implementation which skips occurrences of the `todo!()` macro.

changelog: [`never_loop`]: skip loops containing `todo!()`
2023-09-04 05:51:47 +00:00
Mario Carneiro
4e0a3465d1 fix vec.rs test, comment 2023-09-04 06:35:51 +02:00
bors
f13e1f429a Auto merge of #11259 - Jarcho:ice_10253, r=dswij
Don't pass extra generic arguments in `needless_borrow`

fixes #10253

Also switches to using `implements_trait` which does ICE when clippy's debug assertions are enabled.

changelog: None
2023-09-04 03:17:50 +00:00
y21
7262145964 [implied_bounds_in_impl]: fix suggestion for assoc types 2023-09-03 22:21:03 +02:00
bors
3de0f19c41 Auto merge of #11437 - y21:issue-11422, r=xFrednet
[`implied_bounds_in_impls`]: don't ICE on default generic parameter and move to nursery

Fixes #11422

This fixes two ICEs ([1](https://github.com/rust-lang/rust-clippy/issues/11422#issue-1872351763), [2](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2901e6febb479d3bd2a74f8a5b8a9305)), and moves it to nursery for now, because this lint needs some improvements in its suggestion (see #11435, for one such example).

changelog: Moved [`implied_bounds_in_impls`] to nursery (Now allow-by-default)
[#11437](https://github.com/rust-lang/rust-clippy/pull/11437)
changelog: [`implied_bounds_in_impls`]: don't ICE on default generic parameter in supertrait clause

r? `@xFrednet` (since you reviewed my PR that added this lint, I figured it might make sense to have you review this as well since you have seen this code before. If you don't want to review this, sorry! Feel free to reroll then)

--------

As for the ICE, it's pretty complicated and very confusing imo, so I'm going to try to explain the idea here (partly for myself, too, because I've confused myself several times writing- and fixing this):
<details>
<summary>Expand</summary>

The general idea behind the lint is that, if we have this function:
```rs
fn f() -> impl PartialEq<i32> + PartialOrd<i32> { 0 }
```
We want to lint the `PartialEq` bound because it's unnecessary. That exact bound is already specified in `PartialOrd<i32>`'s supertrait clause:
```rs
trait PartialOrd<Rhs>: PartialEq<Rhs> {}
//    PartialOrd<i32>: PartialEq<i32>
```

 The way it does this is in two steps:
- Go through all of the bounds in the `impl Trait` return type and collect each of the trait's supertrait bounds into a vec. We also store the generic arguments for later.
  - `PartialEq` has no supertraits, nothing to add.
  - `PartialOrd` is defined as `trait PartialOrd: PartialEq`, so add `PartialEq` to the list, as well as the generic argument(s) `<i32>`

Once we are done, we have these entries in the vec: `[(PartialEq, [i32])]`

- Go through all the bounds again, and looking for those bounds that have their trait `DefId` in the implied bounds vec.
  - `PartialEq` is in that vec. However, that is not enough, because the trait is generic. If the user wrote `impl PartialEq<String> + PartialOrd<i32>`, then `PartialOrd` clearly doesn't imply `PartialEq`. Which means, we also need to check that the generic parameters match. This is why we also collected the generic arguments in `PartialOrd<i32>`. This process of checking generic arguments is pretty complicated and is also where the two ICEs happened.

The way it checks that the generic arguments match is by comparing the generic parameters in the super trait clause:
```rs
trait PartialOrd<Rhs>: PartialEq<Rhs> {}
//                     ^^^^^^^^^^^^^^
```
...this needs to match...
```rs
fn f() -> impl PartialEq<i32> + ...
//             ^^^^^^^^^^^^^^
```
In the compiler, the `Rhs` generic parameter is its own type and we cannot just compare it to `i32`. We need to "substitute" it.
Internally, `Rhs` is represented as `Rhs#1` (the number next to # represents the type parameter index. They start at 0, but 0 is "reserved" for the implicit `Self` generic parameter).

How do we go from `Rhs#1` to `i32`? Well, we know that all the generic parameters had to be substituted in the `impl ... + PartialOrd<i32>` type. So we subtract 1 from the type parameter index, giving us 0 (`Self` is not specified in that list of arguments). We use that as the index into the generic argument list `<i32>`. That's `i32`. Now we know that the supertrait clause looks like `: PartialEq<i32>`.

Then, we can compare that to what the user actually wrote on the bound that we think is being implied: `impl PartialEq<i32> + ...`.

Now to the actual bug: this whole logic doesn't take into account *default* generic parameters. Actually, `PartialOrd` is defined like this:
```rs
trait PartialOrd<Rhs = Self>: PartialEq<Rhs> {}
```
If we now have a function like this:
```rs
fn f() -> impl PartialOrd + PartialEq {}
```
that logic breaks apart... We look at the supertrait predicate `: PartialEq<Rhs>` (`Rhs` is `Rhs#1`), then take the first argument in the generic argument list `PartialEq<..>` to resolve the `Rhs`, but at this point we crash because there *is no* generic argument.
The index 0 is out of bounds. If this happens (and we even get to linting here, which could only happen if it passes typeck), it must mean that that generic parameter has a default type that is not required to be specified.

This PR changes the logic such that if we have a type parameter index that is out of bounds, it looks at the definition of the trait and check that there exists a default type that we can use instead.
So, we see `<Rhs = Self>`, and use `Self` for substitution, and end up with this predicate: `: PartialEq<Self>`. No crash this time.

</details>
2023-09-03 16:09:40 +00:00
Mario Carneiro
1317378b9e fix todo item check, remove unimplemented 2023-09-03 17:16:06 +02:00
tom-anders
e0014afa2d Add suggestions for std_instead_of_core
Fixes #11446
2023-09-03 14:34:40 +02:00
Mario Carneiro
61a2f972b3 skip todo / unimplemented in never_loop 2023-09-03 01:54:28 -04:00
Michael Watzko
1c27ba931b Stabilize the Saturating type (saturating_int_impl, gh-87920)
Also stabilizes saturating_int_assign_impl, gh-92354.

And also make pub fns const where the underlying saturating_*
fns became const in the meantime since the Saturating type was
created.
2023-09-03 01:22:46 +02:00
y21
26c0f97579 [len_without_is_empty]: follow type alias 2023-09-02 22:55:32 +02:00
y21
51206323a1 [slow_vector_initialization]: only warn on vec![] expn 2023-09-02 16:31:17 +02:00
Mario Carneiro
44f64acb7e never_loop catches loop { panic!() } 2023-09-02 08:18:53 -04:00
Mario Carneiro
b3980d8497 catch never loops through diverging functions 2023-09-02 07:51:34 -04:00
Mario Carneiro
68011893d8 Rewrite never_loop as a strict reachability pass
fixes #11004
2023-09-02 03:14:19 -04:00
bors
a8b5245ea3 Auto merge of #11416 - Alexendoo:raw-strings-multipart, r=xFrednet
Use multipart suggestions for raw string lints

Should make it slightly easier to see the suggested edit

Before/after for `needless_raw_string_hashes`:

| Before| After |
|--------|--------|
| ![before](https://github.com/rust-lang/rust-clippy/assets/1830331/da52a436-d890-4594-9191-819c1af946c7) | ![after](https://github.com/rust-lang/rust-clippy/assets/1830331/9731d790-8efa-42a2-b2e9-0ec51398f8f3) |

changelog: none
2023-09-01 22:19:57 +00:00
Alex Macleod
f595f1e0ff Use multipart suggestions for raw string lints 2023-09-01 21:18:51 +00:00
bors
acdffd791b Auto merge of #11427 - oli-obk:ui_test_bump, r=Alexendoo
Bump ui_test

This makes `ui_test` parse `--bless` and allows a follow up change to use `Mode::Error` (instead of `Mode::Yolo`) with `RustfixMode::Everything`

changelog: none
2023-09-01 11:58:35 +00:00
Oliver Scherer
aeed86c5c1 Bump ui_test to 0.20 2023-09-01 11:48:20 +00:00
Caio
b3136a874d [clippy] Use symbols intended for arithmetic_side_effects 2023-09-01 10:28:55 +02:00
y21
790922c5d6 update ui tests and some minor cleanups 2023-08-31 18:42:27 +02:00
y21
b54bac9f14 new lint: missing_assert_for_indexing 2023-08-31 17:44:19 +02:00
Alex Macleod
299fbceb96 Check binary operators and attributes in disallowed_macros 2023-08-31 13:14:44 +00:00
bors
77e395e87c Auto merge of #11376 - Jarcho:issue_11366, r=llogiq
Fix span when linting `explicit_auto_deref` immediately after `needless_borrow`

fixes #11366

changelog: `explicit_auto_deref`: Fix span when linting immediately after `needless_borrow`
2023-08-31 11:30:37 +00:00
bors
c50d86fc6a Auto merge of #11418 - Benjscho:explicit_iter_loop_config, r=llogiq
Add config flag for reborrows in explicit_iter_loop

This PR adds a config flag for enforcing explicit into iter lint for reborrowed values. The config flag, `enforce_iter_loop_reborrow`, can be added to clippy.toml files to enable the linting behaviour. By default the reborrow lint is disabled.

fixes: #11074

changelog: [`explicit_iter_loop`]: add config flag `enforce_iter_loop_reborrow` to disable reborrow linting by default
2023-08-31 11:19:04 +00:00
y21
563abf9651 [implied_bounds_in_impls]: move to nursery and fix ICEs 2023-08-30 22:08:05 +02:00
bors
3da21b089f Auto merge of #11396 - y21:issue11345, r=Jarcho
new lint: `iter_out_of_bounds`

Closes #11345

The original idea in the linked issue seemed to be just about arrays afaict, but I extended this to catch some other iterator sources such as `iter::once` or `iter::empty`.

I'm not entirely sure if this name makes a lot of sense now that it's not just about arrays anymore (specifically, not sure if you can call `.take(1)` on an `iter::Empty` to be "out of bounds"?).

changelog: [`iter_out_of_bounds`]: new lint
2023-08-30 19:51:32 +00:00
Oli Scherer
11d8e5595b Bump ui_test to 0.18.1 2023-08-30 07:49:17 +00:00
Oli Scherer
6a876f236c Bump ui_test 2023-08-29 13:47:06 +00:00
bors
b97eaab558 Auto merge of #11387 - y21:issue11371, r=blyxyas
[`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`

Closes #11371

This turned out to be a little more code than I originally thought, because the lint also makes sure to not lint if the user tries to mutate the option:
```rs
if option.is_some() {
  option = None;
  option.unwrap(); // don't lint here
}
```
... which means that even if we taught this lint to recognize `.as_mut()`, it would *still* not lint because that would count as a mutation. So we need to allow `.as_mut()` calls but reject other kinds of mutations.
Unfortunately it doesn't look like this is possible with `is_potentially_mutated` (seeing what kind of mutation happened).
This replaces it with a custom little visitor that does basically what it did before, but also allows `.as_mut()`.

changelog: [`unnecessary_unwrap`]: lint on `.as_ref().unwrap()`
2023-08-28 20:29:42 +00:00
bors
5cc5f27899 Auto merge of #11385 - markhuang1212:master, r=blyxyas
skip float_cmp check if lhs is a custom type

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

changelog: [`float_cmp`]: allow float eq comparison when lhs is a custom type that implements PartialEq<f32/f64>

If the lhs of a comparison is not float, it means there is a user implemented PartialEq, and the caller is invoking that custom version of `==`, instead of the default floating point equal comparison.

People may wrap f32 with a struct (say `MyF32`) and implement its PartialEq that will do the `is_close()` check, so that `MyF32` can be compared with either f32 or `MyF32`.
2023-08-28 18:27:53 +00:00
bors
4118738998 Auto merge of #11401 - y21:issue11394, r=xFrednet
[`if_then_some_else_none`]: look into local initializers for early returns

Fixes #11394

As the PR title says, problem was that it only looked for early returns in semi statements. Local variables don't count as such, so it didn't count `let _v = x?;` (or even just `let _ = return;`) as a possible early return and didn't realize that it can't lint then.

Imo the `stmts_contains_early_return` function that was used before is redundant. `contains_return` could already do that if we just made the parameter a bit more generic, just like `for_each_expr`, which can already accept `&[Stmt]`

changelog: [`if_then_some_else_none`]: look into local initializers for early returns
2023-08-28 08:48:35 +00:00
Ben Schofield
be55a96d80 Add config flag for reborrows in explicit_iter_loop
This commit adds a config flag for enforcing explicit into iter lint
for reborrowed values. The config flag, enforce_iter_loop_reborrow, can be
added to clippy.toml files to enable the linting behaviour. By default
the lint is not enabled.
2023-08-27 21:45:14 -06:00
bors
8de52e5bf4 Auto merge of #11405 - Alexendoo:redundant-aux, r=giraffate
Remove redundant auxiliary test files

`ui_test` has special handling for `..` paths so these are no longer needed

changelog: none
2023-08-28 03:43:28 +00:00
y21
33cc140f55 add more negative tests 2023-08-27 23:38:43 +02:00
bors
74a46a74e4 Auto merge of #11391 - mojave2:fix-uitest-enum_clike_unportable_variant, r=Alexendoo
fix the uitest `enum_clike_unportable_variant`

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

changelog: none
2023-08-26 11:01:10 +00:00
bors
4736908ff7 Auto merge of #11404 - mojave2:issue-11368, r=matthiaskrgr
fix "derivable_impls: attributes are ignored"

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

changelog: [`derivable_impls`]: allow the lint when the trait-impl methods has any attribute.
2023-08-26 10:19:21 +00:00
mojave2
d2f6522d78
update uitest enum_clike_unportable_variant
update an uitest stderr

update uitest enum_clike_unportable_variant
2023-08-26 09:34:38 +08:00
y21
f80c55deb5 add a test for statics and doc comments 2023-08-26 01:10:32 +02:00
Alex Macleod
d78d26a8c7 Remove redundant auxiliary test files 2023-08-25 14:25:49 +00:00
Meng Huang
e43c234168
allow float_cmp when lhs is a custom type 2023-08-25 19:48:25 +08:00
mojave2
90fcc67d32
fix "derivable_impls: attributes are ignored" 2023-08-25 19:15:44 +08:00
bors
706c48b62a Auto merge of #11395 - c410-f3r:let-chain, r=Manishearth
[`arithmetic_side_effects`] Fix #11393

Fix #11393

```
changelog: [`arithmetic_side_effects`]: Detect division by zero for `Wrapping` and `Saturating`
```
2023-08-25 01:05:38 +00:00
y21
11072b51fa lint vecs, version bump, more tests 2023-08-25 01:13:35 +02:00
bors
19eaafb920 Auto merge of #11338 - y21:issue11337, r=Centri3
allow trait alias DefIds in `implements_trait_with_env_from_iter`

Fixes #11337

changelog: none
2023-08-24 22:28:29 +00:00
y21
dba7763128 [if_then_some_else_none]: look into local initializers 2023-08-24 23:44:17 +02:00
bors
d65c4595ee Auto merge of #11360 - lengyijun:any_all, r=blyxyas
[`iter_overeager_cloned`]: detect .cloned().all() and .cloned().any()

changelog: [`iter_overeager_cloned`]

r? `@blyxyas`
2023-08-24 19:54:05 +00:00
Philipp Krones
cc61aeea54 Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup 2023-08-24 21:32:12 +02:00
y21
86b6644379 new lint: iter_out_of_bounds 2023-08-24 20:21:55 +02:00
Caio
2faa43c8b4 [arithmetic_side_effects] Fix #11393 2023-08-24 13:22:27 -03:00
lengyijun
fb6fad20c8 [iter_overeager_cloned]: detect .cloned().all() and .cloned().any() 2023-08-24 08:44:25 +08:00
y21
42c6492ebc [unnecessary_unwrap]: lint on .as_ref().unwrap() 2023-08-23 21:02:01 +02:00
y21
12275713d5 support inherent impls and trait impls 2023-08-23 17:06:55 +02:00
y21
09506f49c1 rename lint, docs, improve diagnostics 2023-08-23 17:06:55 +02:00
y21
2ebff58969 make generics work
fix compile error in doc example
2023-08-23 17:05:55 +02:00
y21
42bd6d7af3 new lint: implied_bounds_in_impl 2023-08-23 17:05:55 +02:00
bors
4932d05733 Auto merge of #11373 - Red-Rapious:master, r=blyxyas,y21
Added new lint: `reserve_after_initialization`

Closes https://github.com/rust-lang/rust-clippy/issues/11330.

A new lint that informs the user about a more concise way to create a vector with a known capacity.
Example:
```rust
let mut v: Vec<usize> = vec![];
v.reserve(10);
```

Produces the following help:
```rust
  |
2 | /     let mut v: Vec<usize> = vec![];
3 | |     v.reserve(10);
  | |__________________^ help: consider using `Vec::with_capacity(space_hint)`: `let v: Vec<usize> = Vec::with_capacity(10);`
  |
```

And can be rewritten as:
```rust
let v: Vec<usize> = Vec::with_capacity(10);
```

changelog: new lint [`reserve_after_initialization`]
2023-08-23 12:06:41 +00:00
bors
edfee16ade Auto merge of #11379 - popzxc:fix-tuple-array-conversions, r=xFrednet
Fix tuple_array_conversions lint on nightly

```
changelog: ICE: [`tuple_array_conversions`]: Don't expect array length to always be usize
```

tl;dr: changed [`Const::eval_target_usize`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/consts.rs#L359) to [`Consts::try_eval_target_usize`](https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/consts.rs#L327) to get rid of ICE.

I have encountered a problem with clippy: it caught ICE when working with a codebase that uses a lot of nightly features.
Here's a (stripped) ICE info:

```
error: internal compiler error: /rustc/5c6a7e71cd66705c31c9af94077901a220f0870c/compiler/rustc_middle/src/ty/consts.rs:361:32: expected usize, got Const { ty: usize, kind: N/#1 }

thread 'rustc' panicked at /rustc/5c6a7e71cd66705c31c9af94077901a220f0870c/compiler/rustc_errors/src/lib.rs:1635:9:
Box<dyn Any>
stack backtrace:
...
  16:        0x110b9c590 - rustc_middle[449edf845976488d]::util:🐛:bug_fmt
  17:        0x102f76ae0 - clippy_lints[71754038dd04c2d2]::tuple_array_conversions::all_bindings_are_for_conv
...
```

I don't really know what's going on low-level-wise, but seems like this lin assumed that the length of the array can always be treated as `usize`, and *I assume* this doesn't play well with `feat(generic_const_exprs)`.

I wasn't able to build a minimal reproducible example, but locally this fix does resolve the issue.
2023-08-23 07:20:41 +00:00
Igor Aleksanov
f0eaa66263 Add a test for tuple_array_conversion 2023-08-23 09:54:50 +04:00
Esteban Küber
32eecd4b88 Fix clippy lint for identical if/else contraining ? expressions
Follow up to #114819.
2023-08-23 00:58:09 +00:00
Red Rapious
7977d209b2 Do not lint inside macros 2023-08-22 19:36:58 +02:00
Red Rapious
df8bb47f17 Improved snippets and added tests 2023-08-22 18:46:16 +02:00
Guillaume Gomez
f4670121d5 Move code comments to prevent having weird clippy fmt issues 2023-08-22 17:18:12 +02:00
Guillaume Gomez
a05d3a4137 Automatic generation of error annotations for ui tests 2023-08-22 17:18:11 +02:00
Guillaume Gomez
3a31c05578 Remove/move comments to prevent weird rustfmt wrapping 2023-08-22 17:17:48 +02:00
Guillaume Gomez
9c96605b20 Manually add annotations for ui tests 2023-08-22 17:14:08 +02:00
Jason Newcomb
82f2e52469 Fix span when linting explicit_auto_deref immediately after needless_borrow 2023-08-21 22:34:32 -04:00
J-ZhengLi
77215672e9 fix [undocumented_unsafe_blocks] not able to detect comment for global vars 2023-08-22 10:27:16 +08:00
Red Rapious
b0bd6219c8 Simplified code and added tests 2023-08-21 23:36:15 +02:00
Red Rapious
7fbf808a50 Added new lint: reserve_after_initialization 2023-08-21 18:50:53 +02:00
bors
fc1152abf6 Auto merge of #11359 - Alexendoo:unwrap-or-default-check-suggestion, r=dswij
Check that the suggested method exists in unwrap_or_default

Fixes #11355

changelog: none
2023-08-20 15:26:33 +00:00
Alex Macleod
8f2d47ea72 Check that the suggested method exists in unwrap_or_default 2023-08-19 20:22:45 +00:00
lengyijun
e440065a0f [iter_overeager_cloned]: detect .cloned().map() and .cloned().for_each()
key idea:
for `f` in `.map(f)` and `.for_each(f)`:
1. `f` must be a closure with one parameter
2. don't lint if mutable paramter in clsure `f`: `|mut x| ...`
3. don't lint if parameter is moved
2023-08-19 21:18:14 +08:00
y21
e52bd6f850 new lint: should_panic_without_expect 2023-08-18 18:57:14 +02:00
bors
1698ce0ba1 Auto merge of #11280 - samueltardieu:issue-11267, r=Centri3
[new_without_default]: include `where` clause in suggestions, make applicable

changelog: [`new_without_default`]: include `where` clause in suggestions
2023-08-18 15:55:40 +00:00
bors
5638860ff8 Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT

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

The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables.

cc `@Centri3`

changelog: none
2023-08-17 18:06:36 +02:00
bors
d068043891 Auto merge of #11070 - y21:issue11065, r=flip1995
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099).
It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17 18:06:36 +02:00
bors
d5298bea7f Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r=Centri3
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT

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

The problem was that the `async block`s are popping a closure which we didn't go into, making it miss the mutable access to the variables.

cc `@Centri3`

changelog: none
2023-08-17 15:55:23 +00:00
bors
701e77c87f Auto merge of #11070 - y21:issue11065, r=flip1995
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro

Fixes #11065 (which is actually two issues: an ICE and a false positive)

It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099).
It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore)

changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item
changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP)

r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17 14:41:46 +00:00
Guillaume Gomez
7e46217362 Add new regression test for needless_pass_by_ref_mut 2023-08-17 14:24:04 +02:00
bors
710db18ccd Auto merge of #11336 - Alexendoo:uitest-backslash, r=flip1995
Use ui_test's Windows path backslash heuristic

changelog: none

Instead of unconditionally replacing `\` with `/` we now use [`Match::PathBackslash`](https://docs.rs/ui_test/latest/ui_test/enum.Match.html#variant.PathBackslash) to only replace backslashes in paths that look like windows paths

`ui-toml` and `ui-cargo` tests still use the old way because they produce verbatim paths on windows in some tests (`\\?\C:\foo\...`) which was finnicky to get the replacement order correct with

Also removes the `ui_test` -> `compiletest` alias and `VarGuard`
2023-08-15 15:22:29 +00:00
J-ZhengLi
aa8995e589 allow calling to_owned with borrowed value for [implicit_clone] 2023-08-15 09:41:15 +08:00
Esteban Küber
d0a26f1c9c bless clippy test 2023-08-14 22:00:46 +00:00
y21
f746e19169 allow trait alias DefIds in implements_trait_with_env_from_iter 2023-08-14 19:10:33 +02:00
Alex Macleod
77d10ac63d Use ui_test's Windows path backslash heuristic 2023-08-14 15:59:00 +00:00
y21
f47165c703 find expansions more efficiently 2023-08-14 16:50:31 +02:00
y21
2820d980cb [useless_conversion]: fix FP in macro and add test 2023-08-14 16:28:04 +02:00
lengyijun
fc061890d6 [iter_overeager_cloned]: detect .cloned().filter() and .cloned().find()
Key idea:
```
// before
iter.cloned().filter(|x| unimplemented!() )
// after
iter.filter(|&x| unimplemented!() ).cloned()

// before
iter.cloned().filter( foo )
// after
iter.filter(|&x| foo(x) ).cloned()
```
2023-08-14 09:13:01 +08:00
bors
344ae115db Auto merge of #11329 - unvalley:lint-binary-heap-retain, r=Alexendoo
[`manual_retain`]: add lint case for `binary_heap`

Closes #9059

This PR adds changes to perform linting on the `binary_heap` as well, under the [manual_retain rule](https://rust-lang.github.io/rust-clippy/master/index.html#/manual_retain).

changelog: [manual_retain]: update for lint `binary_heap`
2023-08-13 14:45:01 +00:00
unvalley
1eff39ddb6 fix: change msrv to 1.69 for binary heap 2023-08-13 22:52:06 +09:00
Alex Macleod
3ac06a12a5 Do not bless by default in ui tests 2023-08-13 13:25:48 +00:00
unvalley
d5dbee4aa0 feat: update manual_retain to lint binary_heap_retain
refactor: rename variable

chore: reorder

test: update naming for msrv
2023-08-13 17:09:39 +09:00
Samuel Tardieu
f9b22e7b84 [new_without_default]: make the suggestion machine-applicable
Now that generics and lifetimes are output as expected, the lint
should be applicable.
2023-08-11 21:16:56 +02:00
Samuel Tardieu
621e76d252 [new_without_default]: include where clauses in suggestion
Fix #11267
2023-08-11 21:10:18 +02:00
Samuel Tardieu
7a06d7ec51 [new_without_default]: lifetimes are included in output
The comment was likely obsolete.
2023-08-11 21:10:18 +02:00
bors
75370e0671 Auto merge of #11325 - oli-obk:SPEEDTEST, r=flip1995
Fix SPEEDTEST instructions and output

* `--nocapture` hasn't been needed anymore since forever (even before `ui_test`)
* the result was dividing by 1000 instead of the number of test runs, giving bogus (but still useful for the purpose) timing results.

changelog: fix SPEEDTEST instructions and output
2023-08-11 15:30:38 +00:00
Oli Scherer
cd8f12dd36 Show correct measurements in SPEEDTEST 2023-08-11 15:22:23 +00:00
Oli Scherer
665a61938d Bump ui_test 2023-08-11 15:08:48 +00:00
Oli Scherer
43f04e12ad Bump ui_test crate 2023-08-11 14:03:06 +00:00
Oli Scherer
1088507a30 Canonicalize paths in a single location 2023-08-11 14:02:52 +00:00
Oli Scherer
00919a4f92 Update ui test crate to auto-detect aux build crate kind 2023-08-11 14:02:35 +00:00
Oli Scherer
3d88fae050 Update ui test crate 2023-08-11 14:02:28 +00:00
Oli Scherer
0afd38b093 Make a panic message more informative if binary files are accidentally created somewhere in the test folder 2023-08-11 14:01:53 +00:00
Oli Scherer
4c779da913 Remove some leftover cruft from compiletest-rs 2023-08-11 13:59:54 +00:00
Philipp Krones
f730a2655a Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyup 2023-08-11 14:05:13 +02:00
bors
1e8fdf4928 Auto merge of #11320 - max-niederman:redundant_locals_shadow_mutated, r=Alexendoo
redundant_locals: fix FPs on mutated shadows

Fixes #11290.

When a mutable binding is shadowed by
a mutable binding of the same name in a different scope, mutations in that scope have different meaning.
This PR fixes spurious `redundant_locals` emissions on such locals.

cc `@Centri3,` `@flip1995`

changelog: [`redundant_locals`]: fix false positives on mutated shadows
2023-08-11 10:58:13 +00:00
bors
8703661a9a Auto merge of #11316 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

cc `@max-niederman` With the latest sync, I'm getting a lot of FP in the `redundant_locals` lint you recently added. Any ideas where this could come from?

changelog: none
2023-08-11 08:54:35 +00:00
Philipp Krones
3927677234
Dogfood and bless tests 2023-08-11 10:53:18 +02:00
Max Niederman
a5f62bdfcd
redundant_locals: fix FPs on mutated shadows
When a mutable binding is shadowed by
a mutable binding of the same name in a different scope,
mutations in that scope have different meaning.
This commit fixes spurious `redundant_locals` emissions
on such locals.
2023-08-10 19:53:45 -07:00
Catherine Flores
1ec0501bca Revert "New lint [filter_map_bool_then]"
This reverts commits 978b1daf99 and 3235d9d612.
2023-08-10 17:28:01 -05:00
Catherine Flores
7b2fd81f43 Add test for &mut 2023-08-10 16:33:07 -05:00
Catherine Flores
beb57f074e Don't ICE with late bound regions 2023-08-10 16:26:22 -05:00
Philipp Krones
17b9c42572
Merge remote-tracking branch 'upstream/master' into rustup 2023-08-10 21:15:24 +02:00
Guillaume Gomez
1d01f1bac1 Update UI test for async blocks for NEEDLESS_PASS_BY_REF_MUT 2023-08-10 16:23:27 +02:00
bors
7c595b4599 Auto merge of #11305 - y21:issue11304, r=Centri3
[`redundant_guards`]: don't lint on float literals

Fixes #11304

changelog: [`redundant_guards`]: don't lint on float literals

r? `@Centri3` i figured you are probably a good reviewer for this since you implemented the lint ^^
2023-08-08 16:18:06 +00:00
y21
b6156502af document the new behavior and add test for float in struct 2023-08-08 18:04:57 +02:00
y21
f959ccc09b [redundant_guards]: don't lint on floats 2023-08-08 17:19:53 +02:00
bors
526d1156bd Auto merge of #11191 - Alexendoo:redundant-type-annotations-ice, r=llogiq
redundant_type_annotations: only pass certain def kinds to type_of

Fixes #11190
Fixes rust-lang/rust#113516

Also adds an `is_lint_allowed` check to skip the lint when it's not needed

changelog: none
2023-08-06 18:45:38 +00:00
Morten Lohne
1d61fc1b0a Rename 'impossible_double_const_comparisons' -> 'impossible_comparisons' and 'ineffective_double_const_comparisons' -> 'redundant_comparisons', after discussion on Zulip 2023-08-05 21:28:08 +02:00
Morten Lohne
8f40d09e0f Add tests for const comparisons that compare two different types 2023-08-05 21:28:08 +02:00
Morten Lohne
046d3df35e New lints: impossible_double_const_comparisons and ineffective_double_const_comparisons 2023-08-05 21:28:08 +02:00
bors
d412b91fd1 Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk
Add `internal_features` lint

Implements https://github.com/rust-lang/compiler-team/issues/596

Also requires some more test blessing for codegen tests etc

`@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
2023-08-03 22:58:02 +00:00
bors
5818225a89 Auto merge of #11255 - blyxyas:fix-perf-sus_xor_used_as_pow, r=xFrednet
Fix `suspicious_xor_used_as_pow.rs` performance

The original `suspicious_xor_used_as_pow` lint had poor performance, so I fixed that + a little refactor so that module is readable.

**107 millis. -> 106 millis.** Using `SPEEDTEST` on Rust's VMs

fix #11060
changelog: [`suspicious_xor_used_as_pow`]: Improve performance by 0.934%
2023-08-03 20:07:54 +00:00
blyxyas
3fb84415cd
Fix suspicious_xor_used_as_pow.rs performance 2023-08-03 21:58:59 +02:00
Nilstrieb
85b5e98ea2 Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
bors
1eb254ef83 Auto merge of #11242 - samueltardieu:issue-11238, r=Centri3,giraffate
New lint `ignored_unit_patterns`

This idea comes from #11238. I've put the lint in `pedantic` as it might trigger numerous positives (three in Clippy itself).

changelog: [`ignored_unit_patterns`]: new lint
2023-08-03 01:04:39 +00:00
bors
237dd599db Auto merge of #11288 - Centri3:#11278, r=Alexendoo
[`ptr_as_ptr`]: Take snippet instead of pretty printing type

Fixes #11278

changelog: [`ptr_as_ptr`]: Include leading `super`s in suggestion
2023-08-02 22:32:35 +00:00
Catherine Flores
fef85c9083 Take snippet instead of pretty printing type 2023-08-02 17:26:25 -05:00
bors
97d1cfa2b4 Auto merge of #11286 - Centri3:#11283, r=Alexendoo
Suppress `question_mark` warning if `question_mark_used` is not allowed

Closes #11283

changelog: [`question_mark`]: Don't lint if `question_mark_used` is not allowed
2023-08-02 22:20:30 +00:00
Catherine Flores
4d49065a6c Suppress question_mark if question_mark_used is not allowed 2023-08-02 14:13:16 -05:00
Catherine Flores
71c54137ea Extract never-like into clippy_utils 2023-08-02 14:00:26 -05:00
Catherine Flores
779e0f4021 Do not lint unwrapping on ! or never-like enums 2023-08-02 14:00:12 -05:00
Urgau
7ef1a54ffe Rename incorrect_fn_null_checks to useless_ptr_null_checks (clippy side) 2023-08-01 20:04:01 +02:00
bors
588c1abb76 Auto merge of #11269 - y21:issue11268, r=Centri3
[`unnecessary_mut_passed`]: don't lint in macro expansions

Fixes #11268

changelog: [`unnecessary_mut_passed`]: don't lint in macro expansions
2023-08-01 05:15:09 +00:00
Philipp Krones
b0e64a9c09 Merge commit '5436dba826191964ac1d0dab534b7eb6d4c878f6' into clippyup 2023-07-31 23:53:53 +02:00
Samuel "Sam" Tardieu
f9a6dfa60d New lint ignored_unit_patterns 2023-07-31 22:00:53 +02:00
y21
dc1e8b0dd9 [unnecessary_mut_passed]: don't lint in macro expansions 2023-07-31 21:09:52 +02:00
bors
5436dba826 Auto merge of #11263 - c410-f3r:let-chain, r=Centri3
[`arithmetic_side_effects`] Fix #11262

Fix #11262

Rustc already handles paths that refer literals -> https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d795058a2e1634c867288c20ff9432c8

```
changelog: [`arithmetic_side_effects`]: Ignore paths that refer literals
```
2023-07-30 20:16:57 +00:00
bors
2ab124126d Auto merge of #11261 - y21:issue11260, r=blyxyas
[`unnecessary_find_map`]: look for then_some

Closes #11260

changelog: [`unnecessary_find_map`]: lint `.then_some()` in closure
2023-07-30 18:26:45 +00:00
Caio
35d434d08e [arithmetic_side_effects] Fix #11262 2023-07-30 14:33:38 -03:00
y21
be6a103c8c add more tests to unnecessary_find_map and unnecessary_filter_map 2023-07-30 16:52:53 +02:00
Matthias Krüger
f54263af58 Rollup merge of #112655 - WaffleLapkin:must_use_map_or, r=workingjubilee
Mark `map_or` as `#[must_use]`

I don't know what else to say.

r? libs
2023-07-30 14:25:08 +02:00
y21
008746cae4 [unnecessary_find_map]: look for then_some 2023-07-30 13:51:35 +02:00
Maybe Waffle
0c93e30956 Mark map_or as #[must_use] 2023-07-30 10:22:23 +00:00
Jason Newcomb
8277e7d154 Don't pass extra generic arguments in needless_borrow 2023-07-30 03:47:42 -04:00
Jason Newcomb
caf601434b Resolve type aliases in type_certainty 2023-07-30 03:26:32 -04:00
Jason Newcomb
4d80a2ed2e Rework redundant_closure
* Better track when a early-bound region appears when a late-bound region is required
* Don't lint when the closure gives explicit types.
2023-07-30 01:19:29 -04:00
bors
436060f637 Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstrieb
Rename and allow `cast_ref_to_mut` lint

This PR is a small subset of https://github.com/rust-lang/rust/pull/112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`).

BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until https://github.com/rust-lang/rust/pull/112431 is merged.

r? `@Nilstrieb`
2023-07-29 07:48:44 +00:00
bors
0c0026e380 Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, r=compiler-errors
make `noop_method_call` warn by default

r? `@compiler-errors`
2023-07-29 01:40:50 +00:00
Philipp Krones
3d60241841
Merge remote-tracking branch 'upstream/master' into rustup 2023-07-28 23:44:28 +02:00
bors
d3c5b488db Auto merge of #11210 - y21:readonly_write_lock, r=giraffate
new lint: [`readonly_write_lock`]

Closes #8555

A new lint that catches `RwLock::write` calls to acquire a write lock only to read from it and not actually do any writes (mutations).

changelog: new lint: [`readonly_write_lock`]
2023-07-28 13:08:02 +00:00
bors
e97a770bf1 Auto merge of #114134 - fee1-dead-contrib:rm-constness-from-param-env, r=oli-obk
Remove `constness` from `ParamEnv`

This should be replaced by keyword generics/effects. cc #110395

r? `@oli-obk`
2023-07-28 08:53:12 +00:00
bors
295bdc028f Auto merge of #10759 - blyxyas:unset_opt_env_unwrap, r=flip1995
Now `option_env_unwrap` warns even if a variable isn't set at compiletime

Fixes #10742
changelog: Fix false negative where `option_env_unwrap` wouldn't warn if the env variable isn't set at compile-time.
2023-07-27 19:52:46 +00:00
y21
136339f2d3 new lint: [readonly_write_lock] 2023-07-27 21:19:35 +02:00
Deadbeef
39fb315396 bless clippy 2023-07-27 17:56:25 +00:00
blyxyas
3bfccacca9
Add comments + Very minor Refactor 2023-07-26 23:16:24 +02:00
Trevor Gross
6ca6be6f2b Unite bless environment variables under RUSTC_BLESS
Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to
indicate that output should be blessed, but they use different variable names.
In order to improve consistency, this patch applies the following changes:

- Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always
  available
- Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS`
- Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS`
- Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS`
- Adjust the blessable test in `rustc_errors` to use this same
  convention
- Update documentation where applicable

Any tools that uses `RUSTC_BLESS` should check that it is set to any value
other than `"0"`.
2023-07-26 16:54:02 -04:00
blyxyas
4e1db44404
Now option_env_unwrap warns even if a variable isn't set at compile time. 2023-07-26 18:57:57 +02:00
Matthias Krüger
01b9f9d9da ci: test that we fail CI if we don't find clippy panicking 2023-07-26 17:05:20 +02:00
bors
fc13bf8be2 Auto merge of #11225 - matthiaskrgr:fix_integration_tests2, r=flip1995
Fix integration tests #2

fix integration tests.

It turned out that the following tests fail to build at all:

chalk, combine, stdarch and hyper.

This is often a problem of passing `--all-targets --all-features`, in case of combine though, outdated deps were to blame.

I have opened tickets against combine and rustfmt
https://github.com/rust-lang/rustfmt/issues/5859
https://github.com/Marwes/combine/issues/357

should we just remove the other failing repos? :/

changelog: fix integration tests on ci
2023-07-26 08:55:48 +00:00
bors
0d0dbae550 Auto merge of #11233 - Centri3:#11232, r=Jarcho
[`arc_with_non_send_sync`]: No longer lints macro-generated code

Fixes #11232

changelog: [`arc_with_non_send_sync`]: No longer lints macro-generated code
2023-07-26 03:26:10 +00:00
Catherine Flores
90947e95ad [arc_with_non_send_sync]: Check if it's macro-generated 2023-07-25 18:09:59 -05:00
Catherine
3235d9d612 Only lint Copy types 2023-07-25 17:51:05 -05:00
Catherine
978b1daf99 New lint [filter_map_bool_then] 2023-07-25 17:42:36 -05:00
bors
2153c0fcc8 Auto merge of #11226 - GuillaumeGomez:needless-ref-mut-cfg, r=llogiq
Needless ref mut cfg

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

cc `@Centri3`

changelog: Emit note if function is behind a cfg for `NEEDLESS_PASS_BY_REF_MUT` lint.
2023-07-25 19:00:59 +00:00
Matthias Krüger
12b63f5c35 ci: integration tests: print clippy run output and set LD_LIBRARY_PATH to rustc sysroot 2023-07-25 19:39:50 +02:00
bors
70c5798993 Auto merge of #11198 - y21:issue10938, r=Centri3
[`slow_vector_initialization`]: catch `Vec::new()` followed by `.resize(len, 0)`

Closes #10938

changelog: [`slow_vector_initialization`]: catch `Vec::new()` followed by `.resize(len, 0)`
2023-07-25 17:23:01 +00:00
Guillaume Gomez
04b710b569 Use libtest errors check to better enforce UI testing 2023-07-25 18:43:58 +02:00
Guillaume Gomez
15de3dd2af Add a note if the function is behind a cfg 2023-07-25 18:08:16 +02:00
Ralf Jung
2b16c37b65 bless more 2023-07-25 14:30:58 +02:00
bors
d09c8a9387 Auto merge of #11221 - Alexendoo:ui-test-text, r=flip1995
Remove Gha status emitter in compile-test

Disables the github specific output for now since it can be a bit confusing - https://github.com/oli-obk/ui_test/issues/109, in particular the truncation/repetition

r? `@flip1995`

changelog: none
2023-07-25 08:29:27 +00:00
Catherine Flores
ef482d17f2 Do not lint if used as a fn-like argument 2023-07-24 19:29:23 -05:00
bors
867e0ec024 Auto merge of #11218 - MrNossiom:master, r=Manishearth
changelog: [`min_ident_chars`]: don't lint const generics

Fixes: #11163

changelog: [`min_ident_chars`]: don't lint const generics
2023-07-24 21:26:56 +00:00
Alex Macleod
5c26e82d80 Remove Gha status emitter in compile-test 2023-07-24 18:29:11 +00:00
bors
31f37693e9 Auto merge of #11031 - Centri3:needless_return, r=giraffate
New lint [`needless_return_with_try`]

Closes #10902

Rather than having a config option, this will just suggest removing the "return"; if `try_err` is used as well, then it'll be added again but without the `?`.

changelog: New lint [`needless_return_with_try`]
2023-07-24 13:17:50 +00:00
Milo Moisson
82982133a9
changelog: [min_ident_chars]: don't lint const generics 2023-07-24 14:59:27 +02:00
bors
a447725394 Auto merge of #11215 - MrNossiom:master, r=Jarcho
ptr_arg should ignore extern functions

Fixes: #11181

changelog: [`ptr_arg`]: ignore extern functions that are not

I am not sure whether we should ignore other Rust calling conventions like `rust-intrinsic`, `rust-call` or `rust-cold`.
2023-07-24 00:01:48 +00:00
bors
e4923c21c8 Auto merge of #10120 - smoelius:or_insert_with, r=blyxyas
`unwrap_or_else_default` -> `unwrap_or_default` and improve resulting lint

Resolves #10080 (though it doesn't implement exactly what's described there)

This PR does the following:
1. Merges `unwrap_or_else_default.rs`'s code into `or_fun_call.rs`
2. Extracts the code to handle `unwrap_or(/* default value */)` and similar, and moves it into `unwrap_or_else_default`
3. Implements the missing functionality from #9342, e.g.,, to handle `or_insert_with(Default::default)`
4. Renames `unwrap_or_else_default` to `unwrap_or_default` (since the "new" lint handles both `unwrap_or` and `unwrap_or_else`, it seemed sensible to use the shortened name)

This PR is currently two commits. The first implements 1-3, the second implements 4.

A word about 2: the `or_fun_call` lint currently produces warnings like the following:
```
error: use of `unwrap_or` followed by a call to `new`
  --> $DIR/or_fun_call.rs:56:14
   |
LL |     with_new.unwrap_or(Vec::new());
   |              ^^^^^^^^^^^^^^^^^^^^^ help: try: `unwrap_or_default()`
```
To me, such warnings look like they should come from `unwrap_or_else_default`, not `or_fun_call`, especially since `or_fun_call` is [in the nursery](https://github.com/rust-lang/rust-clippy/pull/9829).

---

changelog: Move: Renamed `unwrap_or_else_default` to [`unwrap_or_default`]
[#10120](https://github.com/rust-lang/rust-clippy/pull/10120)
changelog: Enhancement: [`unwrap_or_default`]: Now handles more functions, like `or_insert_with`
[#10120](https://github.com/rust-lang/rust-clippy/pull/10120)
<!-- changelog_checked-->
2023-07-23 20:28:07 +00:00
bors
58775046a9 Auto merge of #11214 - y21:issue11213, r=Jarcho
check that the types are equal in `SpanlessEq::eq_expr`

Fixes #11213

changelog: [`if_same_then_else`]: don't lint for integer literals of different types
2023-07-23 20:00:31 +00:00
Milo Moisson
30d06a810c
ptr_arg should ignore extern functions 2023-07-23 17:10:13 +02:00
y21
e975d05cde check that the types are equal in SpanlessEq::eq_expr 2023-07-23 15:51:11 +02:00
Deadbeef
1662fdb2d0 fix 2023-07-23 09:58:31 +00:00
bors
43577d58f9 Auto merge of #11184 - GuillaumeGomez:needless_pass_by_ref_mut-async, r=llogiq
Fix async functions handling for `needless_pass_by_ref_mut` lint

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

The problem with async is that "internals" are actually inside a closure from the `ExprUseVisitor` point of view, meaning we need to actually run the check on the closures' body as well.

changelog: none

r? `@llogiq`
2023-07-23 07:21:05 +00:00
bors
356768b317 Auto merge of #11029 - Centri3:empty_slice, r=Jarcho
Make `comparison_to_empty` work on `if let`/`let` chains

This adds `LetChain` to `clippy_utils::higher`, other lints may benefit from such a change as well :D

changelog: Enhancement: [`comparison_to_empty`]: Now lints on `if let`
2023-07-23 05:10:32 +00:00
bors
e8403a892b Auto merge of #11200 - y21:issue9695, r=Jarcho
[`unused_async`]: don't lint if paths reference async fn without immediate call

Fixes #9695
Fixes #9359

Clippy shouldn't lint unused `async` if there are paths referencing them if that path isn't the receiver of a function call, because that means that the function might be passed to some other function:
```rs
async fn f() {} // No await statements, so unused at this point

fn requires_fn_future<F: Future<Output = ()>>(_: fn() -> F) {}
requires_fn_future(f); // `f`'s asyncness is actually not unused.
```
(This isn't limited to just passing the function as a parameter to another function, it could also first be stored in a variable and later passed to another function as an argument)

This requires delaying the linting until post-crate and collecting path references to local async functions along the way.

changelog: [`unused_async`]: don't lint if paths reference async fn that require asyncness
2023-07-22 20:40:48 +00:00
bors
ea21ed7f10 Auto merge of #11196 - c410-f3r:let-chain, r=xFrednet
[significant_drop_tightening] Fix #11189

Fix #11189

```
changelog: FP: [`significant_drop_tightening`]: Consider tuples in drop calls
```
2023-07-22 20:14:57 +00:00
y21
482d5fafc9 replace HashMap with Vec, use span_lint_hir_and_then 2023-07-22 14:33:36 +02:00
Centri3
51b57723d1 new lint redundant_guards 2023-07-22 06:28:05 -05:00
Catherine
da93ee86e5 Make comparison_to_empty work on if let/let chains
refactor it
2023-07-22 05:59:01 -05:00
Max Niederman
008ba2b8bb
new lint: redundant_local
fix dogfood lints in `redundant_local`

keep `redundant_local` from running in proc macros

rewrite `redundant_local` as late pass

make redundant_local's `find_binding` more readable

pluralize `redundant_locals` name

add test for `redundant_locals` in macros

test `redundant_locals` in proc macros

use more destructuring in `redundant_locals`

fix: format redundant_locals.rs

ignore needless_pass_by_mut_ref in redundant_locals test
2023-07-21 18:14:03 -07:00
Catherine
9cf1509b25 New lint absolute_paths 2023-07-21 17:26:58 -05:00
bors
d2c9047a92 Auto merge of #11205 - Centri3:#11201, r=Manishearth
[`inherent_to_string`]: Don't lint `unsafe` or `extern` fns

Fixes #11201

changelog: [`inherent_to_string`]: No longer lints `unsafe` or `extern` fns
2023-07-21 15:01:04 +00:00
Catherine Flores
f3f7f63c16 [inherent_to_string]: Don't lint unsafe or extern fns 2023-07-21 06:45:30 -05:00