Commit graph

9766 commits

Author SHA1 Message Date
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
bors
d44ea7c5c5 Auto merge of #10785 - Centri3:diverting_sub_expression, r=Jarcho
Fix `diverging_sub_expression` not checking body of block

Fixes #10776

This also adds a warning to the test `ui/never_loop.rs`, not sure if this is correct or not.

changelog: [`diverging_sub_expression`]: Fix false negatives with body of block
2023-06-10 00:16:43 +00:00
y21
9d58a42623 [map_unwrap_or]: don't lint when referenced variable is moved 2023-06-10 01:38:04 +02:00
Jason Newcomb
b6fa4d43d3 Extend explicit_iter_loop to all types 2023-06-09 19:24:55 -04:00
Catherine
d1957b87c8
Update excessive_nesting.rs 2023-06-09 16:29:34 -05:00
Catherine
b7fedb88cf
Update excessive_nesting.rs 2023-06-09 16:28:01 -05:00
bors
476efe92e7 Auto merge of #10672 - Centri3:excessive-width-lints, r=Alexendoo
Add `excessive_nesting` lint

changelog: new lint [`excessive_nesting`]
2023-06-09 20:47:06 +00:00
Centri3
35aff1ae86 refactor 2023-06-09 15:32:42 -05:00
Centri3
c1c134a288 ensure there are no stmts for expr check 2023-06-09 11:44:59 -05:00
Centri3
0c545c7bcc also lint single expression blocks
Update mixed_read_write_in_expression.rs

Update diverging_sub_expression.stderr
2023-06-09 11:44:59 -05:00
bors
b356491a31 Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errors
Uplift `clippy::undropped_manually_drops` lint

This PR aims at uplifting the `clippy::undropped_manually_drops` lint.

## `undropped_manually_drops`

(warn-by-default)

The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop.

### Example

```rust
struct S;
drop(std::mem::ManuallyDrop::new(S));
```

### Explanation

`ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either.

-----

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

`@rustbot` label: +I-lang-nominated
r? compiler

-----

For Clippy:

changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2023-06-09 12:44:23 +00:00
bors
05de787089 Auto merge of #10913 - y21:issue10033, r=Manishearth,Centri3
[`unnecessary_to_owned`]: check that the adjusted type matches target

Fixes #10033.

Before this change, the lint would assume that removing the `.to_string()` in `f(&x.to_string())` would be ok if x is of some type that implements `Deref<Target = str>` and `f` takes a `&str`.
This turns out to not actually be ok if the `to_string` call is some method that exists on `x` directly, which happens if it implements `Display`/`ToString` itself.

changelog: [`unnecessary_to_owned`]: only lint if the adjusted receiver type actually matches
2023-06-09 08:52:44 +00:00
y21
dd084940de check that the adjusted receiver type matches target 2023-06-09 04:13:00 +02:00
bors
384cf37612 Auto merge of #10910 - Alexendoo:unnecessary-pointer-casts, r=llogiq
Ignore more pointer types in `unnecessary_cast`

Spotted this because

e2c655b4c0/tests/ui/suspicious_to_owned.rs (L9-L10)

currently fails on `aarch64-unknown-linux-gnu` as `c_char` is `u8` there

The current implementation checks for `as alias`, `as _`. This adds things like
- `as *const alias`
- `as *const cfg_dependant`
- `as *const _`

changelog: none
2023-06-08 19:38:12 +00:00
Alex Macleod
4346c992cb Ignore more pointer types in unnecessary_cast 2023-06-08 18:19:35 +00:00
Renato Lochetti
55c9100334
Don't ling as_conversions in proc macros 2023-06-08 19:04:35 +01:00
Alex Macleod
96697d2ee7 Fix useless_vec suggestion in for _ in vec![..] 2023-06-08 17:27:12 +00:00
bors
b7c330fc78 Auto merge of #10905 - y21:issue10684, r=Alexendoo
[`redundant_closure`]: special case inclusive ranges

Fixes #10684.

`x..=y` ranges need a bit of special handling in this lint because it desugars to a call to the lang item `RangeInclusiveNew`, where the callee span would be the same as the range expression itself, so the suggestion looked a bit weird. It now correctly suggests `RangeInclusive::new`.

changelog: [`redundant_closure`]: special case `RangeInclusive`
2023-06-08 12:15:35 +00:00
bors
60258b061d Auto merge of #10898 - avborhanian:master, r=Manishearth,Centri3
Adds new lint `arc_with_non_send_or_sync`

Fixes #653

Adds a new lint to check for uses of non-Send/Sync types within Arc.

```
changelog: [`arc_with_non_send_sync`]: Added a lint to detect uses of non-Send/Sync types within Arc.
```
2023-06-08 09:46:01 +00:00
Urgau
f47e9156a4 Drop uplifted clippy::undropped_manually_drops 2023-06-08 11:41:34 +02:00
avborhanian
20548eba6c Swapping to matches macro. 2023-06-08 00:38:18 -07:00
avborhanian
2f5d1c748a Adding extra check to ignore generic args. 2023-06-08 00:22:04 -07:00
Andrew Xie
737cba0c37 Whoops, submodule change was actually valid - undoing fixup 2023-06-08 01:05:38 -04:00
Andrew Xie
ecd6afaa12 fixup! Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems 2023-06-08 00:40:29 -04:00
Andrew Xie
f2f342adb4 Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few misc issues, added collect to UnordItems 2023-06-08 00:38:50 -04:00
bors
177c6fea1f Auto merge of #10901 - y21:smarter-useless-vec, r=Manishearth,Centri3
[`useless_vec`]: lint `vec!` invocations when a slice or an array would do

First off, sorry for that large diff in tests. *A lot* of tests seem to trigger the lint with this new change, so I decided to `#![allow()]` the lint in the affected tests to make reviewing this easier, and also split the commits up so that the first commit is the actual logic of the lint and the second commit contains all the test changes. The stuff that changed in the tests is mostly just line numbers now. So, as large as the diff looks, it's not actually that bad. 😅
I manually went through all of these to find out about edge cases and decided to put them in `tests/ui/vec.rs`.

For more context, I wrote about the idea of this PR here: https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-1579155257 (that explains the logic)

Basically, it now also considers the case where a `Vec` is put in a local variable and the user only ever does things with it that one could also do with a slice or an array. This should catch a lot more cases, and (at least from looking at the tests) it does.

changelog: [`useless_vec`]: lint `vec!` invocations when a slice or an array would do (also considering local variables now)
2023-06-08 04:33:26 +00:00
bors
9ca1344d9a Auto merge of #10904 - lochetti:fix_10273, r=Centri3
`suspicious_else_formatting`: Don't warn if there is a comment between else and curly bracket

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

The idea is that if the only thing after `else` and before `{` is a comment, we will not warn because, probably, the line break was "made" by rustfmt.

changelog: [`suspicious_else_formatting`]: Don't warn if the only thing between `else` and curly bracket is a comment
2023-06-08 04:18:08 +00:00
avborhanian
8330887e1b Updating documentation and lint formatting. 2023-06-07 20:53:52 -07:00
avborhanian
339cd14f27 Adds new lint arc_with_non_send_or_sync 2023-06-07 20:53:48 -07:00
Centri3
5da34559ee Check if from proc macro and better tests 2023-06-07 18:34:34 -05:00
Centri3
725399a178 move to complexity but don't lint by default 2023-06-07 18:34:34 -05:00
Centri3
378d77584a work with lint attributes 2023-06-07 18:34:34 -05:00
Centri3
493a23e957 check non-inline modules, ignore all macros 2023-06-07 18:34:34 -05:00
Centri3
88143ac295 decided against reinventing the wheel 2023-06-07 18:34:34 -05:00