Commit Graph

9799 Commits

Author SHA1 Message Date
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
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
bors
6ec23880f2 Auto merge of #10979 - y21:issue9909, r=giraffate
[`get_unwrap`]: include a borrow in the suggestion if argument is not an integer literal

Fixes #9909

I have to say, I don't really understand what the previous logic was trying to do, but this fixes the linked bug.
It was checking if the argument passed to `.get()` can be parsed as a usize (i.e. if it's an integer literal, probably?), and if not, it wouldn't include a borrow? I don't know how we came to that conclusion, but that logic doesn't work:
```rs
let slice = &[1, 2];
let _r: &i32 = slice.get({ 1 }).unwrap();
// previous suggestion: slice[{ 1 }]
// the suggestion should be: &slice[{ 1 }]
```
Here the argument passed to it isn't an integer literal, but it should still include a borrow, because it would otherwise change the type from `&i32` to `i32`.

The exception is that if the parent of the `get().unwrap()` expr is a dereference or a method call or the like, we don't need an explicit borrow because it's automatically inserted by the compiler

changelog: [`get_unwrap`]: include a borrow in the suggestion if argument is not an integer literal
2023-06-21 23:57:02 +00:00
bors
9fa4089410 Auto merge of #10993 - Centri3:iter_nth_zero, r=Manishearth
Don't lint [`iter_nth_zero`] in `next`

Closes #9820
This also *slightlyy* modifies the output of `iter_nth`, as I noticed the types' names weren't in backticks

changelog: [`iter_nth_zero`]: No longer lints in implementations of `Iterator::next`
2023-06-21 22:06:12 +00:00
Centri3
242807a9c1 Don't lint iter_nth_zero in next 2023-06-21 15:58:52 -05:00
Catherine
b6f194b48c move to drop_forget_ref 2023-06-21 15:56:24 -05:00
bors
b3fd7b8120 Auto merge of #10948 - Centri3:borrow_as_ptr, r=dswij
[`borrow_as_ptr`]: Ignore temporaries

Fixes #9884

changelog: [`borrow_as_ptr`]: Ignore temporaries
2023-06-21 17:07:52 +00:00
y21
716305d4b6 [question_mark]: don't lint inside of try block 2023-06-21 16:39:46 +02:00
bors
a2b99d8174 Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstrieb
Rollup of 6 pull requests

Successful merges:

 - #112632 (Implement PartialOrd for `Vec`s over different allocators)
 - #112759 (Make closure_saved_names_of_captured_variables a query. )
 - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`)
 - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment))
 - #112830 (More codegen cleanups)
 - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-21 08:00:23 +00:00
y21
bdb2a17107 declare needs_ref later 2023-06-21 09:16:25 +02:00
y21
3122e3d78f use let chains, move assignments out of block, add tests 2023-06-21 09:04:40 +02:00
bors
70c2d0cfe5 Auto merge of #106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieu
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata

FCP completed in https://github.com/rust-lang/rust/issues/103763#issuecomment-1362267967

Closes #103763
2023-06-21 05:13:39 +00:00
Catherine
e3b601a1aa Add WebAssembly to allowed idents 2023-06-20 18:12:20 -05:00
Catherine
d8d59965f1 Lint mem_forget if fields are Drop 2023-06-20 13:37:03 -05:00
y21
765a6e4a90 put issue link between <> 2023-06-20 17:36:38 +02:00
y21
1b6738ba39 s/is_dyn_trait/is_dyn_any 2023-06-20 17:33:32 +02:00
y21
87c28b9463 [type_repetition_in_bounds]: respect msrv for combining maybe bounds 2023-06-20 17:24:46 +02:00
bors
62972ae2dd Auto merge of #10952 - Centri3:excessive_precision, r=dswij
Don't lint `excessive_precision` on inf

Fixes #9910

changelog: [`excessive_precision`]: No longer lints overflowing literals
2023-06-20 14:56:21 +00:00
bors
5da6174318 Auto merge of #10990 - y21:issue8634-partial, r=blyxyas,xFrednet
[`single_match`]: don't lint if block contains comments

Fixes #8634

It now ignores matches with a comment in the "else" arm

changelog: [`single_match`]: don't lint if block contains comments
2023-06-20 13:57:19 +00:00
bors
8fd021f504 Auto merge of #10986 - Centri3:undocumented_unsafe_blocks, r=Manishearth
Allow safety comment above attributes

Closes #8679

changelog: Enhancement: [`undocumented_safety_block`]: Added `accept-comment-above-attributes` configuration.
2023-06-20 05:04:46 +00:00
Centri3
cc2e49f695 allow safety comment above attributes 2023-06-19 23:46:57 -05:00
bors
1919dff4ee Auto merge of #10989 - ericmarkmartin:use-placeref-abstraction, r=Manishearth
Use placeref abstraction

rust-lang/rust#80647 suggests refactoring certain patterns with MIR places to use higher-level abstractions provided by the [`Place`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.Place.html)/[`PlaceRef`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_middle/mir/struct.PlaceRef.html). While working on that issue, I found a couple candidates for such refactoring in clippy.

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

changelog: none
2023-06-20 04:43:38 +00:00
bors
89294e1756 Auto merge of #10992 - blyxyas:fix-test_case_lib, r=Manishearth
`items_after_test_module`: Ignore in-proc-macros items

The library `test-case` is having some problems with this lint, ignoring proc macros should fix it.
Related to #10713 and frondeus/test-case#122

(Couldn't add test cases for this exact situation without importing the library, but I think the fix is simple enough that we can be pretty sure there won't be any problems :) )

changelog:[`items_after_test_module`]: Ignore items in procedural macros
2023-06-20 04:14:20 +00:00
bors
5b60388e5a Auto merge of #10930 - y21:issue9956, r=blyxyas,xFrednet
[`redundant_closure_call`]: handle nested closures

Fixes #9956.

This ended up being a much larger change than I'd thought, and I ended up having to pretty much rewrite it as a late lint pass, because it needs access to certain things that I don't think are available in early lint passes (e.g. getting the parent expr). I think this'll be required to fi-x #10922 anyway, so this is probably fine.
(edit: had to write "fi-x" because "fix" makes github think that this PR fixes it, which it doesn't 😅 )

Previously, it would suggest changing `(|| || 42)()()` to `|| 42()`, which is a type error (it needs parens: `(|| 42)()`). In my opinion, though, the suggested fix should have really been `42`, so that's what this PR changes.

changelog: [`redundant_closure_call`]: handle nested closures and rewrite as a late lint pass
2023-06-19 20:30:35 +00:00
bors
f396004b25 Auto merge of #10975 - hehaoqian:fix_self_named_module_files, r=Centri3,xFrednet
Fix false positive of [self_named_module_files] and [mod_module_files]

changelog: [self_named_module_files] [mod_module_files]: No longer lints dependencies located in subdirectory of workspace

fixes #8887

---

First time contributor here, just read contribution guide today.

I have several questions:

1. ~Is it the correct way to use environment variable `CARGO_HOME` to get the location of cargo home directory?~
(Edit: Code no longer uses CARGO_HOME)
2. How to setup test for this PR? This involves multiple files and `CARGO_HOME` setup. ~Not sure how to do this.~
~Edit: Working on tests right now~ A workspace_test has been added
2023-06-19 20:14:21 +00:00
bors
c8c03ea606 Auto merge of #10793 - c410-f3r:bbbbbbbbbbb, r=xFrednet
[`arithmetic_side_effects`] Fix #10792

Fix #10792

```
changelog: [`arithmetic_side_effects`]: Retrieve field values of structures that are in constant environments
```
2023-06-19 19:51:49 +00:00
blyxyas
62c9e0b87d
Ignore in-proc-macros items 2023-06-19 20:50:24 +02:00
y21
2e856fa99b add test for block comment and add note to description 2023-06-19 20:07:31 +02:00
y21
d7e723441e [single_match]: don't lint if block contains comments 2023-06-19 17:18:27 +02:00
Michael Goulet
b2c7ce8908 s/Clause/ClauseKind 2023-06-19 14:57:42 +00:00
Eric Mark Martin
66590ba41b use PlaceRef abstractions 2023-06-19 03:44:04 -04:00
hehaoqian
e11ebbd5e7 Move continue into if statement
Co-authored-by: Catherine <114838443+Centri3@users.noreply.github.com>
2023-06-19 08:36:27 +08:00
Centri3
2cd4a9182a Ignore functions annotated with #[test] 2023-06-18 19:32:38 -05:00
y21
26ac76c15f add it to the methods lint pass 2023-06-18 22:36:08 +02:00
y21
9ab1e8e95c that was definitely not the right version 2023-06-18 22:27:20 +02:00
y21
c5a9adc2be new lint: type_id_on_box 2023-06-18 22:20:10 +02:00
hehaoqian
65b93a5b43 Fix false positive of [self_named_module_files] and [mod_module_files] 2023-06-18 09:04:59 +08:00
Centri3
a8605269bd add test for closures 2023-06-17 20:01:15 -05:00
Centri3
07dbcbda12 new lint single_call_fn 2023-06-17 20:01:06 -05:00
Caio
0e1caa765e Fix #10792 2023-06-17 17:03:31 -03:00
y21
6331c943ff include a ref if argument is not just a numeric literal 2023-06-17 20:48:56 +02:00
bors
8c8ff5f31d Auto merge of #10976 - dswij:issue-10966, r=Alexendoo
Make [`missing_panics_doc`]  not lint for `todo!()`

closes #10966

changelog: [`missing_panics_doc`] now does not lint for `todo!()`
2023-06-17 16:40:39 +00:00
dswij
1f621af28c Exlude todo!() from missing_panics_in_doc 2023-06-17 23:20:33 +08:00
Renato Lochetti
e2e6a02445
Addressing reviewer comments 2023-06-17 09:36:38 -03:00
Renato Lochetti
520228b377
Adding configuration to allow safety comment above stmt containing unsafe block 2023-06-17 09:36:36 -03:00
Oli Scherer
5777494f99 Add AliasKind::Weak for type aliases.
Only use it when the type alias contains an opaque type.

Also does wf-checking on such type aliases.
2023-06-16 19:39:48 +00:00
bors
3217f8aeaa Auto merge of #10942 - Centri3:unnecessary_cast, r=llogiq
Ignore more type aliases in `unnecessary_cast`

This is potentially the worst code I've ever written, and even if not, it's very close to being on par with starb. This will ignore `call() as i32` and `local_obtained_from_call as i32` now.

This should fix every reasonable way to reproduce #10555, but likely not entirely.

changelog: Ignore more type aliases in `unnecessary_cast`
2023-06-16 19:24:11 +00:00
bors
e11f36cc67 Auto merge of #10965 - not-my-profile:explain-status, r=Alexendoo
Make `--explain` subcommand return 1 for missing lints

changelog: The `--explain` subcommand now exits with the 1 exit code for missing lints
2023-06-16 11:28:51 +00:00
Martin Fischer
894d5dafac Make --explain subcommand return 1 for missing lints 2023-06-16 11:53:25 +02:00
Martin Fischer
a94aac607c Refactor to make following commit pass single_match_else lint 2023-06-16 11:53:24 +02:00
bors
43ecf8ea7d Auto merge of #10953 - KisaragiEffective:missing_panics_doc_trigger_on_expect, r=dswij
[`missing_panics_doc`]: pickup expect method

close #10240

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

changelog: [`missing_panics_doc`]: pickup expect method
2023-06-16 09:12:46 +00:00
bors
87b5f89497 Auto merge of #10925 - Centri3:needless_clone_impl2, r=xFrednet
add lint [`incorrect_clone_impl_on_copy_type`]

Split off from #10788.

Closes #10700

----

changelog: new lint [`incorrect_clone_impl_on_copy_type`]
[#10925](https://github.com/rust-lang/rust-clippy/pull/10925)
2023-06-16 08:09:18 +00:00
Kisaragi
73c0c14526
improve grammer in comment sentence
Co-authored-by: dswij <dharmasw@outlook.com>
2023-06-16 16:39:09 +09:00
bors
ee67c79598 Auto merge of #10835 - y21:drain-collect, r=dswij
new lint: `drain_collect`

Closes #10818.

This adds a new lint that looks for `.drain(..).collect()` and suggests replacing it with `mem::take`.

changelog: [`drain_collect`]: new lint
2023-06-16 04:53:35 +00:00
y21
3fe2478ecf don't unnecessarily walk more in visitor and add more tests 2023-06-15 22:04:25 +02:00
bors
cda13a8b26 Auto merge of #10946 - Centri3:match_same_arms, r=blyxyas,xFrednet
[`match_same_arms`]: don't lint if `non_exhaustive_omitted_patterns`

Fixes #10327

changelog: [`match_same_arms`]: Don't lint if `non_exhaustive_omitted_patterns` is `warn` or `deny`
2023-06-15 18:40:49 +00:00
y21
5821fbbc30 add test case for not whole length, move sugg into variable 2023-06-15 20:23:12 +02:00
y21
20ae597ec4 add a description 2023-06-15 20:23:12 +02:00
y21
3f3657a3e4 make clippy happy 2023-06-15 20:23:12 +02:00
y21
d2a6ec2d4d take into account reborrowing when inserting &mut in sugg 2023-06-15 20:23:12 +02:00
y21
2748ab9565 new lint: drain_collect 2023-06-15 20:23:11 +02:00
Centri3
10cc1684ce rename lint and disallow clone_from 2023-06-15 07:04:47 -05:00
Centri3
67d5e6ec39 add lint [needless_clone_impl]
Update needless_impls.rs
2023-06-15 07:04:36 -05:00
Centri3
a899034927 Don't lint excessive_precision on inf 2023-06-15 06:16:04 -05:00
bors
eee3112dc3 Auto merge of #10840 - Alexendoo:from-over-into-expanded-path, r=dswij
from_over_into: Show suggestions for non-Self expanded paths

changelog: [`from_over_into`]: Show suggestions when the body contains macros not expanding to `Self`

Currently any path in a macro expansion causes the suggestion to be hidden, meaning most macro calls cause it to be hidden

Now it's only hidden if the expansion contains `Self`
2023-06-15 07:14:40 +00:00
bors
2dd452f51b Auto merge of #10931 - y21:issue10000, r=Jarcho
[`unnecessary_fold`]: suggest turbofish if necessary

Fixes #10000

This adds turbofish `::<T>` to the suggestion in `unnecessary_fold`. This is necessary because the `Sum` trait is generic, which breaks inference when changing `fold()` to `sum()`.

changelog: [`unnecessary_fold`]: suggest turbofish if necessary
2023-06-15 05:45:41 +00:00
bors
823d9dd503 Auto merge of #10934 - Centri3:single_range_in_vec_init, r=giraffate
new lint [`single_range_in_vec_init`]

Lints on `vec![0..200]` (or `[0..200]`), suggesting either `(0..200).collect::<Vec<i32>>()` or `[0; 200]`.

Haven't tested it with anything that isn't primitive. Probably should!

Closes #10932

changelog: new lint [`single_range_in_vec_init`]
2023-06-14 23:57:03 +00:00
y21
d102e2296c move check_fold_with_op function out 2023-06-14 22:38:06 +02:00
y21
69e892e3a1 get rid of unnecessary function pointer 2023-06-14 22:29:57 +02:00
bors
ffe95252bd Auto merge of #10954 - y21:issue10158, r=llogiq
[`derivable_impls`]: don't lint if `default()` call expr unsize-coerces to trait object

Fixes #10158.

This fixes a FP where the derive-generated Default impl would have different behavior because of unsize coercion from `Box<T>` to `Box<dyn Trait>`:
```rs
struct S {
  x: Box<dyn std::fmt::Debug>
}
impl Default for S {
  fn default() -> Self {
    Self {
      x: Box::<()>::default()
     // ^~ Box<()> coerces to Box<dyn Debug>
     // #[derive(Default)] would call Box::<dyn Debug>::default()
    }
  }
}
```
(this intentionally only looks for trait objects `dyn` specifically, and not any unsize coercion, e.g. `&[i32; 5]` to `&[i32]`, because that breaks existing tests and isn't actually problematic, as far as I can tell)

changelog: [`derivable_impls`]: don't lint if `default()` call expression unsize-coerces to trait object
2023-06-14 16:59:26 +00:00
y21
4795c91939 fix internal lints 2023-06-14 17:15:57 +02:00
y21
fcb9a382f7 dogfood 2023-06-14 17:10:26 +02:00
y21
5b6ba204a7 fmt 2023-06-14 17:01:57 +02:00
y21
2ba1926955 [derivable_impls]: don't lint if expr unsize-coerces 2023-06-14 16:52:02 +02:00
Centri3
830d307d0a refactor a bit 2023-06-14 08:41:20 -05:00
Centri3
27a701a670 [match_same_arms]: don't lint if non_exhaustive_omitted_patterns
formatting :/
2023-06-14 08:36:09 -05:00
Kisaragi Marine
79f93a655a
missing_panics_doc: pickup expect method 2023-06-14 22:26:57 +09:00
Centri3
72aa180798 use rustc's criteria for a temporary 2023-06-14 06:56:38 -05:00
bors
1d0d686f10 Auto merge of #10950 - KisaragiEffective:ignore_main_in_notest_doc_block, r=xFrednet
[`needless_doctest_main`]: ignore `main()` in `no_test` code fences

close #10491

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

changelog: [`needless_doctest_main`]: ignore `main()` in `no_test` code fence
2023-06-14 10:09:57 +00:00
bors
a59236ffb4 Auto merge of #10919 - y21:issue10579, r=blyxyas,xFrednet
[`map_unwrap_or`]: don't lint when referenced variable is moved

Fixes #10579.

The previous way of checking if changing `map(f).unwrap_or(a)` to `map_or(a, f)` is safe had a flaw when the argument to `unwrap_or` moves a binding and the `map` closure references that binding in some way.

It used to simply check if any of the identifiers in the `unwrap_or` argument are referenced in the `map` closure, but it didn't consider the case where the moved binding is referred to through references, for example:
```rs
let x = vec![1, 2];
let x_ref = &x;
Some(()).map(|_| x_ref.clone()).unwrap_or(x);
```
This compiles as is, but we cannot change it to `map_or`. This lint however did suggest changing it, because the simple way of checking if `x` is referenced anywhere in the `map` closure fails here. The safest thing to do here imo (what this PR does) is check if the moved value `x` is referenced *anywhere* in the body (before the `unwrap_or` call). One can always create a reference to the value and smuggle them into the closure, without actually referring to `x`. The original, linked issue shows another one such example:
```rs
    let x = vec![1,2,3,0];
    let y = x.strip_suffix(&[0]).map(|s| s.to_vec()).unwrap_or(x);
```
`x.strip_suffix(&[0])` creates a reference to `x` that is available through `s` inside of the `map` closure, so we can't change it to `map_or`.

changelog: [`map_unwrap_or`]: don't lint when referenced variable is moved
2023-06-14 09:48:22 +00:00
bors
b9b453748d Auto merge of #10945 - Centri3:no_effect, r=llogiq
[`no_effect`]: Suggest adding `return` if applicable

Closes #10941

Unfortunately doesn't catch anything complex as `no_effect` already wouldn't, but I'm fine with that (it catches `ControlFlow` at least :D)

changelog: [`no_effect`]: Suggest adding `return` if statement has same type as function's return type and is the last statement in a block
2023-06-14 06:39:44 +00:00
Kisaragi Marine
062b209904
Ignore main() in no_test code fences 2023-06-14 12:31:49 +09:00
Centri3
d2725402a9 [borrow_as_ptr]: Ignore temporaries 2023-06-13 17:53:36 -05:00
Centri3
74a0c9c62f [needless_lifetimes]' suggestion now points at the lifetimes 2023-06-13 14:05:22 -05:00
Centri3
d255e7a53f [no_effect]: suggest adding return if applicable
make cargo test pass

Revert "Make it `Unspecified`"

This reverts commit 774863041c1878ab7fb6e27c1c61c04de0e25bc8.

Make it `Unspecified`
2023-06-13 13:23:33 -05:00
bors
72332b2598 Auto merge of #10944 - GuillaumeGomez:cleanup-needless-pass-by-value, r=xFrednet
Remove dead code in `needless_pass_by_value`

The `spans_need_deref` is never used so I removed it alongside all linked code as well.

changelog: none
2023-06-13 15:58:10 +00:00
Guillaume Gomez
bcaf655b70 Remove dead code in needless_pass_by_value 2023-06-13 17:08:51 +02:00
blyxyas
d5b2f11340
Now cargo collect-metadata updates the CHANGELOG.md 2023-06-13 16:52:18 +02:00
Centri3
357e80ea0d Ignore more type aliases in unnecessary_cast 2023-06-13 06:51:56 -05:00
bors
8a1f0cd765 Auto merge of #10935 - Alexendoo:needless-if-cases, r=Manishearth
Don't lint non-statement/faux empty `needless_if`s

Also has a basic fall-back for `if` statements that have attributes applied to them and incorporates https://github.com/rust-lang/rust-clippy/pull/10921#pullrequestreview-1474008780 while I was there

r? `@Manishearth`

changelog: none
2023-06-13 04:34:37 +00:00
bors
7c2bf28365 Auto merge of #10358 - pksunkara:unnecessary-unwrap, r=llogiq
Add `unnecessary_literal_unwrap` lint

Add lint for more unnecessary unwraps and suggest fixes for them.

Fixes #10352

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

r? `@llogiq`

---

changelog: New lint [`unnecessary_literal_unwrap`]
[#10358](https://github.com/rust-lang/rust-clippy/pull/10358)
<!-- changelog_checked -->
2023-06-12 18:04:22 +00:00
bors
da56c3502a Auto merge of #10933 - y21:issue2262-followup, r=Centri3
[`useless_vec`]: lint on `vec![_]` invocations that adjust to a slice

Fixes #2262 (well, actually my PR over at #10901 did do most of the stuff, but this PR implements the one last other case mentioned in the comments that my PR didn't fix)

Before this change, it would lint `(&vec![1]).iter().sum::<i32>()`, but not `vec![1].iter().sum::<i32>()`. This PR handles this case.
This also refactors a few things that I wanted to do in my other PR but forgot about.

changelog: [`useless_vec`]: lint on `vec![_]` invocations that adjust to a slice
2023-06-12 16:25:59 +00:00
Centri3
6702c7a7a6 Add lint [single_range_in_vec_init] 2023-06-12 11:09:52 -05:00
Pavan Kumar Sunkara
6e4c5561be Preserve type annotations when present 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
6e4dc93e24 Support suggesting panics 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
69af0e13b2 Recognize Err 2023-06-12 16:19:26 +01:00
rsdy
6e0e09c8f7 Track init and unwrap of expr 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
7ed7283e0f Recognize unwrap_or_else method 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
8f83502989 Recognize unwrap_or methods 2023-06-12 16:19:26 +01:00
rsdy
1d159e7d11 Recognize Ok 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
daf6197481 Implement the suggestion 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
21b88ce290 Implement the lint for expect 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
0b1bb5fbf3 Implement the lint 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
2902359b3c Add the lint to the lib 2023-06-12 16:19:26 +01:00
rsdy
5bb768177e Add hook 2023-06-12 16:19:26 +01:00
Pavan Kumar Sunkara
e707447a86 Boilerplate for the new lint 2023-06-12 16:19:26 +01:00
Alex Macleod
5e20a572ee Don't lint non-statement/faux empty needless_ifs 2023-06-12 15:19:00 +00:00
y21
b309875fd8 [useless_vec]: detect unnecessary vec![_] 2023-06-12 15:48:04 +02:00
bors
b095247ab6 Auto merge of #10911 - lochetti:fix_9657, r=Alexendoo
Don't linting `as_conversions` in proc macros

Don't linting `as_conversions` if code was generated by procedural macro.

This PR fixes https://github.com/rust-lang/rust-clippy/issues/9657

I implemented the fix changing the lint code to be a `LateLintPass` in order to be able to use the `is_from_proc_macro` out of the box. If the reviwer thinks that it would be better to do the other way (implementing `WithSearchPat`) just let me know. I might need some help in implementing it for the `ustc_ast::ast::Expr`

changelog: [`as_conversions`] avoiding warnings in macro-generated code
2023-06-12 12:28:36 +00:00
y21
de7d43bc61 make lint description easier to read, prevent ICE 2023-06-12 12:21:38 +02:00
y21
7aa4babb5c rename "drawbacks" to "known issues" 2023-06-12 12:21:38 +02:00
y21
6b232fdee9 use span_lint_and_note 2023-06-12 12:21:38 +02:00
y21
52c6ef77fd fmt 2023-06-12 12:21:38 +02:00
y21
760f91f895 cargo dev update_lints 2023-06-12 12:21:38 +02:00
y21
7312a93a06 new lint: large_stack_frames 2023-06-12 12:21:38 +02:00
Centri3
29c1c6e104 refactor and add link to issue 2023-06-12 03:22:01 -05:00
Centri3
95d1bff225 add to tests and configuration 2023-06-12 03:22:01 -05:00
Centri3
243943ff56 make it work for locals as well
oopos
2023-06-12 03:22:01 -05:00
Centri3
7cdd87ca4a ignore generics and allow arbitrary threshold 2023-06-12 03:22:01 -05:00
Centri3
03c8db048e make cargo test pass + example 2023-06-12 03:21:43 -05:00
Centri3
e2ecb132a5 rename the lint 2023-06-12 03:21:43 -05:00
Centri3
52cfc997af Add lint single_letter_idents 2023-06-12 03:21:43 -05:00
bors
903fe3b9f2 Auto merge of #10894 - Centri3:type_repetition_in_bounds, r=blyxyas,xFrednet
[`type_repetition_in_bounds`]: Don't lint on derived code

fixes #10504.

changelog: [`type_repetition_in_bounds`]: Don't lint on derived code
2023-06-12 07:18:39 +00:00
bors
841f2199e0 Auto merge of #10416 - Jarcho:explicit_iter_loop_ext, r=Manishearth
Extend `explicit_iter_loop` and `explicit_into_iter_loop`

fixes #1518

Some included cleanups
* Split `for_loop` test into different files for each lint (partially).
* Move handling of some `into_iter` cases from `explicit_into_iter`.

---

changelog: Enhancement: [`explicit_iter_loop`]: Now also handles types that implement `IntoIterator`.
[#10416](https://github.com/rust-lang/rust-clippy/pull/10416)

changelog: Sugg: [`explicit_into_iter_loop`]: The suggestion now works on mutable references.
[#10416](https://github.com/rust-lang/rust-clippy/pull/10416)
<!-- changelog_checked -->
2023-06-12 05:30:32 +00:00
bors
21e6235b4c Auto merge of #10921 - Centri3:needless_if, r=blyxyas,Manishearth
Add `needless_if` lint

first off: Sorry about the large diff. Seems a ton of tests do this (understandably so).

this is basically everything I wanted in #10868, while it doesn't lint *all* unnecessary empty blocks, it lints needless if statements; which are basically the crux of the issue (for me) anyway. I've committed code that includes this far too many times 😅 hopefully clippy can help me out soon

closes #10868

changelog: New lint [`needless_if`]
2023-06-12 04:18:50 +00:00
y21
c9daec2585 [unnecessary_fold]: suggest turbofish if necessary 2023-06-12 03:20:55 +02:00
y21
e305b0730f fix docs 2023-06-12 00:20:54 +02:00
y21
7280ad9f7b [redundant_closure_call]: handle nested closures 2023-06-11 23:54:48 +02:00
Centri3
108c04acf0 Stop visiting once it's found Let 2023-06-11 09:43:26 -05:00
Centri3
59bca098f9 don't lint on if let
don't lint on `if let`
2023-06-11 07:02:20 -05:00
Centri3
4c7bc1785d ignore more type aliases in unnecessary_cast
ignore more type aliases in unnecessary_cast
2023-06-11 06:59:01 -05:00
Centri3
b2bdc37a55 add description
add description
2023-06-11 05:46:18 -05:00
bors
e986b6444e Auto merge of #10917 - Centri3:module_inception, r=xFrednet
allow disabling module inception on private modules

Fixes #10842

changelog: Enhancement [`module_inception`]: Added `allow-private-module-inception` configuration.
[#10917](https://github.com/rust-lang/rust-clippy/pull/10917)
<!-- changelog_checked -->
2023-06-10 13:21:48 +00:00
Centri3
b303e2053c allow disabling module inception on private modules
allow disabling module inception on private modules
2023-06-10 08:09:07 -05:00
bors
9011c4d248 Auto merge of #10918 - Centri3:patch-2, r=xFrednet
Fix `excessive_nesting` example

whoops 😅

changelog: none
2023-06-10 13:06:44 +00:00
Centri3
26f50395ba Add needless_if lint 2023-06-10 06:51:03 -05:00
Urgau
edb3266b91 Drop uplifted clippy:cmp_nan 2023-06-10 11:13:01 +02:00
Jason Newcomb
949712c90a Reborrow mutable references in explicit_iter_loop 2023-06-09 21:40:03 -04:00
Jason Newcomb
482baf2bcc Fix explicit_into_iter_loop with mutable references 2023-06-09 21:40:03 -04:00