Commit graph

6124 commits

Author SHA1 Message Date
Lukas Lueg
657b0da912 Add partialeq_to_none lint
Fixes #9275
2022-08-08 20:17:13 +02:00
Federico Guerinoni
f6cab94bd0 Rename logic_bug to overly_complex_bool_expr
Closes #1916
2022-08-08 18:38:39 +02:00
bors
4912c0ece4 Auto merge of #9126 - Jarcho:auto_deref_sugg, r=Manishearth
`explicit_auto_deref` changes

fixes #9123
fixes #9109
fixes #9143
fixes #9101

This avoid suggesting code which hits a rustc bug. Basically `&{x}` won't use auto-deref if the target type is `Sized`.

changelog: Don't suggest using auto deref for block expressions when the target type is `Sized`
changelog: Include the borrow in the suggestion for `explicit_auto_deref`
changelog: Don't lint `explicit_auto_deref` on `dyn Trait` return
changelog: Don't lint `explicit_auto_deref` when other adjustments are required
changelog: Lint `explicit_auto_deref` in implicit return positions for closures
2022-08-08 15:20:24 +00:00
Jason Newcomb
ecb51fe6a5 Lint explicit_auto_deref in implicit return positions for closures 2022-08-08 10:25:05 -04:00
Jason Newcomb
5285928bc0 Fix ICE when checking the HIR ty of closure args. 2022-08-08 10:09:05 -04:00
bors
0ee702514e Auto merge of #9303 - Jarcho:ice_9297, r=Alexendoo
Fix ICE when reading literals with weird proc-macro spans

fixes #9297
changelog: Fix ICE when reading literals with weird proc-macro spans
2022-08-08 11:36:27 +00:00
Jason Newcomb
99abd4a9f6 Fix ICE when reading literals with weird proc-macro spans 2022-08-07 22:22:17 -04:00
Jason Newcomb
670efd5720 Don't lint default_trait_access in proc-macro expansions 2022-08-07 21:55:08 -04:00
Jason Newcomb
4ae582ef88 Don't lint missing_docs_in_private_items on proc-macro output 2022-08-07 21:53:51 -04:00
Jason Newcomb
2ae8b300a7 Don't lint unit_arg when expanded from a proc-macro 2022-08-07 21:52:25 -04:00
Jason Newcomb
99e77d07b2 Allow type erasure using *const/mut int_type in transmute_undefined_repr 2022-08-07 17:58:31 -04:00
bors
5721ca9a13 Auto merge of #9294 - alex-semenyuk:enable_def_id_nocore_on_windows, r=xFrednet
Enable test for def_id_nocore for windows

Verified that it actully works on windows
changelog: none
2022-08-05 21:08:19 +00:00
alex-semenyuk
1e1193f4fa Enable test for def_id_nocore for windows 2022-08-05 23:24:50 +03:00
bors
57731f1dd7 Auto merge of #9292 - alex-semenyuk:typos_fixed, r=Alexendoo
Fix some typos

changelog: none
2022-08-05 09:19:07 +00:00
alex-semenyuk
f63b324ab1 Fix some typos 2022-08-05 00:59:21 +03:00
bors
2dc7d2f7f5 Auto merge of #9266 - alex-semenyuk:cast_abs_to_unsigned_paren_fix, r=Jarcho
Fix cast_abs_to_unsigned with code in parens

Close #9185
changelog: none
2022-08-04 18:45:32 +00:00
alex-semenyuk
0e1d65850a Fix cast_abs_to_unsigned generates non-compiling code when original code is in parens 2022-08-04 21:30:50 +03:00
alex-semenyuk
7062a013e7 Fix some typos 2022-08-04 19:53:07 +03:00
Michael Krasnitski
80f0f280df Extend if_then_some_else_none to also suggest bool::then_some 2022-08-03 23:18:59 -04:00
Jason Newcomb
b426bd52a1 Don't lint transmute_undefined_repr when the the first field of a repr(C) type is compatible with the other type 2022-08-03 14:41:32 -04:00
bors
71777465cc Auto merge of #9284 - lengyijun:typo, r=dswij
fix typo in tests/ui/redundant_allocation.rs

changelog: none
2022-08-03 10:33:45 +00:00
Fabian Wolff
f232402057 Warn about dead tuple struct fields 2022-08-03 12:17:23 +02:00
lengyijun
b50ba06a83 fix typo in tests/ui/redundant_allocation.rs 2022-08-03 04:57:36 +00:00
Daniel Macovei
503c03c558 clean up 2022-08-02 12:06:22 -05:00
Daniel Macovei
145ebb1cd7 add paren before '?' when suggesting deref 2022-08-02 10:39:35 -05:00
bors
05e7d5481b Auto merge of #9053 - AaronC81:fix-9052, r=flip1995
Fix suggestions for `async` closures in redundant_closure_call

Fixes #9052

changelog: Fix suggestions given by [`redundant_closure_call`] for async closures
2022-08-02 12:39:37 +00:00
Allen Hsu
3ddc04f4db Add extra test cases from #8771, #8757, #9076. 2022-08-02 22:00:04 +10:00
Allen Hsu
b96842d7d7 Split unfixable lints. 2022-08-02 22:00:04 +10:00
Allen Hsu
171d082433 Compare where predicates to trait bounds.
- only compare where predicates to trait bounds when generating where
  clause specific message to fix #9151
- use comparable_trait_ref to account for trait bound generics to fix #8757
2022-08-02 22:00:04 +10:00
bors
00e59cdad0 Auto merge of #9264 - guerinoni:instant-elapsed, r=Alexendoo
Add `elapsed_instant` lint

Closes #8603

- \[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`

---

changelog: [`elapsed_instant`]: Add lint
2022-08-02 11:16:47 +00:00
bors
367d09fc4e Auto merge of #9254 - alex-semenyuk:enable_empty_loop_no_std_on_windows, r=dswij
Enable test empty_loop_no_std on windows

Verified that it actully works on windows
changelog: none
2022-08-02 06:44:03 +00:00
Federico Guerinoni
0696624ba7 Add elapsed_instant lint
Closes #8603

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
2022-08-01 23:39:00 +02:00
bors
a5a6c95da8 Auto merge of #9273 - tabokie:assert_ok_fp, r=flip1995
Move [`assertions_on_result_states`] to restriction

Close #9263

This lint causes regression on readability of code and log output. And printing runtime values is not particularly useful for majority of tests which should be reproducible.

changelog: Move [`assertions_on_result_states`] to restriction and don't lint it for unit type

Signed-off-by: tabokie <xy.tao@outlook.com>
2022-08-01 12:16:45 +00:00
tabokie
48ad9d8bc7 do not apply [assertions_on_result_states] to unwrap unit type
Signed-off-by: tabokie <xy.tao@outlook.com>
2022-08-01 20:13:33 +08:00
bors
a591e725a6 Auto merge of #9223 - sgued:unwrap-expect-used, r=giraffate
unwrap_used: Don't recommend using `expect` when the `expect_used` lint is not allowed

Fixes #9222

```
changelog: [`unwrap_used`]: Don't recommend using `expect` when the `expect_used` lint is not allowed
```
2022-08-01 01:27:03 +00:00
Andy Caldwell
56c9cc458d
Add deprecation test for old configuration entry 2022-07-29 19:39:20 +01:00
Andy Caldwell
66b46749e6
Change lint name to plural 2022-07-29 19:35:39 +01:00
Andy Caldwell
2f48257cfb
Rename "blacklisted name" to "disallowed name" throughout 2022-07-29 19:35:18 +01:00
bors
53a09d4855 Auto merge of #9252 - Metaswitch:use-deprecated-config, r=Jarcho
Read and use deprecated configuration (as well as emitting a warning)

Original change written by `@flip1995` I've simply rebased to master and fixed up the formatting/tests.  This change teaches the configuration parser which config key replaced a deprecated key and attempts to populate the latter from the former.  If both keys are provided this fails with a duplicate key error (rather than attempting to guess which the user intended).

Currently this on affects `cyclomatic-complexity-threshold` -> `cognitive-complexity-threshold` but will also be used in #8974 to handle `blacklisted-names` -> `disallowed-names`.

```
changelog: deprecated configuration keys are still applied as if they were provided as their non-deprecated name.
```

- [x] `cargo test` passes locally
- [x] Run `cargo dev fmt`
2022-07-29 00:54:10 +00:00
Andy Caldwell
ea25ef10cf
Harden duplicates checking and add tests 2022-07-28 23:05:24 +01:00
Philipp Krones
67c405cc1d Merge commit '3c7e7dbc1583a0b06df5bd7623dd354a4debd23d' into clippyup 2022-07-28 19:08:22 +02:00
Philipp Krones
0905ec465d
Merge remote-tracking branch 'upstream/master' into rustup 2022-07-28 18:55:32 +02:00
alex-semenyuk
38e80132d5 Enable test empty_loop_no_std on windows 2022-07-28 10:57:01 +03:00
Philipp Krones
08e7ec4047
Read and use deprecated configuration (as well as emitting a warning)
Co-authored-by: Andy Caldwell <andycaldwell@microsoft.com>
2022-07-27 17:47:20 +01:00
bors
d72e5f2e10 Auto merge of #9241 - Jarcho:ice_9238, r=xFrednet
Fix ICE in `miri_to_const`

fixes #9238
changelog: Fix ICE when using `#![feature(generic_const_exprs)]` in various lints
2022-07-25 22:14:55 +00:00
bors
8882578a67 Auto merge of #9130 - c410-f3r:arith, r=llogiq
Add `Arithmetic` lint

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

r? `@llogiq`

changelog: Add `Arithmetic` lint
2022-07-25 21:26:15 +00:00
bors
c76db5c04e Auto merge of #9243 - Jarcho:std_core, r=Manishearth
Don't lint `std_instead_of_core` on `std::env`

fixes #9239

This also reorders the execution of the lint to do as little as possible in the case where the path doesn't start with `std` or `alloc`.

changelog: [`std_instead_of_core`](https://rust-lang.github.io/rust-clippy/master/#std_instead_of_core): Don't lint on `use std::env`
changelog: [`std_instead_of_alloc`](https://rust-lang.github.io/rust-clippy/master/#std_instead_of_alloc): Don't lint `use std::vec` twice
2022-07-25 15:19:41 +00:00
bors
1cce0477e4 Auto merge of #9225 - tabokie:assert_ok, r=Jarcho
add `[assertions_on_result_states]` lint

Close #9162

changelog: add `[assertions_on_result_states]` lint

Signed-off-by: tabokie <xy.tao@outlook.com>
2022-07-25 15:00:27 +00:00
tabokie
8454602cef Add [assertions_on_result_states] lint
Signed-off-by: tabokie <xy.tao@outlook.com>
2022-07-25 22:42:41 +08:00
bors
a14edd571e Auto merge of #9246 - kyoto7250:reopen_issue_8493, r=Jarcho
check macro statements in `[non_copy_const]`

close #8493
close #9224

This PR fixes false positives in `[non_copy_const]`.

changelog: fix false positives in`[non_copy_const]`

---

r? `@Jarcho`
2022-07-25 14:26:27 +00:00
kyoto7250
b6c301055e fixed tests to not use tokio 2022-07-25 23:04:18 +09:00
kyoto7250
477356460b check macro statements in non_copy_const.rs 2022-07-25 22:28:49 +09:00
bors
f847795bb2 Auto merge of #9245 - alex-semenyuk:enable_multiple_config_files_on_windows, r=Alexendoo
Enable test multiple_config_files on windows

Verified that it actully works on windows
changelog: none
2022-07-25 12:24:41 +00:00
alex-semenyuk
b5e5b42815 Enable test multiple_config_files on windows 2022-07-25 13:57:26 +03:00
Jason Newcomb
6bc024df18 Improve [std|alloc]_instead_of_[alloc|core] lints
* Don't call `TyCtxt::crate_name` unless necessary
* Don't lint on `use std::env`
* Only lint once on `use std::vec`
2022-07-24 23:15:39 -04:00
Jason Newcomb
2255cfd2ab Fix ICE in question_mark 2022-07-24 23:12:29 -04:00
Jason Newcomb
ab6463e9d9 Fix ICE in miri_to_const 2022-07-24 18:23:33 -04:00
Alex Macleod
d60d5e8bde Fix useless_format spans for format!("{foo}") 2022-07-24 16:47:17 +00:00
Michael Goulet
632f9945d6 Do not resolve associated const when there is no provided value 2022-07-22 18:58:07 +00:00
Sosthène Guédon
3e52031471 unwrap_used: Fix help, "an None" -> "None" 2022-07-22 19:14:58 +02:00
Sosthène Guédon
6ee03e2b01 unwrap_used: Stop recommending using expect when the expect_used lint is not allowed 2022-07-21 22:50:54 +02:00
bors
05a51e5730 Auto merge of #9214 - Jarcho:assign_op_prim, r=Manishearth
Check `assign_op_pattern` for conflicting borrows

fixes #9180

changelog: [`assign_op_pattern`](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern): Don't lint when the suggestion would cause borrowck errors.
2022-07-21 17:00:40 +00:00
bors
fa3c293db4 Auto merge of #9215 - alex-semenyuk:enable_test_entrypoint_recursion, r=Jarcho
Enable test for entrypoint_recursion for windows

Verified that this test actually works on windows
changelog: none
2022-07-21 15:45:50 +00:00
bors
bc903cd3c2 Auto merge of #9216 - smoelius:master, r=flip1995
Add `ui_cargo_toml_metadata` test

This PR adds a test to check the metadata of packages in the `ui_cargo` directory.

A recent change to Cargo causes it to warn when it finds multiple packages with the same name in a git dependency (the issue is described [here](https://github.com/rust-lang/cargo/issues/10752)).

Many (if  not all) Dylint libraries depend upon `clippy_utils`. As a result of the change, one now sees the following when building a Dylint library:
```
warning: skipping duplicate package `fail` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/module_style/pass_mod`
warning: skipping duplicate package `fail` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/module_style/fail_no_mod`
warning: skipping duplicate package `cargo_common_metadata` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_common_metadata/fail_publish_true`
warning: skipping duplicate package `fail-cargo` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/pass_cargo`
warning: skipping duplicate package `fail-clippy` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/fail_clippy`
warning: skipping duplicate package `fail-both-same` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/fail_both_same`
warning: skipping duplicate package `fail-file-attr` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/fail_file_attr`
```
There appear to be two contributing factors:
- Some packages in `ui_cargo` could have a `publish = false` added to them.
- Some packages in `ui_cargo` seem to be inconsistently named.

The new test checks that each package in the `ui_cargo` directory has a name matching one of its parent directories, and `publish = false` in its metadata (with a few exceptions).

Note that the packages in `cargo_common_metadata` require special care because `publish` is the subject of some of the `cargo_common_metadata` tests.

Also note that this PR adds `walkdir` as a dev dependency to the `clippy` package. However, it was already a dependency of `clippy_dev` and `lintcheck`. So hopefully this is acceptable.

Our continued thanks for making `clippy_utils` available, BTW. :)

r? `@flip1995`

changelog: none
2022-07-21 07:58:27 +00:00
alex-semenyuk
27d49b08d5 Enable test for entrypoint_recursion for windows 2022-07-20 21:41:12 +03:00
Jason Newcomb
a2f9b93116 Don't lint assign_op_pattern when the suggestion would cause borrowck errors 2022-07-20 10:23:07 -04:00
bors
7c8e1bff90 Auto merge of #9207 - Jarcho:todo_arm, r=giraffate
Check for `todo!` on every expression in `SpanlessEq`

fixes #9204
changelog: [`match_same_arms`](https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms): Don't lint on arms with `todo!`
2022-07-20 01:38:00 +00:00
Evan Typanski
40340745a8 Use parens around [needless_borrow] field calls 2022-07-19 15:17:24 -04:00
Jason Newcomb
95c759157c Check for todo! on every expression in SpanlessEq 2022-07-19 09:57:18 -04:00
Michael Goulet
30a9533570 Mention first and last macro in backtrace 2022-07-19 03:07:54 +00:00
Caio
31e5465f8a Add Arithmetic lint 2022-07-18 14:29:45 -03:00
bors
cce617165d Auto merge of #9148 - arieluy:then_some_unwrap_or, r=Jarcho
Add new lint `obfuscated_if_else`

part of #9100, additional commits could make it work with `then` and `unwrap_or_else` as well

changelog: Add new lint `obfuscated_if_else`
2022-07-18 12:45:11 +00:00
bors
bf70865cf4 Auto merge of #9199 - Xiretza:unused-self-exported-api, r=Jarcho
unused_self: respect avoid-breaking-exported-api

```
changelog: [`unused_self`]: Now respects the `avoid-breaking-exported-api` config option
```

Fixes #9195.

I mostly copied the implementation from `unnecessary_wraps`, since I don't have much understanding of rustc internals.
2022-07-18 12:29:22 +00:00
bors
f4c9183531 Auto merge of #9146 - arieluy:type_params, r=dswij
Fix `mismatching_type_param_order` false positive

changelog: Don't lint `mismatching_type_param_order` on complicated generic params

fixes #8962
2022-07-18 10:13:39 +00:00
Xiretza
7a5965b459 unused_self: respect avoid-breaking-exported-api 2022-07-18 10:57:08 +02:00
Philipp Krones
7d4daaa8fa Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyup 2022-07-18 09:39:37 +02:00
Samuel E. Moelius III
5b3300dc29 Add ui_cargo_toml_metadata test 2022-07-17 22:17:58 -04:00
Ariel Uy
9ff7c91100 Add new lint obfuscated_if_else
New lint suggests using `if .. else ..` instead of
`.then_some(..).unwrap_or(..)`.
2022-07-17 18:44:49 -07:00
Ariel Uy
8cf39a8c19 Fix mismatching_type_param_order false positive
Previously was giving false positive when an impl had a nontrivial
generic argument such as a tuple. Don't lint on these cases.
2022-07-17 11:23:09 -07:00
Jason Newcomb
d602ab1445 Don't lint exlipicit_auto_deref when other adjustments are needed 2022-07-17 11:14:08 -04:00
Jason Newcomb
84e03b6215 Don't lint explicit_auto_deref on dyn Trait return 2022-07-17 11:14:07 -04:00
Jason Newcomb
9ce0f82b8a Include the borrow in the suggestion for explicit_auto_deref 2022-07-17 11:14:07 -04:00
Jason Newcomb
c990e2922a Don't suggest using auto deref for block expressions 2022-07-17 11:14:07 -04:00
Caio
f88a1399bb Stabilize let_chains 2022-07-16 20:17:58 -03:00
Aaron Christiansen
4c43aa7053 Fix suggestion for async in redundant_closure_call
Fix redundant_closure_call for single-expression async closures

Add Sugg::asyncify

Use Sugg for redundant_closure_call implementation
2022-07-15 15:49:04 +01:00
bors
aa0706bf20 Auto merge of #9178 - alex-semenyuk:match_like_matches_macro_fix, r=Jarcho
match_like_matches_macro does not trigger when one arm contains conta…

Close #9163
changelog: none
2022-07-15 13:57:46 +00:00
bors
fe6814508f Auto merge of #9174 - flip1995:rustup, r=Jarcho
Rustup

r? `@ghost`

changelog: none
2022-07-15 13:38:01 +00:00
Philipp Krones
f074034590
Merge remote-tracking branch 'upstream/master' into rustup 2022-07-15 09:49:15 +02:00
alex-semenyuk
2894df3409 match_like_matches_macro does not trigger when one arm contains contains a block with only a bool literal 2022-07-15 09:15:31 +03:00
i509VCB
2f825db578
std_instead_of_core, std_instead_of_alloc, alloc_instead_of_core 2022-07-14 16:05:52 -05:00
bors
0f5a38f2d6 Auto merge of #9170 - Rqnsom:box_collection, r=Jarcho
[`box_collection`]: raise warn for all std collections

So far, only [`Vec`, `String`, `HashMap`] were considered.

Extend collection checklist for this lint with:
- `HashSet`
- `VecDeque`
- `LinkedList`
- `BTreeMap`
- `BTreeSet`
- `BinaryHeap`

changelog: [`box_collection`]: raise warn for all std collections
2022-07-14 13:02:06 +00:00
Ralf Jung
eee0bf459d add array tests, cleanup, tidy, and bless 2022-07-13 18:31:29 -04:00
bors
a7162f29b4 Auto merge of #9134 - Jarcho:while_let_iter_closure, r=dswij
Improve `while_let_on_iterator` suggestion inside an `FnOnce` closure

changelog: Improve `while_let_on_iterator` suggestion inside an `FnOnce` closure
2022-07-13 16:20:14 +00:00
Korlo
467e1b23aa box_collection: raise warn for all std collections
So far, only [Vec, String, Hashmap] were considered.

Extend collection checklist for this lint with:
- HashSet
- VecDeque
- LinkedList
- BTreeMap
- BTreeSet
- BinaryHeap
2022-07-13 17:02:09 +02:00
bors
0db9280783 Auto merge of #9159 - alex-semenyuk:fix_typos, r=dswij
Fix typos

changelog: none
2022-07-13 14:48:32 +00:00
bors
0930ac91b9 Fix typos
changelog: none
2022-07-13 14:48:32 +00:00
Alex Macleod
018684dd9a Use LazyLock for lint_message_convention regexes 2022-07-13 14:10:39 +00:00
bors
f78292a4ad Auto merge of #9156 - Rqnsom:manual_flatten, r=Alexendoo
fix [`manual_flatten`] help texts order

fixes  #8948

Whenever suggestion for this lint does not fit in one line,
legacy solution has some unexpected/unhandled behavior:
lint will then generate two help messages which seem to be shown in the wrong order.
The second help message in that case will contain the suggestion.

The first help message always refers to a suggestion message,
and **it should adapt** depending on the location of the suggestion:
- inline suggestion within the error/warning message
- suggestion separated into a second help text

This is my first contribution here, so I hope I didn't miss anything for creating this PR.

changelog: fix [`manual_flatten`] help texts order
2022-07-13 12:52:08 +00:00
Korlo
852c38c543 fix for manual_flatten help texts order
Whenever suggestion for this lint does not fit in one line,
lint will generate two help messages. The second help message
will always contain the suggestion.

The first help message refers to suggestion message,
and it should adapt depending on the location of the suggestion:
- inline suggestion within the error/warning message
- suggestion separated into second help text
2022-07-13 09:33:17 +02:00
bors
9ebacd4874 Auto merge of #8703 - aldhsu:add_repeated_where_clause_or_trait_bound, r=flip1995
Add `repeated_where_clause_or_trait_bound` lint

I thought I would try and scratch my own itch for #8674.

1. Is comparing the `Res` the correct way for ensuring we have the same trait?
2. Is there a way to get the spans for the bounds and clauses for suggestions?
I tried to use `GenericParam::bounds_span_for_suggestions` but it only gave me an empty span at the end of the spans.
I tried `WhereClause::span_for_predicates_or_empty_place` and it included the comma.
3. Is there a simpler way to get the trait names? I have used the spans of the traits because I didn't see a way to get it off the `Res` or `Def`.

changelog: Add ``[`repeated_where_clause_or_trait_bound`]`` lint.
2022-07-12 15:48:55 +00:00
Allen Hsu
8878d674b1 Lint for repeated traits within trait bounds or where clauses. 2022-07-12 22:03:55 +10:00
bors
3206fb4eb1 Auto merge of #9138 - Jarcho:branches_sharing_code_2, r=giraffate
Fixes for `branches_sharing_code`

fixes #7198
fixes #7452
fixes #7555
fixes #7589

changelog: Don't suggest moving modifications to locals used in any of the condition expressions in `branches_sharing_code`
changelog: Don't suggest moving anything after a local with a significant drop in `branches_sharing_code`
2022-07-12 00:38:54 +00:00
bors
8a62b6f523 Auto merge of #9144 - alex-semenyuk:or_fun_call_span_fix, r=giraffate
Fix span for or_fun_call

Closes #9033
changelog: [`or_fun_call`]: span points to the `unwrap_or` only instead of through the entire method chain expression
2022-07-11 09:03:20 +00:00
bors
7ea4592a8b Auto merge of #9056 - Jarcho:let_unit_indirect, r=llogiq
Allow `let_unit_value` in more cases

fixes #8998

changelog: Lint `let_unit_value` less aggressively when the type is specified
2022-07-10 18:58:09 +00:00
alex-semenyuk
97cd46fa33 Fix span for or_fun_call 2022-07-10 13:11:19 +03:00
Jason Newcomb
95b78799c3 Ignore the IntoIterator::into_iter call from for loops in significant_drop_in_scrutinee 2022-07-09 08:15:13 -04:00
Jason Newcomb
55563f9ce1 Fixes for branches_sharing_code
* Don't suggest moving modifications to locals used in any of the condition expressions
* Don't suggest moving anything after a local with a significant drop
2022-07-08 20:07:55 -04:00
bors
49f73e14a9 Auto merge of #8356 - J-ZhengLi:master-issue8288, r=dswij
Simplify if let statements

fixes: #8288

---

changelog: Allowing [`qustion_mark`] lint to check `if let` expressions that immediatly return unwrapped value
2022-07-08 16:12:00 +00:00
bors
d0b8f7508c Simplify if let statements
fixes: #8288

---

changelog: Allowing [`qustion_mark`] lint to check `if let` expressions that immediatly return unwrapped value
2022-07-08 16:12:00 +00:00
Matthias Krüger
1e033a9818 Rollup merge of #99026 - anall:buffix/clippy-9131, r=xFrednet
Add test for and fix rust-lang/rust-clippy#9131

This lint seems to have been broken by #98446 -- but of course, there was no clippy test for this case at the time.

`expr.span.ctxt().outer_expn_data()` now has `MacroKind::Derive` instead of `MacroKind::Attr` for something like:

```
#[derive(Clone, Debug)]
pub struct UnderscoreInStruct {
    _foo: u32,
}
```

---

changelog: none

closes: https://github.com/rust-lang/rust-clippy/issues/9131
2022-07-08 08:00:41 +02:00
bors
bee9da14cd Auto merge of #98482 - cjgillot:short-struct-span-closure, r=estebank
Shorten def_span of closures to just their header

Continuation of https://github.com/rust-lang/rust/pull/93967.
2022-07-08 03:05:15 +00:00
Jason Newcomb
9fa12def3c Improve while_let_on_iterator suggestion inside an FnOnce closure 2022-07-07 22:10:24 -04:00
Jason Newcomb
2872b7e0a4 Allow let () = .. as type inference for let_unit_value 2022-07-07 20:06:37 -04:00
Jason Newcomb
196174ddad Changes to let_unit_value
* View through locals in `let_unit_value` when determining if inference is required
* Don't remove typed let bindings for more functions
2022-07-07 20:06:36 -04:00
bors
54feac18d1 Auto merge of #8958 - Alexendoo:simple_filter_map, r=giraffate
Lint simple expressions in `manual_filter_map`, `manual_find_map`

changelog: Lint simple expressions in [`manual_filter_map`], [`manual_find_map`]

The current comparison rules out `.find(|a| a.is_some()).map(|b| b.unwrap())` because `a` being a reference can effect more complicated expressions, this adds a simple check for that case and adds the necessary derefs

There's some overlap with `option_filter_map` so `lint_filter_some_map_unwrap` now returns a `bool` to indicate it linted
2022-07-07 23:39:12 +00:00
Andrea Nall
782b484b79 Fix ICE in sugg::DerefDelegate with (named) closures
rustc comiler internals helpfully tell us how to fix the issue:

  to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`

Fixes ICE in #9041
2022-07-07 16:10:36 -05:00
Andrea Nall
3388787615 Add test for and fix rust-lang/rust-clippy#9131
This lint seems to have been broken by #98446
2022-07-07 19:30:37 +00:00
Dylan DPC
4f9933afbd Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, r=wesleywiser
Finishing touches for `#[expect]` (RFC 2383)

This PR adds documentation and some functionality to rustc's lint passes, to manually fulfill expectations. This is needed for some lints in Clippy. Hopefully, it should be one of the last things before we can move forward with stabilizing this feature.

As part of this PR, I've also updated `clippy::duplicate_mod` to showcase how this new functionality can be used and to ensure that it works correctly.

---

changelog: [`duplicate_mod`]: Fixed lint attribute interaction

r? `@wesleywiser`

cc: https://github.com/rust-lang/rust/issues/97660, https://github.com/rust-lang/rust/issues/85549

And I guess that's it. Here have a magical unicorn 🦄
2022-07-07 18:06:50 +05:30
Alex Macleod
307b8cd825 Lint simple expressions in manual_filter_map, manual_find_map 2022-07-07 11:51:42 +00:00
Marcel Hellwig
ead2c4f122 fix incorrect suggestion for maybe trait bounds 2022-07-07 12:43:16 +02:00
Camille GILLOT
347d999b97 Shorten span for closures. 2022-07-07 09:27:42 +02:00
bors
afb34eb261 Auto merge of #9096 - Jarcho:needless_borrow_subs, r=Manishearth
Fix `needless_borrow` 9095

fixes #9095
changelog: Don't lint `needless_borrow` on method receivers when it would change which trait impl is called
2022-07-06 21:26:46 +00:00
xFrednet
0d443d17eb Fix #[expect] and #[allow] for clippy::duplicate_mod 2022-07-06 22:01:40 +02:00
Takayuki Maeda
e34ee2484b fix miri-opt tests 2022-07-06 19:09:50 +09:00
bors
f93d418f17 Auto merge of #9099 - joshtriplett:unnecessary-lazy-eval-then-some, r=flip1995
Extend unnecessary_lazy_eval to cover `bool::then` -> `bool::then_some`

fixes #9097

changelog: Extend `unnecessary_lazy_eval` to convert `bool::then` to `bool::then_some`
2022-07-06 09:20:55 +00:00
Josh Triplett
528308b5aa Extend unnecessary_lazy_eval to cover bool::then -> bool::then_some 2022-07-06 00:48:51 -07:00
Jason Newcomb
3db0e00bdc Lint shadow_* lints in anon const blocks 2022-07-05 15:21:27 -04:00
bors
462136ac68 Auto merge of #9121 - alex-semenyuk:fix_ui_test_cast_32_bits, r=flip1995
Fix stderr for cast_size_32bit

changelog: fix stderr for cast_size_32bit
2022-07-05 08:57:12 +00:00
alexey semenyuk
2ccb05487c
Fix stderr for cast_size_32bit 2022-07-05 09:43:29 +03:00
bors
48e527e4bd Auto merge of #9117 - Jarcho:unsafe_block_closure, r=giraffate
Fix `undocumented_unsafe_blocks` in closures

fixes #9114
changelog: Fix `undocumented_unsafe_blocks` not checking for comments before the start of a closure
2022-07-05 00:20:33 +00:00
Jason Newcomb
975667945c Fix undocumented_unsafe_blocks in closures 2022-07-04 13:53:42 -04:00
Alex Macleod
fec4593082 new_without_default: ignore const generics/lifetime params on fn new 2022-07-04 14:03:11 +00:00
bors
b15f06e74f Auto merge of #9093 - Jarcho:deref_ice, r=giraffate
Fix ICE in `dereference.rs`

fixes #9089
changelog: Fix ICE when dereferencing or borrowing on explicit returns from closures
2022-07-04 00:22:17 +00:00
Serial
de646e10db Add invalid_utf8_in_unchecked 2022-07-03 15:37:30 -04:00
Jason Newcomb
988b813649 Use correct substitutions when checking if needless_borrow can apply to a method receiver 2022-07-02 15:48:46 -04:00
Jason Newcomb
3e80d3988d Fix ICE in dereference.rs 2022-07-02 00:59:58 -04:00
Camille GILLOT
d5e33d3ded Shorten def_span for more items. 2022-07-01 17:39:19 +02:00
Alex Macleod
a5b70a4c1d Fix allow attributes in let_unit_value 2022-07-01 12:14:28 +00:00
bors
d4488a520a Auto merge of #9039 - Serial-ATA:dev-dogfood, r=giraffate
Add `cargo dev dogfood`

changelog: Add `cargo dev dogfood`

Part of #5394
2022-07-01 01:07:25 +00:00
dAxpeDDa
b7051077c9
Fix false-positive in equatable_if_let 2022-06-30 17:45:34 +02:00
Alex Macleod
6c61f7106f Uncomment test for #8734 2022-06-30 10:13:54 +00:00
Philipp Krones
09f5df5087 Merge commit '0cb0f7636851f9fcc57085cf80197a2ef6db098f' into clippyup 2022-06-30 10:50:09 +02:00
Philipp Krones
f26cf11fe8
Merge remote-tracking branch 'upstream/master' into rustup 2022-06-30 10:27:25 +02:00
Jason Newcomb
adbc8499d3 Don't lint while_let_loop when drop order would change 2022-06-29 13:43:05 -04:00
bors
70f1d0d8fd Auto merge of #9043 - dswij:9037-test, r=Manishearth
`extra_unused_lifetimes` add FP test case emitting from derived attributes.

Add test to cover for #9014 which is fixed in #9037.

changelog: [`extra_unused_lifetimes`] Add FP test case emitting from derived attributes.

---

Seeing the FP from the test:

```sh
$ git revert -m 1 1d1ae10876
$ TESTNAME=extra_unused_lifetime cargo uitest
```
2022-06-29 15:09:37 +00:00
bors
90227c10f7 Auto merge of #8981 - PrestonFrom:more_details_for_significant_drop_lint, r=flip1995
Add details about how significant drop in match scrutinees can cause deadlocks

Adds more details about how a significant drop in a match scrutinee can cause a deadlock and include link to documentation.

changelog: Add more details to significant drop lint to explicitly show how temporaries in match scrutinees can cause deadlocks.
2022-06-29 13:23:21 +00:00
bors
4995b4e584 Auto merge of #9046 - xFrednet:rust-97660-expection-something-something, r=Jarcho
Fix `#[expect]` for most clippy lints

This PR fixes most `#[expect]` - lint interactions listed in rust-lang/rust#97660. [My comment in the issue](https://github.com/rust-lang/rust/issues/97660#issuecomment-1147269504) shows the current progress (Once this is merged). I plan to work on `duplicate_mod` and `multiple_inherent_impl` and leave the rest for later. I feel like stabilizing the feature is more important than fixing the last few nits, which currently also don't work with `#[allow]`.

---

changelog: none

r? `@Jarcho`

cc: rust-lang/rust#97660
2022-06-28 18:28:38 +00:00
bors
a4130e1612 Auto merge of #8355 - Jarcho:explicit_auto_deref_2, r=flip1995
Add lint `explicit_auto_deref` take 2

fixes: #234
fixes: #8367
fixes: #8380

Still things to do:

* ~~This currently only lints `&*<expr>` when it doesn't trigger `needless_borrow`.~~
* ~~This requires a borrow after a deref to trigger. So `*<expr>` changing `&&T` to `&T` won't be caught.~~
* The `deref` and `deref_mut` trait methods aren't linted.
* Neither ~~field accesses~~, nor method receivers are linted.
* ~~This probably shouldn't lint reborrowing.~~
* Full slicing to deref should probably be handled here as well. e.g. `&vec[..]` when just `&vec` would do

changelog: new lint `explicit_auto_deref`
2022-06-28 18:09:26 +00:00
Jason Newcomb
0adb3c0518 Move EqOp into Operators lint pass 2022-06-28 12:51:29 -04:00
Jason Newcomb
85c1f74fef Add explicit_auto_deref test for variadic function 2022-06-28 12:48:50 -04:00
Jason Newcomb
6d21b79be9 Fix needless_borrow suggestion when calling a trait method taking self 2022-06-28 12:48:27 -04:00
Jason Newcomb
0b4ba734cb Refactor dereference.rs
Merge `Position` and `AutoDerefStability`
2022-06-28 12:48:26 -04:00
Jason Newcomb
0204b95357 Lint explicit_auto_deref immediately after needless_borrow 2022-06-28 12:48:26 -04:00
Jason Newcomb
65bc6cb8bf Lint explicit_auto_deref without a leading borrow 2022-06-28 12:48:26 -04:00
Jason Newcomb
20ea26234a Lint field accesses in explicit_auto_deref 2022-06-28 12:48:26 -04:00
Jason Newcomb
a187d6412b Merge different parent walking loops in dereference.rs
`needless_borrow` will now walk further to find the target type.
2022-06-28 12:48:26 -04:00
Jason Newcomb
ee532c0222 Don't lint explicit_auto_deref on reborrows 2022-06-28 12:48:26 -04:00
Jason Newcomb
8a74d33570 Add explicit_auto_deref lint 2022-06-28 12:48:24 -04:00
xFrednet
d11618e6fa
Update boxed_local expect attribute location 2022-06-28 12:38:52 +02:00
bors
b776fb8294 Auto merge of #8774 - hellow554:cargo-rust-version, r=flip1995
try reading rust-version from Cargo.toml

Cargo.toml can contain a field `rust-version`, that acts like a MSRV of
clippy.toml file: https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field
This will try to read that field and use it, if the clippy.toml config
has no `msrv` entry

changelog: respect `rust-version` from `Cargo.toml`

closes #8746
closes #7765
2022-06-28 07:27:08 +00:00
bors
373bb573af Auto merge of #8639 - Jarcho:trivially_copy_pass_by_ref_5953, r=dswij
`trivially_copy_pass_by_ref` fixes

fixes #5953
fixes #2961

The fix for #5953 is overly aggressive, but the suggestion is so bad that it's worth the false negatives. Basically three things together:
* It's not obviously wrong
* It compiles
* It may actually work when tested

changelog: Don't lint `trivially_copy_pass_by_ref` when unsafe pointers are used.
changelog: Better track lifetimes when linting `trivially_copy_pass_by_ref`.
2022-06-28 07:03:57 +00:00
Marcel Hellwig
f0a1cd5645 add uitests for cargo rust-version field 2022-06-28 08:04:10 +02:00
Marcel Hellwig
6384765665 parse Cargo.toml file in ui-cargo tests
compiletest_rs is not meant to test full cargo projects, but instead
only files.
So we need to parse the `Cargo.toml` file ourself and set the
corresponding environment variable. In this case we just set
`CARGO_PKG_RUST_VERSION`, nothing more. But, of course, this can be
extended.
2022-06-28 08:03:48 +02:00
Preston From
3cfd1e5233 Make messages more accurate, check lint enabled 2022-06-27 22:52:22 -06:00
bors
fdd0e727e2 Auto merge of #8649 - ebobrow:imperative_find, r=flip1995
add [`manual_find`] lint for function return case

part of the implementation discussed in #7143

changelog: add [`manual_find`] lint for function return case
2022-06-27 17:15:25 +00:00
Jason Newcomb
c10101cf1c Don't lint trivially_copy_pass_by_ref when unsafe pointers are used 2022-06-27 13:14:27 -04:00
Jason Newcomb
2315f76f9d Actually check lifetimes in trivially_copy_pass_by_ref 2022-06-27 13:14:25 -04:00
bors
eaa03ea911 Auto merge of #8972 - kyoto7250:use_retain, r=llogiq
feat(new lint): new lint `manual_retain`

close #8097

This PR is  a new  lint implementation.
This lint checks if the `retain` method is available.

Thank you in advance.

changelog: add new ``[`manual_retain`]`` lint
2022-06-27 13:58:26 +00:00
Klim Tsoutsman
65f700fa89
Fix let_undescore_lock false-positive when binding without locking
Signed-off-by: Klim Tsoutsman <klimusha@gmail.com>
2022-06-27 20:35:26 +10:00
bors
57e7e1d7d8 Auto merge of #8871 - Serial-ATA:cargo-dev-deprecate, r=giraffate
Add `cargo dev deprecate`

changelog: none

I wrote this awhile ago when `regex` was still a dependency. Is it alright to add it back?
2022-06-27 00:32:22 +00:00
bors
88da5f2bb3 Auto merge of #8939 - Jarcho:transmute_ptr_to_ref_lt, r=giraffate
Suggest `pointer::cast` when possible in `transmute_ptr_to_ref`

fixes #8924

changelog: Suggest casting the pointer for any type containing lifetimes in `transmute_ptr_to_ref`.
changelog: Suggest `pointer::cast` when possible in `transmute_ptr_to_ref`.
2022-06-27 00:05:50 +00:00
kyoto7250
dd3d0fdad3 rename use_retain => manual_retain 2022-06-27 08:11:58 +09:00
kyoto7250
4decfdec76 check msrv 2022-06-27 08:11:58 +09:00
kyoto7250
fd629c0cde check method 2022-06-27 08:11:58 +09:00
kyoto7250
5f2b8e67b3 feat(new lint): new lint use_retain 2022-06-27 08:11:58 +09:00
bors
9b150625a9 Auto merge of #9032 - kyoto7250:issue_9018, r=llogiq
enum_variant_names should ignore when all prefixes are _

close #9018

When Enum prefix is only an underscore, we should not issue warnings.

changelog: fix false positive in enum_variant_names
2022-06-26 16:11:06 +00:00
bors
8789f4e88a Auto merge of #8985 - botahamec:single-match-option, r=llogiq
Lint `[single_match]` on `Option` matches

fixes #8928

changelog: did some cleanup of the logic for ``[`single_match`]`` and ``[`single_match_else`]`` which fixes the bug where `Option` matches were not linted unless a wildcard was used for one of the arms.
2022-06-25 16:48:34 +00:00
xFrednet
6427ba4855
Fix #[expect] for clippy::manual_non_exhaustive 2022-06-25 14:37:51 +02:00
xFrednet
ae4900c9b8
Fix #[expect] for clippy::macro_use_imports 2022-06-25 14:37:50 +02:00
xFrednet
79fc2716dc
Fix #[expect] for unnecessary_unwrap, panicking_unwrap 2022-06-25 14:21:24 +02:00
xFrednet
bdc6ece1b6
Fix #[expect] for clippy::needless_return 2022-06-25 14:16:31 +02:00
xFrednet
54ad99b6e5
Fix #[expect] for clippy::implicit_return 2022-06-25 14:16:31 +02:00
xFrednet
b2976980b5
Fix #[expect] for clippy::boxed_local 2022-06-25 14:16:30 +02:00
xFrednet
b6ee6bba4c
Fix #[expect] for clippy::nonminimal_bool 2022-06-25 14:16:30 +02:00
xFrednet
a3c7101f61
Fix #[expect] for clippy::logic_bug 2022-06-25 14:16:30 +02:00
xFrednet
811d73a2b7
Test #[expect] for redundant_clone 2022-06-25 14:16:29 +02:00
xFrednet
e7c55a478f
Fix #[expect] for clippy::ptr_arg 2022-06-25 14:16:28 +02:00
Jason Newcomb
7cdaabc9b7 Suggest pointer::cast when possible in transmute_ptr_to_ref
Defensively add a cast to any type with lifetimes.
2022-06-25 07:55:30 -04:00
bors
93ebd0e2db Auto merge of #9015 - kyoto7250:issue_8493, r=Jarcho
ignore item in `thread_local!` macro

close #8493

This PR ignores `thread_local` macro in `declare_interior_mutable_const`.

changelog: ignore `thread_local!` macro in `declare_interior_mutable_const`
2022-06-25 02:40:30 +00:00
Serial
aec465cabd Add test for [default_deprecation_reason] 2022-06-24 14:11:24 -04:00
bors
e17864e2ff Auto merge of #9031 - evantypanski:manual_rem_euclid, r=Jarcho
Add [`manual_rem_euclid`] lint

Closes #8883

Adds a lint for checking manual use of `rem_euclid(n)`

changelog: Add [`manual_rem_euclid`] lint
2022-06-24 17:49:53 +00:00
dswij
a8f68240d3 Add test for extra_unused_lifetimes FP on derive
This commit adds test for a `extra_unused_lifetimes` false positive from derive (#9014).

The fix for the FP is introduced in #9037.
2022-06-24 18:07:59 +08:00
bors
f7189846be Auto merge of #8953 - DevAccentor:slow_vector_initialization, r=Manishearth
add vec.capacity() to [`slow_vec_initialization`] detection

fix #8800

for example
```rust
let mut vec1 = Vec::with_capacity(len);
vec1.resize(vec1.capacity(), 0);

let mut vec2 = Vec::with_capacity(len);
vec2.extend(repeat(0).take(vec2.capacity()));
```
will trigger the lint

---

changelog: add `vec.capacity()` to [`slow_vec_initialization`] detection
2022-06-23 22:29:52 +00:00
Evan Typanski
df26c3f551 Add external macro guard and test middle MSRV 2022-06-23 16:49:31 -04:00
Serial
d42af68e03 Add cargo dev dogfood 2022-06-23 12:16:34 -04:00
Preston From
1f707db0bf Update messages for clarity when linting 2022-06-22 22:34:49 -06:00
bors
6985e6592b Auto merge of #9028 - kyoto7250:issue_8798, r=xFrednet
confirm  using chain in collapsible_span_lint_calls

close #8798

This PR fixes false positive when using chain in `collapsible_span_lint_calls`.

changelog: None
2022-06-22 22:35:21 +00:00
Evan Typanski
61e1870aff Add MSRV check for const rem_euclid 2022-06-22 14:23:04 -04:00
Evan Typanski
90f8277fe3 Fix case for function params 2022-06-22 14:23:04 -04:00
Evan Typanski
93e41d3305 Fix case where rem was considered commutative 2022-06-22 14:23:04 -04:00