Commit Graph

20813 Commits

Author SHA1 Message Date
bors
753629bb33 Auto merge of #13412 - GnomedDev:regex-comp-in-loop, r=y21
Implement lint for regex::Regex compilation inside a loop

Closes #598.

Seems like a pretty simple one, I'm not sure if I sorted out all the lint plumbing correctly because I was adding it to the existing regex pass, but seems to work. The name is a bit jank and I'm super open to suggestions for changing it.

changelog: [`regex_creation_in_loops`]: Added lint for Regex compilation inside loops.
2024-10-05 18:41:45 +00:00
bors
f173eb3aef Auto merge of #13505 - samueltardieu:lintcheck-bump-futures, r=y21
lintcheck: bump futures* crates to 0.3.31

changelog: none
2024-10-05 18:21:17 +00:00
Samuel Tardieu
9dd6820edd lintcheck: bump futures* crates to 0.3.31
Version 0.3.30 doesn't compile with our nightly version.
2024-10-05 19:04:45 +02:00
GnomedDev
196dbcf6d5
Avoid linting for Regexes compiled in items defined in loops 2024-10-05 17:10:21 +01:00
bors
a01975b152 Auto merge of #13493 - y21:trait_duplication_in_bounds_fix, r=Manishearth
Compare trait references in `trait_duplication_in_bounds` correctly

Fixes #13476
Fixes #11067
Fixes #9915
Fixes #9626

Currently, the `trait_duplication_in_bounds` lints has a helper type for a trait reference that can be used for comparison and hashing, represented as `{trait: Res, generic_args: Vec<Res>}`. However, there are a lot of issues with this. For one, a `Res` can't represent e.g. references, slices, or lots of other types, as well as const generics and associated type equality. In those cases, the lint simply ignores them and has no way of checking if they're actually the same.

So, instead of using `Res` for this, use `SpanlessEq` and `SpanlessHash` for comparisons with the trait path for checking if there are duplicates.

However, using `SpanlessEq` as is alone lead to a false negative in the test. `std::clone::Clone` + `foo::Clone` wasn't recognized as a duplicate, because it has different segments. So this also adds a new "mode" to SpanlessEq which compares by final resolution. (I've been wondering if this can't just be the default but it's quite a large scale change as it affects a lot of lints and I haven't yet looked at all uses of it to see if there are lints that really do care about having exactly the same path segments).

Maybe an alternative would be to turn the hir types/consts into middle types/consts and compare them instead but I'm not sure there's really a good way to do that

changelog: none
2024-10-03 21:16:22 +00:00
y21
d6be597fbc Use SpanlessEq for in trait_bounds lints 2024-10-03 15:49:37 +00:00
bors
aa0d551351 Auto merge of #13492 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2024-10-03 13:34:02 +00:00
Philipp Krones
c994a60fd4
Bump nightly version -> 2024-10-03 2024-10-03 14:48:03 +02:00
Philipp Krones
d300cdfcda
Merge remote-tracking branch 'upstream/master' into rustup 2024-10-03 14:47:50 +02:00
bors
398be8c842 Auto merge of #13443 - SpriteOvO:simplify-option-neg-methods, r=xFrednet
Simplify negative `Option::{is_some_and,is_none_or}`

Closes #13436.

Improved based on the existing lint `nonminimal_bool`, since there is already handling of similar methods `Option::{is_some,is_none}` and `Result::{is_ok,is_err}`, and there is a lot of reusable code.

When `is_some_and` or `is_none_or` have a negation, we invert it into another method by removing the Not sign and inverting the expression in the closure.

For the case where the closure block has statements, currently no simplification is implemented. (Should we do it?)

```rust
// Currently will not simplify this
_ = !opt.is_some_and(|x| {
    let complex_block = 100;
    x == complex_block
});
```

changelog: [`nonminimal_bool`]: Simplify negative `Option::{is_some_and,is_none_or}`
2024-10-02 08:54:12 +00:00
bors
d578f6ab0c Auto merge of #13122 - rshearman:fix-9854, r=blyxyas
Fix `mut_mutex_lock` when reference not ultimately mutable

When there is are multiple references where one of the references isn't mutable then this results in a false-positive for `mut_mutex_lock` as it only checks the mutability of the first reference level.

Fix this by using `peel_mid_ty_refs_is_mutable` which correctly determines whether the reference is ultimately mutable and thus whether `Mutex::get_lock()` can actually be used.

Fixes #9854

changelog: [`mut_mutex_lock`]: No longer lints if the mutex is behind multiple references and one of those references isn't mutable
2024-10-01 21:02:31 +00:00
Rob Shearman
c88cb08afc Fix mut_mutex_lock when reference not ultimately mutable
When there is are multiple references where one of the references
isn't mutable then this results in a false-positive for
`mut_mutex_lock` as it only checks the mutability of the first
reference level.

Fix this by using `peel_mid_ty_refs_is_mutable` which correctly
determines whether the reference is ultimately mutable and thus
whether `Mutex::get_lock()` can actually be used.

Fixes #9854
2024-10-01 22:19:42 +02:00
Ralf Jung
4891dd4627 make InterpResult a dedicated type to avoid accidentally discarding the error 2024-10-01 21:45:35 +02:00
bors
71c7d445db Auto merge of #13462 - y21:issue13459, r=dswij
`zombie_processes`: consider `wait()` calls in nested bodies

Fixes #13459

Small oversight. We weren't considering uses of the local in closures.

changelog: none
2024-10-01 17:39:32 +00:00
y21
f06a46ee4d consider wait() calls in nested bodies 2024-10-01 19:21:30 +02:00
bors
db1bda3df1 Auto merge of #13286 - smoelius:elidable-impl-lifetimes, r=Alexendoo
Extend `needless_lifetimes` to suggest eliding `impl` lifetimes

Example:
```
error: the following explicit lifetimes could be elided: 'a
  --> tests/ui/needless_lifetimes.rs:332:10
   |
LL |     impl<'a> Foo for Baz<'a> {}
   |          ^^              ^^
   |
help: elide the lifetimes
   |
LL -     impl<'a> Foo for Baz<'a> {}
LL +     impl Foo for Baz<'_> {}
```
The main change is in how `impl` lifetime uses are tracked. Previously, a hashmap was created, and lifetimes were removed from the hashmap as their uses were discovered. However, the uses are needed to generate elision suggestions. So, now, uses are added to the hashmap as they are discovered.

The PR is currently organized as six commits, which I think are self-explanatory:
- Extend `needless_lifetimes` to suggest eliding `impl` lifetimes
- Reorder functions _[not strictly necessary, but IMHO, the code is better structured as a result]_
- Fix lifetime tests
- Fix non-lifetime tests
- Fix `clippy_lints` and `clippy_utils`
- Fix typo in `needless_lifetimes` test

r? `@Alexendoo` (I think you are `needless_lifetimes`' primary author? Sorry if I have this wrong.)

---

changelog: Extend `needless_lifetimes` to suggest eliding `impl` lifetimes
2024-10-01 00:41:21 +00:00
Samuel Moelius
54e4761d05 Address review comment
https://github.com/rust-lang/rust-clippy/pull/13286#discussion_r1780038602
2024-09-29 18:21:47 -04:00
bors
061004aa01 Auto merge of #13469 - nyurik:apply-ref-option, r=llogiq
Convert `&Option<T>` to `Option<&T>`

Run `ref_option` (#13336) on the Clippy's own code, quiet a few hits. Per mentioned video, this may actually improve performance as well.  Switch lint to `pedantic`

----

changelog: [`ref_option`]: upgrade lint to `pedantic`
2024-09-29 21:34:13 +00:00
Asuna
762a91b40e Simplify negative Option::{is_some_and,is_none_or} 2024-09-30 03:36:41 +08:00
Yuri Astrakhan
f7d5d9d892 Convert &Option<T> to Option<&T> 2024-09-28 19:51:02 -04:00
Samuel Moelius
b3cf448761 Adjust comment 2024-09-28 16:30:31 -04:00
bors
7b566c214e Auto merge of #13336 - nyurik:ref-option-sig, r=llogiq
Suggest `Option<&T>` instead of `&Option<T>`

closes #13054

```rust
// bad code
fn foo(a: &Option<T>) {}
fn bar(&self) -> &Option<T> {}

// Use instead
fn foo(a: Option<&T>) {}
fn bar(&self) -> Option<&T> {}
```

Handles argument types and return types in functions, methods, and closures with explicit types.  Honors `avoid_breaking_exported_api` parameter.

See this great [YouTube video](https://www.youtube.com/watch?v=6c7pZYP_iIE) with the in-depth explanation.

### Open Questions
These are not blocking, and could be done in separate PRs if needed.
* [ ] Should `&Option<Box<T>>` be suggested as `Option<&T>` -- without the box?  Handled by [clippy::borrowed_box](https://rust-lang.github.io/rust-clippy/master/index.html#/borrowed_box)
* [ ] Should `&Option<String>` be suggested as `Option<&str>` -- using de-refed type?

### Possible Future Improvements
These cases might also be good to handle, probably in a separate PR.

```rust
fn lambdas() {
  let x = |a: &Option<String>| {};
  let x = |a: &Option<String>| -> &Option<String> { todo!() };
}

fn mut_ref_to_ref(a: &mut &Option<u8>) {}
```

changelog: [`ref_option`]: Suggest `Option<&T>` instead of `&Option<T>`
2024-09-28 20:16:10 +00:00
bors
897f0e4749 Auto merge of #13471 - y21:issue13466-fp, r=llogiq
Remove method call receiver special casing in `unused_async` lint

Fixes the false positive mentioned in https://github.com/rust-lang/rust-clippy/issues/13466#issuecomment-2380025514.

The false negative in the OP would be nice to fix too, but I'd rather do that in a separate PR because it's much more involved

Before this change, the `unused_async` lint would check if the async fn is also used anywhere and avoid linting if so. The exception is if the async function is immediately called, because the returned future handling can be easily removed (and also if we don't have some exceptions then the lint wouldn't trigger anywhere) *or* if it's a method call receiver.

I'm not exactly sure why I implemented that special casing for method call receivers in #11200, but it doesn't make much sense in hindsight imo. Especially given that method calls are essentially equivalent to function calls with the receiver as the first argument, which was the primary motivation for not linting in the first place (async fn passed to another function, like `axum::get(handler)` where handler has to be an async fn).

changelog: none
2024-09-28 19:18:56 +00:00
Yuri Astrakhan
10e02cf8e3 suggest &str 2024-09-28 13:17:29 -04:00
Yuri Astrakhan
38295a0d8a update docs 2024-09-28 13:01:51 -04:00
Yuri Astrakhan
73a16c10db Suggest Option<&T> instead of &Option<T> 2024-09-28 11:57:34 -04:00
y21
d24a63199a remove method call receiver special casing in unused_async lint 2024-09-27 21:44:19 +00:00
bors
b367d3422c Auto merge of #13468 - Alexendoo:driver-ignore-print, r=flip1995
Ignore `--print`/`-Vv` requests in `clippy-driver`

Fixes https://github.com/rust-lang/rust-clippy/issues/12623
Fixes https://github.com/rust-lang/cargo/issues/14385

r? `@flip1995`

changelog: none
2024-09-27 17:16:28 +00:00
Alex Macleod
605f88aab8 Ignore --print/-Vv requests in clippy-driver 2024-09-27 16:58:59 +00:00
Jubilee
ad3464493d Rollup merge of #130912 - estebank:point-at-arg-type, r=compiler-errors
On implicit `Sized` bound on fn argument, point at type instead of pattern

Instead of

```
error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
  --> $DIR/issue-59324.rs:23:20
   |
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
   |                    ^^^^^^^ doesn't have a size known at compile-time
```

output

```
error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
  --> $DIR/issue-59324.rs:23:29
   |
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
   |                             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
```
2024-09-26 22:20:57 -07:00
Esteban Küber
eff6d414c0 On implicit Sized bound on fn argument, point at type instead of pattern
Instead of

```
error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
  --> $DIR/issue-59324.rs:23:20
   |
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
   |                    ^^^^^^^ doesn't have a size known at compile-time
```

output

```
error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time
  --> $DIR/issue-59324.rs:23:29
   |
LL | fn with_factory<H>(factory: dyn ThriftService<()>) {}
   |                             ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
```
2024-09-27 00:45:02 +00:00
Samuel Moelius
51b527266e Fix bug found during review
https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772
2024-09-25 17:56:51 -04:00
bors
c771204ffb Auto merge of #13456 - vHugoObject:master, r=llogiq
fix(clippy_lints/matches): wildcard_in_or_patterns will no longer be triggered for types annotated with #[nonexhaustive]

fixes #13350

----

changelog: none
2024-09-25 19:11:30 +00:00
VictorHugoPilled
bc07027397 fix(clippy_lints/matches): wildcard_in_or_patterns will no longer be triggered for types annotated with #[nonexhaustive] 2024-09-25 13:12:19 -05:00
Samuel Moelius
5c2f6db289 Fix typo in needless_lifetimes test 2024-09-25 13:52:12 -04:00
Samuel Moelius
66f1f544af Fix clippy_lints and clippy_utils 2024-09-25 13:52:12 -04:00
Samuel Moelius
877585089e Fix non-lifetime tests 2024-09-25 13:52:12 -04:00
Samuel Moelius
f2495a1777 Fix lifetime tests 2024-09-25 13:48:15 -04:00
Samuel Moelius
0a11c5c49a Reorder functions 2024-09-25 13:48:15 -04:00
Samuel Moelius
55fcd46f88 Extend needless_lifetimes to suggest eliding impl lifetimes 2024-09-25 13:48:15 -04:00
bors
2a61f59628 Auto merge of #13393 - vHugoObject:master, r=Alexendoo
fix: Specifying reason in expect(clippy::needless_return) no longer triggers false positive

fixes #13366
changelog: none
2024-09-25 14:44:31 +00:00
bors
52b31180b2 Auto merge of #130778 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Really delayed sync (2 1/2 weeks), because of a `debug_assertion` we hit, and I didn't have the time to investigate earlier.

It would be nice to merge this PR with some priority, as it includes a lot of formatting changes due to the rustfmt bump.

Include Cargo.lock update due to Clippy version bump and ui_test bump in Clippy.
2024-09-25 11:40:41 +00:00
bors
169adfc810 Auto merge of #13453 - samueltardieu:push-mtrklxqnmzzn, r=dswij
Use std_or_core to determine the correct prefix

This is a cleanup commit. It replaces hand-crafted tests by the a call to the `std_or_core()` utility function.

changelog: none
2024-09-25 07:57:41 +00:00
bors
f01dfed99f Auto merge of #13442 - Alexendoo:no-rustfix-reasons, r=Jarcho
Add reasons for or remove some `//@no-rustfix` annotations

changelog: none
2024-09-25 02:00:26 +00:00
Trevor Gross
e691743119 Rollup merge of #130764 - compiler-errors:inherent, r=estebank
Separate collection of crate-local inherent impls from error tracking

#119895 changed the return type of the `crate_inherent_impls` query from `CrateInherentImpls` to `Result<CrateInherentImpls, ErrorGuaranteed>` to avoid needing to use the non-parallel-friendly `track_errors()` to track if an error was reporting from within the query... This was mostly fine until #121113, which stopped halting compilation when we hit an `Err(ErrorGuaranteed)` in the `crate_inherent_impls` query.

Thus we proceed onwards to typeck, and since a return type of `Result<CrateInherentImpls, ErrorGuaranteed>` means that the query can *either* return one of "the list inherent impls" or "error has been reported", later on when we want to assemble method or associated item candidates for inherent impls, we were just treating any `Err(ErrorGuaranteed)` return value as if Rust had no inherent impls defined anywhere at all! This leads to basically every inherent method call failing with an error, lol, which was reported in #127798.

This PR changes the `crate_inherent_impls` query to return `(CrateInherentImpls, Result<(), ErrorGuaranteed>)`, i.e. returning the inherent impls collected *and* whether an error was reported in the query itself. It firewalls the latter part of that query into a new `crate_inherent_impls_validity_check` just for the `ensure()` call.

This fixes #127798.
2024-09-24 19:47:50 -04:00
Lukas Markeffsky
08a8e68d2e be even more precise about "cast" vs "coercion" 2024-09-24 23:12:02 +02:00
bors
cbe294c18a Auto merge of #13452 - ljgermain:master, r=Centri3
`invalid_null_ptr_usage`: fix false positives for `std::ptr::slice_from_raw_parts` functions

fixes #13445
changelog: [`invalid_null_ptr_usage`]: fix false positives for `std::ptr::slice_from_raw_parts` functions
2024-09-24 21:02:11 +00:00
Lukas Markeffsky
d802a7a3c7 unify dyn* coercions with other pointer coercions 2024-09-24 22:17:55 +02:00
ljgermain
31bbe2cee3 Apply review suggestions 2024-09-24 15:17:52 -04:00
Samuel Tardieu
0791efaaac Use std_or_core to determine the correct prefix
Replace hand-crafted tests by the a call to the `std_or_core()` utility
function.
2024-09-24 19:09:40 +02:00