Commit graph

10136 commits

Author SHA1 Message Date
Caio
35d434d08e [arithmetic_side_effects] Fix #11262 2023-07-30 14:33:38 -03: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
7423c2760b Don't lint redundant closure for any function call inserted by the compiler. 2023-07-30 01:19:36 -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
Jason Newcomb
71cc39e1f2 Add debug assertions to implements_trait
Improve debug assertions for `make_projection`
2023-07-30 00:38:04 -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
Philipp Krones
3d60241841
Merge remote-tracking branch 'upstream/master' into rustup 2023-07-28 23:44:28 +02:00
León Orell Valerian Liehr
4c9d68e9b8 Make Clippy understand generic const items 2023-07-28 22:21:41 +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
y21
5e88003dda pattern match on local usage slice to avoid ICE 2023-07-28 12:52:06 +02: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
Timo
205a3741c1 make lint description more consistent (writer/reader -> write/read)
Co-authored-by: Takayuki Nakata <f.seasons017@gmail.com>
2023-07-27 21:19:35 +02: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
Deadbeef
be0b4d5a9b Remove constness from ParamEnv 2023-07-27 15:50:42 +00:00
blyxyas
3bfccacca9
Add comments + Very minor Refactor 2023-07-26 23:16:24 +02:00
Matthias Krüger
8615595021 Rollup merge of #114070 - blyxyas:iter_mut_symbol, r=oli-obk
Add `sym::iter_mut` + `sym::as_mut_ptr` for Clippy

We currently have `sym::iter` and `sym::iter_repeat`, this PR adds `sym::iter_mut` as it's useful for https://github.com/rust-lang/rust-clippy/pull/11038 and another Clippy lint, it also adds `sym::as_mut_ptr` as it's useful for https://github.com/rust-lang/rust-clippy/pull/10962.
2023-07-26 20:49:13 +02: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
bors
ed2ec819e9 Auto merge of #114054 - oli-obk:cleanups, r=estebank
Split some functions with many arguments into builder pattern functions

r? `@estebank`

This doesn't resolve all of the ones in rustc, mostly because I need to do other cleanups in order to be able to use some builder derives from crates.io

Works around https://github.com/rust-lang/rust/issues/90672 by making `x test rustfmt --bless` format itself instead of testing that it is formatted
2023-07-26 11:17:35 +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
blyxyas
0404b6b6c2 Add sym::iter_mut + sym::as_mut_ptr 2023-07-25 23:33:08 +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
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
y21
c0484b74f7 simplify looking for Vec::with_capacity exprs 2023-07-25 18:56:57 +02:00
Guillaume Gomez
1c9772c773 Move inherits_cfg function into clippy_utils 2023-07-25 18:43:58 +02:00
y21
1fe2762900 use a dedicated enum for vec initializer 2023-07-25 18:21:00 +02:00
Guillaume Gomez
15de3dd2af Add a note if the function is behind a cfg 2023-07-25 18:08:16 +02:00
Oli Scherer
3fb714d828 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
David Wood
a1473721b0 clippy: env! invocations can't be b"" literals
Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 11:56:54 +01: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
Milo Moisson
7b8598d6c0
ptr lint: check_mut_from_ref is checked independently of the function's ABI 2023-07-24 01:23:35 +02: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
a4e64ff375 Auto merge of #11166 - Jarcho:expr_use, r=Centri3
Refactor some of  `dereference.rs` to util functions

I've seen a few lints that need to be able to tell if changing the type of an expression would be a vaild suggestion. This extracts part of how that's done from `explicit_auto_deref`.

changelog: None
2023-07-23 18:27:48 +00:00
Milo Moisson
30d06a810c
ptr_arg should ignore extern functions 2023-07-23 17:10:13 +02: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
Jason Newcomb
55dd8a9717 Refactor dereference.rs
Extract getting an expression's use context and the context's defined
type as util functions.
2023-07-23 01:21:12 -04: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
Samuel Moelius
99202a0b56 Start addressing review comments 2023-07-22 11:51:44 -04: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 Flores
ae5d391d21 Remove LetChain 2023-07-22 06:15:02 -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
y21
37b83660bc [unused_async]: don't lint if paths reference async fn without call 2023-07-21 01:04:02 +02:00
bors
ee8a429792 Auto merge of #11188 - Centri3:#11178, r=blyxyas
Allow `Self::cmp(self, other)` as a correct impl

Fixes #11178

Also no longer checks if the method name is *just* cmp, but the path. That was an oversight on my part ^^

r? `@xFrednet`
(and `@blyxyas` too!)

changelog: [`incorrect_partial_ord_impl_on_ord_type`]: Now allows non-method calls to `cmp` like `Self::cmp(self, other)`
2023-07-20 22:37:02 +00:00
Catherine
a4c367d0e9 Allow Self::cmp(self, other) as a correct impl 2023-07-20 16:17:24 -05:00
y21
541d0c8ab7 [slow_vector_initialization]: lint Vec::new() 2023-07-20 21:39:32 +02:00
Caio
f0a16bb8a3 [significant_drop_tightening] Fix #11189 2023-07-20 09:04:08 -03:00
bors
fca1f9aec5 Auto merge of #11106 - syvb:literal_unwrap_ice, r=dswij
[`unnecessary_literal_unwrap`]: Fix ICE on None.unwrap_or_default()

Fixes #11099
Fixes #11064

I'm running into #11099 (cc `@y21)` on my Rust codebase. Clippy ICEs on this code when evaluating the `unnecessary_literal_unwrap` lint:
```rust
fn main() {
    let val1: u8 = None.unwrap_or_default();
}
```

This fixes that ICE and adds an message specifically for that case:

```
error: used `unwrap_or_default()` on `None` value
  --> $DIR/unnecessary_literal_unwrap.rs:26:5
   |
LL |     None::<String>.unwrap_or_default();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()`
```

This PR also fixes the same ICE with `None.unwrap_or_else` (by giving the generic error message for the lint in that case).

changelog: Fix ICE in `unnecessary_literal_unwrap` on `None.unwrap_or_default()`
2023-07-20 10:55:30 +00:00
lcnr
5a6c4d7d43 XSimplifiedType to SimplifiedType::X 2023-07-20 11:05:52 +02:00
bors
fbe292e563 Auto merge of #10971 - Centri3:unnecessary_cast_fully_qual_fix, r=dswij
Check for fully qualified paths in `unnecessary_cast`

Noticed this doesn't pick up `::std::primitive::u32` or the sort, now it does
changelog: none
2023-07-20 08:30:19 +00:00
Catherine
15b68c24b8 Extract the logic for if a snippet equals a type 2023-07-20 03:11:35 -05:00
bors
d764a0ea5e Auto merge of #11161 - c410-f3r:let-chain, r=dswij
[significant_drop_tightening] Fix #11160

Fix #11160

```
changelog: [`significant_drop_tightening`]: Ignore literals in function returns
```
2023-07-20 07:28:08 +00:00
bors
d71fbb9db2 Auto merge of #11107 - Centri3:error_impl_error, r=Jarcho
New lint [`error_impl_error`]

Closes #11101

changelog: New lint [`error_impl_error`]
2023-07-20 02:07:27 +00:00
Samuel Moelius
e27977b847 Rename unwrap_or_else_default to unwrap_or_default 2023-07-19 20:36:10 -04:00
Samuel Moelius
84c411272d Merge unwrap_or_else_default.rs into or_fun_call.rs 2023-07-19 20:36:10 -04:00
Alex Macleod
d4f735c3f5 redundant_type_annotations: only pass certain def kinds to type_of 2023-07-19 17:22:06 +00:00
Esteban Küber
cbca8f9908 On nightly, dump ICE backtraces to disk
Implement rust-lang/compiler-team#578.

When an ICE is encountered on nightly releases, the new rustc panic
handler will also write the contents of the backtrace to disk. If any
`delay_span_bug`s are encountered, their backtrace is also added to the
file. The platform and rustc version will also be collected.
2023-07-19 14:10:07 +00:00
bors
0b63e95dce Auto merge of #10949 - y21:issue8010, r=Alexendoo
[`manual_filter_map`]: lint on `matches` and pattern matching

Fixes #8010

Previously this lint only worked specifically for a very limited set of methods on the filter call (`.filter(|opt| opt.is_some())` and `.filter(|res| res.is_ok())`). This PR extends it to also recognize `matches!` in the `filter` and pattern matching with `if let` or `match` in the `map`.

Example:
```rs
enum Enum {
  A(i32),
  B,
}

let _ = [Enum::A(123), Enum::B].into_iter()
  .filter(|x| matches!(x, Enum::A(_)))
  .map(|x| if let Enum::A(s) = x { s } else { unreachable!() });
```
Now suggests:
```diff
-  .filter(|x| matches!(x, Enum::A(_))).map(if let Enum::A(s) = x { s } else { unreachable!() })
+  .filter_map(|x| match x { Enum::A(s) => Some(s), _ => None })
```

Adding this required a somewhat large change in code because it originally seemed to be specifically written with only method calls in the filter in mind, and `matches!` has different behavior in the map, so this new setup should make it possible to support more "generic" cases that need different handling for the filter and map calls.

changelog: [`manual_filter_map`]: lint on `matches` and pattern matching (and some internal refactoring)
2023-07-19 12:59:51 +00:00
bors
7a34143fa3 Auto merge of #11135 - smoelius:unwrap_or_else_default-fp, r=Centri3
Fix `unwrap_or_else_default` false positive

This PR fixes a false positive in the handling of `unwrap_or_else` with a default value when the value is needed for type inference.

An easy example to exhibit the false positive is the following:
```rust
    let option = None;
    option.unwrap_or_else(Vec::new).push(1);
```
The following code would not compile, because the fact that the value is a `Vec` has been lost:
```rust
    let option = None;
    option.unwrap_or_default().push(1);
```
The fix is to:
- implement a heuristic to tell whether an expression's type can be determined purely from its subexpressions, and the arguments and locals they use;
- apply the heuristic to `unwrap_or_else`'s receiver.

The heuristic returns false when applied to `option` in the above example, but it returns true when applied to `option` in either of the following examples:
```rust
    let option: Option<Vec<u64>> = None;
    option.unwrap_or_else(Vec::new).push(1);
```
```rust
    let option = None::<Vec<u64>>;
    option.unwrap_or_else(Vec::new).push(1);
```

(Aside: https://github.com/rust-lang/rust-clippy/pull/10120 unfairly contained multiple changes in one PR. I am trying to break that PR up into smaller pieces.)

---

changelog: FP: [`unwrap_or_else_default`]: No longer lints if the default value is needed for type inference
2023-07-19 11:37:30 +00:00
Samuel Moelius
f583fd18e4 Fix unwrap_or_else_default false positive 2023-07-19 06:45:33 -04:00
Centri3
dcfc6a20db check for fully qualified paths in unnecessary_cast 2023-07-19 05:24:17 -05:00
Catherine
4c79d8ace5 new lint iter_skip_zero 2023-07-19 03:26:15 -05:00
Catherine
19b0e84187 Remove the configuration option
Also no longer lints non-exported types now
2023-07-19 02:08:33 -05:00
Catherine
9d08502496 New lint [string_lit_chars_any] 2023-07-19 00:38:22 -05:00
bors
d4a6634d37 Auto merge of #11175 - y21:issue11174, r=Manishearth
[`redundant_pattern_matching`]: include guard in suggestion

Fixes #11174

changelog: [`redundant_pattern_matching`]: include guard in suggestion
2023-07-18 20:37:30 +00:00
Guillaume Gomez
8b0540bb46 Fix async functions handling for needless_pass_by_ref_mut lint 2023-07-18 22:21:02 +02:00
Catherine
f4b3bb19c1 Add allow_private_error config option 2023-07-18 10:26:22 -05:00
Catherine
75e1329aac New lint [error_impl_error] 2023-07-18 10:26:12 -05:00
bors
9f0cbfd7df Auto merge of #11140 - Centri3:four_forward_slashes, r=blyxyas
New lint [`four_forward_slashes`]

Closes #9212

changelog: New lint [`four_forward_slashes`]
2023-07-18 12:56:18 +00:00
Catherine
0d59d1d617 Rename to needless_return_with_question_mark 2023-07-18 00:23:41 -05:00
bors
747df85f95 Auto merge of #11171 - Centri3:tuple_array_conversions, r=llogiq
Rewrite [`tuple_array_conversions`]

Fixes #11100
Fixes #11144
Fixes #11124

#11082 still needs discussion and #11085 likely can't be fixed.

changelog: [`tuple_array_conversions`]: Move to `pedantic`
changelog: [`tuple_array_conversions`]: Don't lint if mutability of references changes
changelog: [`tuple_array_conversions`]: Don't lint if bindings don't come from the exact same pattern
changelog: [`tuple_array_conversions`]: Don't lint if bindings are used for more than just the conversion
2023-07-18 05:15:50 +00:00
Catherine
c13cb54e25 New lint needless_return_with_try 2023-07-18 00:09:22 -05:00
Michael Goulet
d1e1dcb1fb Rename arg_iter to iter_instantiated 2023-07-17 21:04:12 +00:00
y21
e7fd44f213 add guard to suggestion instead of not linting 2023-07-17 21:18:11 +02:00
y21
c26801ee92 [redundant_pattern_matching]: don't lint if if guards are present 2023-07-17 19:25:28 +02:00
bors
3e0170bff4 Auto merge of #11173 - Alexendoo:needless-return-fn-macro, r=Manishearth
Don't lint `needless_return` in fns across a macro boundary

Fixes #11167

changelog: none
2023-07-17 15:53:21 +00:00
bors
410456da51 Auto merge of #11116 - y21:format_collect, r=Manishearth
new lint: `format_collect`

A perf lint that looks for `format!`ing inside of `map`, then collecting it into a `String`. Did a quick benchmark locally and it's a bit more than 2x faster with fold.
`write!` is still not optimal (presumably because the fmt stuff goes through dynamic dispatch), but it's still a lot better than creating a new string on every element.
I thought about making a machine applicable suggestion, but there's a lot of suggestions that need to be made here, so I decided to just add help messages.

changelog: new lint: `format_collect`
2023-07-17 15:38:33 +00:00
Alex Macleod
d24f0d056f Don't lint needless_return in fns across a macro boundary 2023-07-17 14:03:00 +00:00
Alex Macleod
36f84a6176 Move tuple_array_conversions to nursery 2023-07-17 12:09:20 +00:00
Catherine
74a77047da Rewrite [tuple_array_conversions] 2023-07-17 05:36:50 -05:00
y21
c83d58f507 document that write!ing into a string never fails 2023-07-17 12:23:18 +02:00
y21
c3881569af new lint: format_collect 2023-07-17 12:13:34 +02:00
Philipp Krones
2feb9a582f Another fix for incorrect_impls 2023-07-17 10:22:49 +02:00
Philipp Krones
d6d530fd0b Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup 2023-07-17 10:22:32 +02:00
Sylvestre Ledru
eaccc6d38f [semicolon_if_nothing_returned]: enable the autofix 2023-07-16 19:37:42 +02:00
Caio
1f82f6ddf3 [significant_drop_tightening] Fix #11160 2023-07-14 13:51:34 -03:00
Mahdi Dibaiee
fdb2e363d3 refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
Philipp Krones
faa07d334a
Bump Clippy version -> 0.1.73 2023-07-14 13:36:23 +02:00
Philipp Krones
415fdb2d1a
Merge remote-tracking branch 'upstream/master' into rustup 2023-07-14 13:36:16 +02:00
bors
bafde54367 Auto merge of #11152 - Alexendoo:unnecessary-cast-applicability, r=Manishearth
Set `unnecessary_cast` suggestion to `MaybeIncorrect` for pointer casts

Closes #11113

changelog: none
2023-07-14 07:39:49 +00:00
Urgau
50da77521e Rename cast_ref_to_mut to invalid_reference_casting (clippy side) 2023-07-13 23:01:24 +02:00
syvb
8d258c1508 Add handling for None.unwrap_or(_else) 2023-07-13 13:05:49 -04:00
syvb
c2aaa622eb Fix ICE on None.unwrap_or_default() 2023-07-13 13:00:10 -04:00
Alex Macleod
ea36a9df75 Set unnecessary_cast suggestion to MaybeIncorrect for pointer casts
Removing casts may cause type inference to stop working which requires
manual intervention
2023-07-13 13:29:41 +00:00
bors
7ccf5d404b Auto merge of #11095 - Alexendoo:rustfmt-imports, r=Manishearth
Add `imports_granularity = "Module"` to rustfmt.toml

This lets rustfmt split/merge imports, `Module` seems to be the most common style in clippy

https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=#imports_granularity

changelog: none

Almost all the updates other than the config file change are from `cargo dev fmt` or blessed tests, the exceptions being

- `tests/ui/single_component_path_imports.rs`
- `tests/ui/single_component_path_imports_nested_first.rs`
- `tests/ui/single_component_path_imports_self_after.rs`
- `tests/ui/single_component_path_imports_self_before.rs`
- `tests/ui/unsafe_removed_from_name.rs` (added a test with merged imports as a drive by)
- `tests/ui/wildcard_imports.rs`
- `tests/ui/wildcard_imports_2021.rs`
2023-07-13 12:54:52 +00:00
Alex Macleod
2811effe34 Add imports_granularity = "Module" to rustfmt.toml 2023-07-13 12:44:57 +00:00
bors
a0e825786b Auto merge of #11147 - y21:issue11145, r=Alexendoo
[`arithmetic_side_effect`]: allow different types on the right hand side for `Wrapping<T>`

Fixes #11145

This lint has a list of allowed types, one of which is `Wrapping<T>`, but it was only actually allowed if the type on the right hand side was also `Wrapping<T>`, which meant that, for example, `Wrapping<u32> += u32` would still lint. It now allows binary ops involving `Wrapping<T>` regardless of the type on the rhs.
These impls have only existed since Rust 1.60.0, so that is probably why the lint was previously not handling this correctly

changelog: [`arithmetic_side_effect`]: allow different types on the right hand side for `Wrapping<T>` (e.g. `Wrapping<T> += T`)
2023-07-13 12:28:52 +00:00
bors
631faa1bc7 Auto merge of #11146 - hydro-project:tuple-array-conversions, r=Centri3,xFrednet
[`tuple_array_conversions`]: move from `complexity` to `nursery`

The lint suggestion is arguably often less readable and more complex than the original code.

For example, which of the following is the most readable:
```rust
let _vertices = edges.flat_map(|(src, dst)| [src, dst]);
let _vertices = edges.flat_map(<_ as Into<[i32; 2]>>::into);
let _vertices = edges.flat_map(<[i32; 2]>::from);
```

The lint can be useful, but really only applies if the tuple is either long enough that naming the fields is silly (maybe at least 4 entries long), or if the author intends the fields to be homogenous, which is author intent and can't be determined by the lint. Therefore I think the lint should be marked as pedantic.

Currently, there are also a lot of false positives with the lint:
* https://github.com/rust-lang/rust-clippy/issues/11082
* https://github.com/rust-lang/rust-clippy/issues/11085
* https://github.com/rust-lang/rust-clippy/issues/11100 (https://github.com/rust-lang/rust-clippy/pull/11105)
* https://github.com/rust-lang/rust-clippy/issues/11124
* https://github.com/rust-lang/rust-clippy/issues/11144

Should fix those issues before enabling it for everyone.

---

changelog: Move [`tuple_array_conversions`] to `nursery` (Now allow-by-default)
<!-- FIY: Ignore this change, if the commit gets backported -->
[#11146](https://github.com/rust-lang/rust-clippy/pull/11146)
2023-07-13 08:39:33 +00:00
Catherine
2e43d0c917 Improve suggestion and add more tests 2023-07-12 19:54:55 -05:00
Catherine
885ce610fe New lint [four_forward_slashes]
Make it trim the contents
2023-07-12 19:39:24 -05:00
Samuel Moelius
050b714c9d Add "Known problems" section to needless_borrow documentation 2023-07-12 20:15:54 -04:00
bors
df92b5284e Auto merge of #11123 - panosfol:master, r=giraffate
[`panic_in_result_fn`] remove `todo!`, `unimplemented!`, `unreachable!`

This commit fixes #11025 by removing checks for `todo!`, `unimplemented!` and `unreachable!`.

changelog: [`panic_in_result_fn`] remove `todo!`, `unimplemented!`, `unreachable!`
2023-07-12 23:57:29 +00:00
bors
d398e59163 Auto merge of #11138 - xFrednet:changelog-1-71, r=flip1995
Changelog for Rust 1.71 👑

Roses are red,
violets are blue,
new format is tried,
it's way less of a fight

---

Hey `@rust-lang/clippy,` `@blyxyas,` and `@Centri3,` I've tried the "new"/minimal changelog format we discussed a few meetings ago. I like it, and the writing process was also way quicker.

[🖼️ Rendered 🖼️](https://github.com/xFrednet/rust-clippy/blob/changelog-1-71/CHANGELOG.md#rust-171)

Furthermore, a big thank you to `@blyxyas` and `@Alexendoo` for updating the script that fetches the PR commits and adding links to the config values to the changelog. ❤️

---

changelog: none
2023-07-12 22:35:22 +00:00
Mingwei Samuel
4102a309d7 [tuple_array_conversions]: move from complexity to nursery
Due to outstanding issues:
* https://github.com/rust-lang/rust-clippy/issues/11082
* https://github.com/rust-lang/rust-clippy/issues/11085
* https://github.com/rust-lang/rust-clippy/issues/11100 (https://github.com/rust-lang/rust-clippy/pull/11105)
* https://github.com/rust-lang/rust-clippy/issues/11124
* https://github.com/rust-lang/rust-clippy/issues/11144
2023-07-12 15:28:46 -07:00
y21
c5fc61ca94 [arithmetic_side_effect]: allow different rhs type 2023-07-13 00:24:10 +02:00
Panagiotis Foliadis
c49c177e06 [panic_in_result_fn] remove todo!, unimplemented!, unreachable!
This commit fixes #11025 by removing checks for `todo!`,
`unimplemented!` and `unreachable!`.

Signed-off-by: Panagiotis Foliadis <pfoliadis@hotmail.com>
2023-07-12 22:19:01 +03:00
xFrednet
31397b489a
Update version attribute for 1.71 lints 2023-07-11 19:23:42 +02:00
bors
a8939e5eae Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obk
Uplift `clippy::fn_null_check` lint

This PR aims at uplifting the `clippy::fn_null_check` lint into rustc.

## `incorrect_fn_null_checks`

(warn-by-default)

The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null.

### Example

```rust
let fn_ptr: fn() = /* somehow obtained nullable function pointer */

if (fn_ptr as *const ()).is_null() { /* ... */ }
```

### Explanation

Function pointers are assumed to be non-null, checking for their nullity is incorrect.

-----

Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

`@rustbot` label: +I-lang-nominated
r? compiler
2023-07-11 09:34:48 +00:00
y21
0b5dac0975 [unnecessary_literal_unwrap]: also handle unwrap_err_unchecked 2023-07-11 08:41:36 +02:00
y21
cd1c8532e9 [unnecessary_literal_unwrap]: lint unwrap_unchecked 2023-07-11 08:38:15 +02:00
Urgau
103949b241 Drop uplifted clippy::fn_null_check 2023-07-10 18:12:41 +02:00
bors
3be3fb7231 Auto merge of #11016 - y21:issue10029, r=blyxyas,dswij
[`filter_next`]: suggest making binding mutable if it needs to be

Fixes #10029

changelog: [`filter_next`]: suggest making binding mutable if it needs to be and adjust applicability
2023-07-10 10:47:37 +00:00
bors
9ab7137686 Auto merge of #11133 - GuillaumeGomez:fix-description-typo, r=Manishearth
Fix typo in `needless_pass_by_ref_mut` lint description

Someone nicely showed me that I made a small typo in https://github.com/rust-lang/rust-clippy/pull/10900.

changelog: none
2023-07-10 09:45:22 +00:00
y21
23ac72316d adjust applicability and suggest making binding mutable 2023-07-10 11:24:16 +02:00
Guillaume Gomez
d1575d1f54 changelog: Fix typo in needless_pass_by_ref_mut lint description 2023-07-10 10:27:23 +02:00
bors
9058b040c8 Auto merge of #11096 - y21:issue11091, r=giraffate
[`manual_range_patterns`]: lint negative values

Fixes #11091.

Now also lints negative values in patterns (`-1 | -2 | -3`)

changelog: [`manual_range_patterns`]: lint negative values
2023-07-10 00:04:08 +00:00
bors
507d1c282e Auto merge of #11110 - y21:unnecessary_literal_unwrap_ignore_expn, r=Jarcho
[`unnecessary_literal_unwrap`]: don't lint if binding initializer comes from expansion

Fixes https://github.com/rust-lang/rust-clippy/discussions/11109

changelog: [`unnecessary_literal_unwrap`]: don't lint if binding initializer comes from expansion
2023-07-09 20:09:22 +00:00
bors
ebd8d31542 Auto merge of #11055 - smoelius:try-this, r=dswij
"try this" -> "try"

Current help messages contain a mix of "try", "try this", and one "try this instead". In the spirit of #10631, this PR adopts the first, as it is the most concise.

It also updates the `lint_message_conventions` test to catch cases of "try this".

(Aside: #10120 unfairly contained multiple changes in one PR. I am trying to break that PR up into smaller pieces.)

changelog: Make help messages more concise ("try this" -> "try").
2023-07-09 15:07:25 +00:00
bors
b46033e9ce Auto merge of #10900 - GuillaumeGomez:needless-pass-by-ref, r=llogiq
Add `needless_pass_by_ref_mut` lint

changelog: [`needless_pass_by_ref_mut`]: This PR add a new lint `needless_pass_by_ref_mut` which emits a warning in case a `&mut` function argument isn't used mutably. It doesn't warn on trait and trait impls functions.

Fixes #8863.
2023-07-09 14:25:10 +00:00
Samuel Moelius
3bf2138289 Fix #10535 2023-07-08 19:12:10 -04:00
bors
6ae065ffd6 Auto merge of #11129 - c410-f3r:lock-1, r=Manishearth
[significant_drop_tightening] Fix #11128

Fix #11128

```
changelog: [`significant_drop_tightening`]: Consider manual alias of the `drop` function.
```
2023-07-08 21:10:43 +00:00
Caio
6384221910 Dogfood 2023-07-08 18:08:48 -03:00
Caio
2be695bf29 [significant_drop_tightening] Fix #11128 2023-07-08 17:43:34 -03:00
bors
8e261c09bb Auto merge of #11049 - Centri3:manual_is_infinite, r=blyxyas,xFrednet
New lints [`manual_is_infinite`] and [`manual_is_finite`]

Closes #9665

changelog: New lints [`manual_is_infinite`] and [`manual_is_finite`]
[#11049](https://github.com/rust-lang/rust-clippy/pull/11049)
2023-07-08 18:45:35 +00:00
Catherine
41438c2b90 Refactor, remove Constant::to_bits 2023-07-08 13:17:35 -05:00
Catherine
a5dfb68491 refactor 2023-07-08 13:11:56 -05:00
Centri3
844afbfeba use other instead of self 2023-07-08 13:02:54 -05:00
Centri3
004e89d4cf rename to manual_partial_ord_and_ord_impl
cargo dev fmt

cargo test passes

cargo test passes

refactor a lil

Update bool_comparison.stderr

heavily refactor + bump `clippy::version`

refactor

refactor

check bounds to increase accuracy, and add todos
2023-07-08 13:02:54 -05:00
Centri3
2a1fd22f81 implement manual_partial_ord_impl
first try at this
2023-07-08 13:02:38 -05:00
bors
1816caaa76 Auto merge of #113376 - Nilstrieb:pointer-coercions-are-not-casts-because-that-sounds-way-to-general-aaaa, r=oli-obk
Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`

It makes it sounds like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a little enum variants. Make it clear there these are only coercions and that people who see this and think "why are so many pointer related casts not in these variants" aren't insane.

This enum was added in #59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing.

r? oli-obk
2023-07-08 13:48:30 +00:00
Nilstrieb
5df1f6681d Pass correct substs to implements_trait in incorrect_impls
`Copy<T>` does in fact not exist. The substs on the trait_ref contain
the `Self` type of the impl as the first parameter, so passing that
to `implements_trait`, which then nicely prepends the `Self` type
for us does not end will.
2023-07-07 20:28:51 +02:00
Alex Macleod
87373d7f52 Fix failing clippy tests
Comments out the C string literals due to https://github.com/rust-lang/rust/pull/113334

Fixes https://github.com/rust-lang/rust-clippy/issues/11121
2023-07-07 18:19:08 +00:00
Nilstrieb
b5ac726ed3 Rename adjustment::PointerCast and variants using it to PointerCoercion
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related
casts, when in reality their just used to share a some enum variants. Make it clear there these
are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-07 18:17:16 +02:00
y21
c927912c5b [manual_range_patterns]: document what range we don't lint 2023-07-07 17:25:28 +02:00
y21
5cc0c04826 [manual_range_patterns]: lint negative values 2023-07-07 17:25:28 +02:00
Alex Macleod
4939a716e8 arc_with_non_send_sync: reword and move to suspicious 2023-07-07 12:02:05 +00:00
Catherine
5949f762bf Make suggestion give multiple alternatives 2023-07-06 20:27:21 -05:00
Catherine
f12edfdb53 manual_float_methods 2023-07-06 20:27:21 -05:00
bors
dd8e44c5a2 Auto merge of #11111 - Alexendoo:regex-def-paths, r=giraffate
Fix regex lints for regex 1.9.0

regex 1.9.0 was [just released](https://blog.burntsushi.net/regex-internals/), which changes where the types are defined. Instead of updating the definitions to the ones in 1.9.0 this PR uses [`def_path_def_ids`](https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/fn.def_path_def_ids.html) on the canonical paths so that we don't have to worry about third party crate internals

This means that it still works with older regex versions too, and will for any future layout changes. I tested it with 1.8.4 and 1.9.0

changelog: [`INVALID_REGEX`], [`TRIVIAL_REGEX`]: now works with regex 1.9.0
2023-07-06 23:40:33 +00:00
Boxy
cbe468222a Move TyCtxt::mk_x to Ty::new_x where applicable 2023-07-05 20:27:07 +01:00
Alex Macleod
f945351170 Fix regex lints for regex 1.9.0 2023-07-05 18:29:43 +00:00
y21
6868c0a74b [unnecessary_literal_unwrap]: don't lint if binding initializer is expn 2023-07-05 13:03:34 +02:00
bors
1e656d8d6d Auto merge of #10970 - y21:read_line_without_trim, r=giraffate
new lint: `read_line_without_trim`

This adds a new lint that checks for calls to `Stdin::read_line` with a reference to a string that is then attempted to parse into an integer type without first trimming it, which is always going to fail at runtime.
This is something that I've seen happen a lot to beginners, because it's easy to run into when following the example of chapter 2 in the book where it shows how to program a guessing game.
It would be nice if we could point beginners to clippy and tell them "let's see what clippy has to say" and have clippy explain to them why it fails 👀

I think this lint can later be "generalized" to work not just for `Stdin` but also any `BufRead` (which seems to be where the guarantee about the trailing newline comes from) and also, matching/comparing it to a string slice that doesn't end in a newline character (e.g. `input == "foo"` is always going to fail)

changelog: new lint: [`read_line_without_trim`]
2023-07-05 00:13:59 +00:00
Guillaume Gomez
f048f73251 Add warning about semver compatibility if it's a public function 2023-07-04 20:35:23 +02:00
bors
3f4e5999b2 Auto merge of #11094 - y21:issue11084, r=Alexendoo
[`useless_vec`]: add more tests and don't lint inside of macros

Closes #11084.

I realized that the fix I added in #11081 itself also causes an error in a suggestion when inside of a macro. Example:
```rs
macro_rules! x {
  () => {
    for _ in vec![1, 2] {}
  }
}
x!();
```
Here it would suggest replacing `vec![1, 2]` with `[x!()]`, because that's what the source callsite is (reminder: it does this to get the correct span of `x!()` for code like `for _ in vec![x!()]`), but that's wrong when *inside* macros, so I decided to make it not lint if the whole loop construct is inside a macro to avoid this issue.

changelog: [`useless_vec`]: add more tests and don't lint inside of macros

r? `@Alexendoo` since these were your tests, I figured it makes most sense to assign you
2023-07-03 21:07:44 +00:00
y21
8fad54e8f9 new lint: read_line_without_trim 2023-07-03 22:51:38 +02:00
Guillaume Gomez
33adfcd327 Add warning for NEEDLESS_PASS_BY_REF_MUT lint about the fact that it changes API 2023-07-03 22:48:40 +02:00
Guillaume Gomez
dd3e00f102 Fix warnings of needless_pass_by_ref_mut in clippy 2023-07-03 22:25:36 +02:00
Guillaume Gomez
b41fc6784f Add needless_pass_by_ref lint 2023-07-03 22:25:36 +02:00
y21
b4549c50b5 [useless_vec]: add more tests for macro combinations 2023-07-03 19:48:27 +02:00
bors
ba3bd8f0f1 Auto merge of #11078 - Centri3:11068, r=llogiq
[`needless_raw_string_hashes`]: Only reset hashes needed if not following quote

Fixes #11068

changelog: none
2023-07-03 17:01:27 +00:00
bors
3f17c5c388 Auto merge of #10924 - est31:manual_let_else_question_mark, r=Centri3,flip1995,Manishearth
Don't lint manual_let_else in cases where ? would work

Don't lint `manual_let_else` where the question mark operator `?` would be sufficient, that is, mostly in cases like:

```Rust
let v = if let Some(v) = ex { v } else { return None };
```

Also, this PR emits the `question_mark` lint for `let...else` patterns that could be written with `?` (also, only `return None` like cases).

```
changelog: [`manual_let_else`]: don't lint in cases where question_mark already lints
changelog: [`question_mark`]: lint for `let Some(...) = ex else { return None };`
```

Fixes  #8755
2023-07-03 14:18:32 +00:00
bors
a959061763 Auto merge of #11081 - y21:issue11075, r=Manishearth
[`useless_vec`]: use the source span for initializer

Fixes #11075.

changelog: [`useless_vec`]: use the source span for the initializer expression when inside of a macro
2023-07-03 12:08:36 +00:00
y21
1f77f8cc3c [useless_vec]: use the source span 2023-07-03 13:40:33 +02:00
Catherine
9a581077d4 Fix FP [needless_raw_string_hashes] 2023-07-03 06:35:04 -05:00
bors
2b03bb08b2 Auto merge of #11077 - y21:issue11076, r=Manishearth
[`arc_with_non_send_sync`]: don't lint if type has nested type parameters

Fixes #11076

changelog: [`arc_with_non_send_sync`]: don't lint if type has nested type parameters

r? `@Manishearth`
2023-07-03 09:48:05 +00:00
y21
75c339cd0a [arc_with_non_send_sync]: look for nested type parameters 2023-07-03 11:35:25 +02:00
est31
d80581c7d2 Move pat_and_expr_can_be_question_mark into clippy_utils 2023-07-03 09:42:54 +02:00
est31
6990eaa972 Don't suppress manual_let_else if question_mark is allowed
If question_mark is allowed, there is no overlap any more,
so we can just not suppress it.
2023-07-03 09:42:54 +02:00
bors
c46ddeb9e1 Auto merge of #10987 - y21:type_id_on_box, r=llogiq
new lint: `type_id_on_box`

Closes #7687.

A new lint that detects calling `.type_id()` on `Box<dyn Any>` (and not on the underlying `dyn Any`), which can make up for some pretty confusing bugs!

changelog: new lint: [`type_id_on_box`]
2023-07-03 06:16:14 +00:00
bors
4752466c8e Auto merge of #11069 - y21:issue11063, r=Alexendoo
[`missing_fields_in_debug`]: make sure self type is an adt

Fixes #11063, another ICE that can only happen in core.

This lint needs the `DefId` of the implementor to get its fields, but that ICEs if the implementor does not have a `DefId` (as is the case with primitive types, e.g. `impl Debug for bool`), which is where this ICE comes from.

This PR changes the check I added in #10897 to be more... robust against `Debug` implementations we don't want to lint.
Instead of just checking if the self type is a type parameter and "special casing" one specific case we don't want to lint, we should probably rather just check that the self type is either a struct, an enum or a union and only then continue.
That prevents weird edge cases like this one that can only happen in core.

Again, I don't know if it's even possible to add a test case for this since one cannot implement `Debug` for primitive types outside of the crate that defined `Debug` (core).
I did make sure that this PR no longer ICEs on `impl<T> Debug for T` and `impl Debug for bool`.
Maybe writing such a test is possible with `#![no_core]` and then re-defining the `Debug` trait or something like that...?

changelog: [`missing_fields_in_debug`]: make sure self type is an adt (fixes an ICE in core)

r? `@Alexendoo` (reviewed the last PRs for this lint)
2023-07-02 21:12:10 +00:00
y21
555ceb83fe [missing_fields_in_debug]: make sure self is an adt 2023-07-02 21:42:39 +02:00
bors
83d0682d5e Auto merge of #11061 - Alexendoo:let-and-return-closures, r=llogiq
`let_and_return`: lint 'static lifetimes, don't lint borrows in closures

Fixes #11056

Now also ignores functions returning `'static` lifetimes, since I noticed the `stdin.lock()` example was still being linted but doesn't need to be since https://github.com/rust-lang/rust/pull/93965

changelog: none
2023-07-02 15:14:46 +00:00
Alex Macleod
e29a5acf6f let_and_return: lint 'static lifetimes, don't lint borrows in closures 2023-07-02 14:25:40 +00:00
Philipp Krones
cb3ecf7b79 Merge commit '37f4c1725d3fd7e9c3ffd8783246bc5589debc53' into clippyup 2023-07-02 14:59:02 +02:00
bors
1990b72e8a Auto merge of #11058 - Centri3:typos, r=xFrednet
Fix typos

Just a couple misc typos I found

changelog: none
2023-07-02 12:11:30 +00:00
Catherine
885a18207f Fix typos 2023-07-02 07:11:05 -05:00
bors
bb33e0343f Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillot
Make simd_shuffle_indices use valtrees

This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user).

cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-07-02 07:43:36 +00:00
Catherine
cb5d7e344a address comments 2023-07-01 12:37:16 -05:00
Catherine
fbb3f759e2 update docs 2023-07-01 12:36:02 -05:00
Catherine
04b0857691 Typo 2023-07-01 12:36:02 -05:00
Catherine
354172a18e New lint manual_try_fold 2023-07-01 12:36:02 -05:00
bors
c7bf05c1a4 Auto merge of #11020 - Centri3:tuple_array_conversion, r=llogiq
New lint [`tuple_array_conversions`]

Closes #10748

PS, the implementation is a bit ugly 😅 ~~I will likely refactor soon enough :)~~ Done :D

changelog: New lint [`tuple_array_conversions`]
2023-07-01 15:27:35 +00:00
Samuel Moelius
420f3d11e8 "try this" -> "try" 2023-07-01 07:08:01 -04:00
est31
20dfaba035 Put into one pass 2023-06-30 19:47:22 +02:00
Catherine
efac83813d Make eq_op suggest .is_nan() 2023-06-30 11:43:02 -05:00
est31
c6be62159f Fix the now stricter lint in manual_rem_euclid.rs 2023-06-30 18:01:28 +02:00
est31
86391abc70 Don't lint manual_let_else in cases where the question mark operator would work
Also, lint question_mark for `let...else` clauses that can be simplified to use `?`.
This lint isn't perfect as it doesn't support the unstable try blocks.
2023-06-30 18:01:27 +02:00
bors
2c40b99d08 Auto merge of #11048 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-06-30 14:09:53 +00:00
Philipp Krones
8010c3462d
Merge remote-tracking branch 'upstream/master' into rustup 2023-06-30 16:09:06 +02:00
y21
648d1ae8e0 lint on matches and pattern matching 2023-06-30 14:54:49 +02:00
bors
73f14176e3 Auto merge of #10774 - c410-f3r:lock-1, r=Jarcho
[significant_drop_tightening] Fix #10413

Fix #10413

This is quite a rewrite that unfortunately took a  large amount of time. I tried my best to comment what is going on to easy review but feel free to ask any question.

The problem basically is that the current algorithm is only taking into consideration single blocks which means that things like the following don't work or show unpredictable results.

```rust
let mutex = Mutex::new(1);
{
  let lock = mutex.lock().unwrap();
  {
    let _ = *lock;
  }
}
```

The solve the issue, each path that refers a lock is now being tracked individually.

```
changelog: [`significant_drop_tightening`]: Lift the restriction of only considerate single blocks
```
2023-06-30 02:51:15 +00:00
bors
3d4c536e87 Auto merge of #11013 - Centri3:redundant_rest_pattern, r=giraffate
New lint [`redundant_at_rest_pattern`]

Closes #11011

It's always a great feeling when a new lint triggers on clippy itself 😄

changelog: New lint [`redundant_at_rest_pattern`]
2023-06-29 23:54:35 +00:00
Caio
fc832f0eb7 Dogfood 2023-06-29 09:30:04 -03:00
Caio
f0619024b8 Fix #10413 2023-06-29 09:27:49 -03:00
Catherine
826edd75ef heavily refactor 2023-06-29 06:46:28 -05:00
Catherine
95b24d44a6 Fix FP 2023-06-29 06:46:28 -05:00
Catherine
b1acbde618 Add msrv check and make test pass 2023-06-29 06:46:28 -05:00
Catherine
bfcc8ba444 New lint tuple_array_conversions 2023-06-29 06:46:00 -05:00
bors
9020937bbe Auto merge of #11030 - darklyspaced:master, r=Centri3,xFrednet
suggests `is_some_and` over `map().unwrap`

changelog: Enhancement: [`option_map_unwrap_or`] now considers the [`msrv`] config when creating the suggestion.

 * modified option_map_unwrap_or lint to recognise when an `Option<T>` is mapped to an `Option<bool>` with false being used when `None` is detected; suggests the use of `is_some_and` instead
 * msrv is set to 1.70.0 for this lint; when `is_some_and` was stabilised

fixes #9125
2023-06-29 09:54:51 +00:00
darklyspaced
211278bc86
updated list of lints that use msrv 2023-06-29 10:18:38 +08:00
bors
10ce1a6d5e Auto merge of #11001 - y21:issue8628, r=Jarcho
[`question_mark`]: don't lint inside of `try` block

Fixes #8628.

Diff looks a bit noisy because I had to move the two functions into an impl, because they now need to access the structs `try_block_depth` field to see if they're inside a try block.

changelog: [`question_mark`]: don't lint inside of `try` block
2023-06-28 18:38:44 +00:00
bors
ea4c5c5ca5 Auto merge of #11035 - y21:issue10729, r=Jarcho
[`option_if_let_else`]: suggest `.as_ref()` if scrutinee is of type `&Option<_>`

Fixes #10729

`Option::map_or` takes ownership, so if matching on an `&Option<_>`, we need to suggest `.as_ref()` before calling `map_or` to get the same effect and to not cause a borrowck error.

changelog: [`option_if_let_else`]: suggest `.as_ref()`/`.as_mut()` if scrutinee is of type `&Option<_>`/`&mut Option<_>`
2023-06-28 15:39:04 +00:00
y21
70610c0018 lint in nested bodies if try is in outer body 2023-06-28 12:41:18 +02:00
bors
750c7a11da Auto merge of #11042 - y21:issue10459, r=Manishearth
[`unused_async`]: don't lint if function is part of a trait

Fixes #10459.

We shouldn't lint if the function is part of a trait, because the user won't be able to easily remove the `async`, as this will then not match with the function signature in the trait definition

changelog: [`unused_async`]: don't lint if function is part of a trait
2023-06-28 09:54:20 +00:00
y21
b713cd5945 move is_in_trait_method to utils and rename 2023-06-28 11:35:10 +02:00
Catherine
46aa8abf08 Change category and update to ui_test 2023-06-28 03:20:21 -05:00
Centri3
8296a338db new lints for visibility 2023-06-28 03:20:21 -05:00
Catherine
3376c714ee Add note to remove if statement altogether 2023-06-27 20:10:31 -05:00
y21
b592d39968 manual_range_pattern -> manual_range_patterns 2023-06-27 22:35:54 +02:00
y21
1d4afc5d82 new lint: manual_range_pattern 2023-06-27 22:34:31 +02:00
y21
a43bfefd19 [unused_async]: don't lint on async trait impls 2023-06-27 22:30:38 +02:00
Catherine
e9ced12512 Rename the lint 2023-06-27 06:31:04 -05:00
Catherine
9a8347ded5 New lint [redundant_rest_pattern] 2023-06-27 06:06:56 -05:00
Centri3
8cb6c86996 change category and refactor
Update raw_strings.rs

Revert "new lints for visibility"

This reverts commit 0e5a537d209727169769dc19cf86aef27122c092.

new lints for visibility
2023-06-27 05:16:40 -05:00
Centri3
cb52d19ce1 don't lint needless_raw_string_hashes when it's unnecessary 2023-06-27 05:12:00 -05:00
Catherine
ec765d9516 Update raw_strings.rs 2023-06-27 05:12:00 -05:00
Centri3
bc744eb82b new lint needless_raw_string + refactor a bit
Thanks, #112373, for the snippet at line 75!
2023-06-27 05:12:00 -05:00
Centri3
1bf74fc303 add needless_raw_string_hashes lint
add semicolon in doctest
2023-06-27 05:12:00 -05:00
darklyspaced
a693cbc1bc
changed msrv name for consistency & changed nested if for style 2023-06-27 11:29:02 +08:00
darklyspaced
ca00b138b2
ignore too_many_arguments on check 2023-06-27 11:29:02 +08:00
darklyspaced
c378bf9ddf
Revert "now passes dogfood by wrapping unwrap_recv and unwrap_arg into a tuple"
This reverts commit 7b91844a3207d90d4200a7b53d0ae1a7a1dca73a.
2023-06-27 11:29:02 +08:00
darklyspaced
b832175b2d
now passes dogfood by wrapping unwrap_recv and unwrap_arg into a tuple
was previously failing due to `check` having to many arguments.
2023-06-27 11:29:02 +08:00
darklyspaced
c60222dc12
changed the msrv to 1.70 to suggest is_some_and
if the msrv is not >= 1.70 then the `map_or` is suggested instead of `is_some_and` (even when `unwrap_or` returns false)
2023-06-27 11:29:02 +08:00
darklyspaced
9b7d8d1dc7
suggests is_some_and over map().unwrap_or(false) 2023-06-27 11:29:02 +08:00
Michael Goulet
716c552632 Migrate predicates_of and caller_bounds to Clause 2023-06-26 23:12:03 +00:00
Catherine
d29506794e Don't lint code from external macros 2023-06-26 15:10:06 -05:00
y21
733a9ea6b9 [option_if_let_else]: suggest .as_ref() if &Option<_> 2023-06-26 20:13:06 +02:00
bors
a9e0bbb931 Auto merge of #112887 - WaffleLapkin:become_unuwuable_in_hir, r=compiler-errors,Nilstrieb
`hir`: Add `Become` expression kind (explicit tail calls experiment)

This adds `hir::ExprKind::Become` alongside ast lowering. During hir-thir lowering we currently lower `become` as `return`, so that we can partially test `become` without ICEing.

cc `@scottmcm`
r? `@Nilstrieb`
2023-06-26 13:51:04 +00:00
Oli Scherer
7bd8ab77e5 Make simd_shuffle_indices use valtrees 2023-06-26 09:34:52 +00:00
Maybe Waffle
555bd985d2 Support hir::ExprKind::Become in clippy 2023-06-26 08:56:32 +00:00
bors
407bfd483a Auto merge of #11005 - Centri3:never_loop, r=giraffate
Check if `if` conditions always evaluate to true in `never_loop`

This fixes the example provided in #11004, but it shouldn't be closed as this is still an issue on like
```rust
let x = true;
if x { /* etc */ }`
```
This also makes `clippy_utils::consts::constant` handle `ConstBlock` and `DropTemps`.

changelog: [`never_loop`]: Check if `if` conditions always evaluate to true
2023-06-26 00:42:38 +00:00
bors
78e36d9f53 Auto merge of #10996 - Centri3:mem_forget, r=xFrednet
Lint `mem_forget` if any fields are `Drop`

Closes #9298
I think this way of doing it (`needs_drop`) should be fine.

---

changelog: Enhancement: [`mem_forget`]: Now lints on types with fields that implement `Drop`
[#10996](https://github.com/rust-lang/rust-clippy/pull/10996)
2023-06-25 09:40:13 +00:00
Catherine
a5ae9044fb make note less verbose 2023-06-25 04:28:40 -05:00
Renato Lochetti
f0eb40c981
Avoid linting on procedural macros 2023-06-24 19:45:16 -03:00
bors
1b4c423f30 Auto merge of #11021 - y21:issue9493, r=llogiq
[`format_push_string`]: look through `match` and `if` expressions

Closes #9493.

changelog: [`format_push_string`]: look through `match` and `if` expressions
2023-06-24 18:59:58 +00:00
y21
fe856d383f [format_push_string]: look through match, if, if-let 2023-06-24 19:54:12 +02:00
Catherine
db4efe3f6d Don't lint ptr_arg when return type uses Cow's lifetime 2023-06-24 03:26:40 -05:00
bors
ce0a48a9b6 Auto merge of #10994 - y21:issue8772, r=giraffate
[`type_repetition_in_bounds`]: respect MSRV for combining bounds

Fixes #8772.

changelog: [`type_repetition_in_bounds`]: respect msrv for combining `?Sized` bound
2023-06-23 00:31:04 +00:00
Michael Goulet
533a819115 Migrate item_bounds to ty::Clause 2023-06-22 18:34:23 +00:00
y21
33b6d0d206 rename MSRV alias, add MSRV to lint doc 2023-06-22 17:19:43 +02:00
Catherine
6a1084c26f Check if if conditions always evaluate to true in never_loop 2023-06-22 04:31:05 -05:00