Commit graph

6060 commits

Author SHA1 Message Date
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
kyoto7250
ab645bb081 enum_variant_names should ignore when all prefixes are _ 2022-06-22 08:32:54 +09:00
Evan Typanski
6e1df4732b Fix case where suggestion errored for infer type 2022-06-21 16:41:36 -04:00
Evan Typanski
e5ebd3edab Implement manual_rem_euclid lint 2022-06-21 14:13:15 -04:00
Preston From
2476100c85 Add details about significant drop in match scrutinees causing deadlocks
Adds more details about how a significant drop in a match scrutinee can
cause a deadlock and include link to documentation. Emits messages
indicating temporaries with significant drops in arms of matches and
message about possible deadlocks/unexpected behavior.

changelog: Add more details to significant drop lint to explicitly show
how temporaries in match scrutinees can cause deadlocks/unexpected
behavior.
2022-06-20 23:59:15 -06:00
Marcel Hellwig
6fc84d4da3 put parentheses around neg_multiply suggestion if needed 2022-06-20 23:47:53 +02:00
bors
93c6f9ebed Auto merge of #9006 - kyoto7250:issue-8836-v2, r=Jarcho
feat(fix): ignore `todo!` and `unimplemented!` in `if_same_then_else`

close: #8836
take over:  #8853

This PR adds  check `todo!` and `unimplemented!` in if_same_then_else.
( I thought `unimplemented` should not be checked as well as todo!.)

Thank you in advance.

changelog: ignore todo! and unimplemented! in if_same_then_else

r? `@Jarcho`
2022-06-20 15:08:32 +00:00
Alex Macleod
a0b107bbb6 unused_async: lint async methods 2022-06-20 12:03:27 +00:00
kyoto7250
4a4b5cf061 confirm using chain in collapsible_span_lint_calls 2022-06-20 13:17:54 +09:00
kyoto7250
46d056e2eb check last statement 2022-06-20 11:05:40 +09:00
Maybe Waffle
ee37029afa remove last use of MAX_SUGGESTION_HIGHLIGHT_LINES 2022-06-20 00:25:07 +04:00
Maybe Waffle
9395c261d6 remove span_lint_and_sugg_for_edges from clippy utils 2022-06-19 23:21:14 +04:00
Matthias Krüger
4737e9e42b Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se
once cell renamings

This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128

- Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`
- Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}`

(I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc)

```@rustbot``` label +T-libs-api -T-libs
2022-06-19 00:17:13 +02:00
Alex Macleod
eeedf72c33 Use RefCell in needless_return tests 2022-06-18 16:36:47 +00:00
kyoto7250
a9215d90c8 ignore item in thread_local! 2022-06-18 21:02:47 +09:00
kyoto7250
7a83809c8c check only first statement 2022-06-18 17:49:03 +09:00
bors
e933bb6bc3 Auto merge of #8989 - kyoto7250:default_iter_empty, r=Alexendoo
feat(lint): add default_iter_empty

close #8915

This PR adds `default_iter_empty` lint.

This lint checks `std::iter::Empty::default()` and replace with `std::iter::empty()`.

Thank you in advance.

---

changelog: add `default_instead_of_iter_empty` lint.
2022-06-17 21:06:09 +00:00
bors
09c93018d7 Auto merge of #97892 - klensy:fix-spaces, r=oli-obk
diagnostics: remove trailing spaces

Remove few occurrences of trailing spaces and drive by fix of needless alloc of const string.
2022-06-17 17:30:16 +00:00
kyoto7250
2bb8c45026 feat(lint): add default_iter_empty
Update description in clippy_lints/src/default_iter_empty.rs

Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>

Update clippy_lints/src/default_iter_empty.rs

Co-authored-by: Alex Macleod <alex@macleod.io>

Update clippy_lints/src/default_iter_empty.rs

Co-authored-by: Alex Macleod <alex@macleod.io>

renamed default_iter_empty to default_instead_of_iter_empty

Avoid duplicate messages

add tests for regression

rewrite 'Why is this bad?'

cargo dev fmt

delete default_iter_empty lint in renamed_lint.rs

rewrite a message in the suggestion

cargo dev update_lints --check
2022-06-17 21:34:36 +09:00
Dylan DPC
51e2d6a4a9 Rollup merge of #97798 - WaffleLapkin:allow_for_suggestions_that_are_quite_far_away_from_each_other, r=estebank
Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown

This is an attempt to fix suggestions one part of which is 6 lines or more far from the first. I've noticed "the problem" (of not showing some parts of the suggestion) here: https://github.com/rust-lang/rust/pull/97759#discussion_r889689230.

I'm not sure about the implementation (this big closure is just bad and makes already complicated code even more so), but I want to at least discuss the result.

Here is an example of how this changes the output:

Before:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
5 |
6 |
7 |
8 |
...
```

After:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
...
31|
32~ } };
  |
```

r? `@estebank`
`@rustbot` label +A-diagnostics +A-suggestion-diagnostics
2022-06-17 12:21:48 +02:00
Maybe Waffle
f095f802dc Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
flip1995
f8f9d01c2a Merge commit 'd7b5cbf065b88830ca519adcb73fad4c0d24b1c7' into clippyup 2022-06-16 17:39:06 +02:00
flip1995
c5c8f6122f
Merge remote-tracking branch 'upstream/master' into rustup 2022-06-16 16:04:06 +02:00
Maybe Waffle
4d88993544 bless clippy ui tests 2022-06-16 18:00:32 +04:00
klensy
922ff84baf bless clippy tests 2022-06-16 15:51:12 +03:00
kyoto7250
7cb4cef123 feat(fix): ignore todo! and unimplemented! in if_same_then_else 2022-06-16 21:38:47 +09:00
Dany Marcoux
9306e9a4df Ignore bodies containing todo!() in clippy::if_same_then_else 2022-06-16 00:36:56 +09:00
andylizi
a8370d4460
Fix false positive for never_loop struct expression fields 2022-06-15 18:02:59 +08:00
bors
844c06a7c7 Auto merge of #8964 - tamaroning:read_zero_byte_vec, r=dswij
Warn about read into zero-length `Vec`

Closes #8886

- \[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: none
2022-06-15 06:16:14 +00:00
Alex Macleod
08cfb8ddc3 Remove error-pattern comments 2022-06-14 16:28:34 +00:00
tamaron
14478bb94b add lint 2022-06-14 23:30:43 +09:00
bors
5a45805db5 Auto merge of #8947 - Serial-ATA:lint-produces-output, r=xFrednet
Add lint output to lint list

changelog: Add the ability to show the lint output in the lint list

This just adds the logic to produce the output, it hasn't been added to any lints yet. It did help find some mistakes in some docs though 😄.

### Screenshots

<details>
<summary>A single code block</summary>

![single-code-block](https://user-images.githubusercontent.com/69764315/172013766-145b22b1-1d91-4fb8-9cd0-b967a52d6330.png)
</details>

<details>
<summary>A single code block with a "Use instead" section</summary>

![with-usage](https://user-images.githubusercontent.com/69764315/172013792-d2dd6c9c-defa-41e0-8c27-8e8e311adb63.png)
</details>

<details>
<summary>Multiple code blocks</summary>

![multi-code-block](https://user-images.githubusercontent.com/69764315/172013808-5328f59b-e7c5-4914-a396-253822a6d350.png)
</details>

This is the last task in #7172 🎉.
r? `@xFrednet` (?)
2022-06-14 10:42:09 +00:00
bors
c07cbb9ea6 Auto merge of #8901 - Jarcho:sharing_code, r=dswij
Rework `branches_sharing_code`

fixes #7378

This changes the lint from checking pairs of blocks, to checking all the blocks at the same time. As such there's almost none of the original code left.

changelog: Don't lint `branches_sharing_code` when using different binding names
2022-06-14 08:59:40 +00:00
Micha White
01c75e4b98
Added tests for Cow and Result 2022-06-10 13:12:02 -04:00
Micha White
6d6c63ee23
Lint single_match with Options, Results, and Cows 2022-06-10 13:11:50 -04:00
Alex Macleod
eae9c56aab Add tests for some fixed redundant_closure issues 2022-06-10 13:25:22 +00:00
bors
b3c94c0828 Auto merge of #8976 - xFrednet:rust-97660-catch-emissions-with-expect, r=Jarcho
Fix some `#[expect]` lint interaction

Fixing the first few lints that aren't caught by `#[expect]`. The root cause of these examples was, that the lint was emitted at the wrong location.

---

changelog: none

r? `@Jarcho`

cc: rust-lang/rust#97660
2022-06-09 22:28:36 +00:00
xFrednet
9d201d68b4
Fix #[expect] for default_numeric_fallback 2022-06-09 09:17:46 +02:00
bors
919cf5083b Auto merge of #8907 - kyoto7250:fix_8898, r=giraffate
fix(lint): check const context

close: https://github.com/rust-lang/rust-clippy/issues/8898

This PR fixes a bug in checked_conversions.

Thank you in advance.

changelog: check const context in checked_conversions.
2022-06-09 00:04:09 +00:00
bors
50541b90e9 Auto merge of #8950 - Jarcho:derive_non_pub, r=dswij
Fixes for `derive_partial_eq_without_eq`

fixes  #8875

changelog: Don't lint `derive_partial_eq_without_eq` on non-public types
changelog: Better handle generics in `derive_partial_eq_without_eq`
2022-06-08 14:03:50 +00:00
bors
34f2839683 Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis
Remove migrate borrowck mode

Closes #58781
Closes #43234

# Stabilization proposal

This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile.

Tracking issue: #43234
RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md
Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable).

## Motivation

Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors.

The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition.

In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker.

In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver.

While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff.

## What is stabilized

As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise.

There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl.

As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions.

## What isn't stabilized

This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck.

## Tests

Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll`

## History

* On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234)
* On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271)
* On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094)
* On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825)
* On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862)
* On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083)
* On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681)
* On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114)
* On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221)
* On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)
2022-06-07 05:04:14 +00:00
Jason Newcomb
bf3ab592f0 Changes to iter_overeager_cloned
* Don't lint on `.cloned().flatten()` when `T::Item` doesn't implement `IntoIterator`
* Reduce verbosity of lint message
* Narrow down the scope of the replacement range
2022-06-07 00:40:32 -04:00
Serial
fdadebe672 Add lint output to lint list 2022-06-06 20:04:56 -04:00
bors
ad70bffa9e Auto merge of #8944 - xFrednet:8877-append-doc-idents, r=Manishearth
List configuration values can now be extended instead of replaced

I've seen some `clippy.toml` files, that have a few additions to the default list of a configuration and then a copy of our default. The list will therefore not be updated, when we add new names. This change should make it simple for new users to append values instead of replacing them.

I'm uncertain if the documentation of the `".."` is apparent. Any suggestions are welcome. I've also check that the lint list displays the examples correctly.

<details>
<summary>Lint list screenshots</summary>

![image](https://user-images.githubusercontent.com/17087237/171999434-393f2f83-09aa-4bab-8b05-bd4973150f27.png)

![image](https://user-images.githubusercontent.com/17087237/171999401-e6942b53-25e6-4b09-89e5-d867c7463156.png)

</details>

---

changelog: enhancement: [`doc_markdown`]: Users can now indicate, that the `doc-valid-idents` should extend the default and not replace it
changelog: enhancement: [`blacklisted-name`]: Users can now indicate, that the `blacklisted-names` should extend the default and not replace it

Closes: #8877

That's it. Have a fantastic weekend to everyone reading this. Here is a cookie 🍪
2022-06-06 16:34:27 +00:00
xFrednet
8db734990b
Fix #[expect] for async_yields_async 2022-06-06 14:13:28 +02:00
xFrednet
7e1730e16c
Fix #[expect] for same_name_method 2022-06-06 12:36:57 +02:00
xFrednet
a613460e8a
Fix #[expect] for needless_borrow, ref_binding_to_ref 2022-06-06 11:51:36 +02:00
Dennis Luxen
8ba377a783 Fix names to use plural 2022-06-05 22:47:21 +02:00
Dennis Luxen
0409306bb0 Implement support for implicit start and end 2022-06-05 22:46:53 +02:00
Dennis Luxen
90c8463d7e Rewrite check to account for floating point literals 2022-06-05 22:46:34 +02:00
Dennis Luxen
5948959c7e Fix misnomer braces -> parenthesis 2022-06-05 22:46:23 +02:00
Dennis Luxen
ba43f0aee9 Add new lint [needless_braces_on_range_literal] 2022-06-05 22:45:57 +02:00
bors
3e52dee646 Auto merge of #8941 - DevAccentor:for_loops_over_fallibles, r=llogiq
improve [`for_loops_over_fallibles`] to detect the usage of iter, iter_mut and into_iterator

fix #6762

detects code like
```rust
for _ in option.iter() {
    //..
}
```

changelog: Improve [`for_loops_over_fallibles`] to detect `for _ in option.iter() {}` or using `iter_mut()` or `into_iterator()`.
2022-06-05 11:16:37 +00:00
DevAccentor
5a70d88af5 add vec.capacity() to slow_vec_initialization 2022-06-05 11:01:54 +02:00
DevAccentor
3737abe802 change based on review 2022-06-05 10:26:29 +02:00
Jason Newcomb
648dbebfb1 Actually get the correct ParamEnv in derive_partial_eq_without_eq 2022-06-04 20:35:41 -04:00
Jason Newcomb
a0821fbd75 Don't lint derive_partial_eq_without_eq on private types 2022-06-04 17:28:23 -04:00
xFrednet
c31b4a9d21
List configuration values can now be extended instead of replaced 2022-06-04 16:03:25 +02:00
bors
542d474d38 Auto merge of #8930 - kyoto7250:issue_8920, r=Alexendoo
fix(manual_find_map and manual_filter_map): check clone method

close #8920

Added conditional branching when the clone method is used.

Thank you in advance.

---

changelog: check `clone()` and other variant preserving methods in [`manual_find_map`] and [`manual_filter_map`]
2022-06-04 13:05:27 +00:00
kyoto7250
42cf98553a refactor: check copied and cloned 2022-06-04 21:28:14 +09:00
Philipp Krones
7713f28f54 Remove unnecessary clap_derive dependency added in 9ee211af
The fixed issue in this commit can be tested without depending on
clap/clap_derive. This updates the test case to do so.
2022-06-04 14:04:35 +02:00
Philipp Krones
f067783461 Merge commit 'd9ddce8a223cb9916389c039777b6966ea448dc8' into clippyup 2022-06-04 13:34:07 +02:00
DevAccentor
5a49918f36 improve for_loops_over_fallibles to detect the usage of iter, iter_mut and into_iterator 2022-06-04 11:11:00 +02:00
kyoto7250
990f8bf5a6 refactor: Add some methods 2022-06-04 17:15:55 +09:00
Jack Huey
1fad95309b Fully stabilize NLL 2022-06-03 17:16:41 -04:00
DevAccentor
64fe4e32db add as_underscore lint 2022-06-03 18:11:23 +02:00
Ariel Uy
58cd01c2fc Add new lint mismatching_type_param_order
Add new lint for checking if type parameters are consistent between type
definitions and impl blocks.
2022-06-03 00:04:55 -07:00
bors
1194c6369e Auto merge of #8932 - dswij:pr-8879, r=giraffate
`needless_return` checks for macro expr in return stmts

closes #8879

Macro expressions in returns were not checked by `needless_return`. The test added in [this commit](6396a7a425 (diff-a869168cfafb7e6e5010feb76a16389d6c96d59e98113dee5c2b304a5160e43aR51-R55)) seems to have regressed.

changelog: [`needless_return`] checks for macro exprs in return statements
2022-06-03 00:00:23 +00:00
bors
97e5449a70 Auto merge of #8902 - PrestonFrom:add_suggestion_for_move_and_clone_when_not_ref, r=flip1995
When setting suggestion for significant_drop_in_scrutinee, add suggestion for MoveAndClone for non-ref

When trying to set the current suggestion, if the type of the expression
is not a reference and it is not trivially pure clone copy, we should still
trigger and emit a lint message. Since this fix may require cloning an
expensive-to-clone type, do not attempt to offer a suggested fix.

This change means that matches generated from TryDesugar and AwaitDesugar
would normally trigger a lint, but they are out of scope for this lint,
so we will explicitly ignore matches with sources of TryDesugar or
AwaitDesugar.

changelog: Update for ``[`significant_drop_in_scrutinee`]`` to correctly
emit lint messages for cases where the type is not a reference *and*
not trivially pure clone copy.
changelog: [`significant_drop_in_scrutinee`]: No longer lint on Try `?`
and `await` desugared expressions.
2022-06-02 17:16:43 +00:00
bors
e32b66c871 Auto merge of #8906 - rust-lang:copy-large-enum-variants, r=Jarcho
remove `large_enum_variant` suggestion for `Copy` types

Replaces the (erroneous) suggestion on `large_enum_variant` for `Copy` types by a note. This fixes #8894.

---

changelog: none
2022-06-02 16:37:09 +00:00
dswij
b885035ef7 needless_return checks for macro expr in return stmts 2022-06-02 20:22:15 +08:00
Andre Bogus
756caf79e6 account for generics 2022-06-02 12:45:15 +02:00
Preston From
bc5a8e9537 Lint message correctly identifies match vs for loop 2022-06-02 02:38:57 -06:00
kyoto7250
007fae10ed fix(manual_find_map and manual_filter_map): check clone method 2022-06-02 09:54:14 +09:00
bors
7572b6b757 Auto merge of #8869 - Jarcho:derive_partial_eq_without_eq, r=flip1995
Set correct `ParamEnv` for `derive_partial_eq_without_eq`

fixes #8867

changelog: Handle differing predicates applied by `#[derive(PartialEq)]` and `#[derive(Eq)]` in `derive_partial_eq_without_eq`
2022-06-01 19:27:54 +00:00
bors
c4c413b6fc Auto merge of #7930 - lengyijun:needless_deref_new, r=Jarcho
new lint: `borrow_deref_ref`

changelog: ``[`borrow_deref_ref`]``

Related pr: #6837 #7577
`@Jarcho` Could you please give a review?

`cargo lintcheck` gives no false negative (but tested crates are out-of-date).

TODO:
1. Not sure the name. `deref_on_immutable_ref` or some others?
2022-06-01 16:43:14 +00:00
lengyijun
202fdb9c53 split into borrow_deref_ref.rs and borrow_deref_ref_unfixable.rs 2022-06-01 15:43:48 +00:00
Jason Newcomb
ca78e2428e Add lint swap_ptr_to_ref 2022-05-31 13:08:05 -04:00
bors
5b1a4c0d76 Auto merge of #8884 - evantypanski:manual_range_contains_multiple, r=Manishearth
Fix `manual_range_contains` false negative with chains of `&&` and `||`

Fixes #8745

Since the precedence for `&&` is the same as itself the HIR for a chain of `&&` ends up with a right skewed tree like:

```
     &&
    /  \
  &&   c2
 /  \
... c1
```

So only the leftmost `&&` was actually "fully" checked, the top level was just `c2` and `&&` so the `manual_range_contains` lint won't apply. This change makes it also check `c2` with `c1`.

There's a bit of a hacky solution in the [second commit](257f09776a) to check if the number of open/closing parens in the snippet match. This is to prevent a case like `((x % 2 == 0) || (x < 0)) || (x >= 10)` from offering a suggestion like `((x % 2 == 0) || !(0..10).contains(&x)` which now won't compile.

Any suggestions for that paren hack welcome, kinda new to working on this so not too sure about possible solutions :) it's weird because I don't know how else to check for parens in HIR considering they're removed when lowering AST.

changelog: Fix [`manual_range_contains`] false negative with chains of `&&` and `||`
2022-05-31 16:17:12 +00:00
bors
7000e758c1 Auto merge of #8564 - Jarcho:transmute_erase_regions, r=Alexendoo
Don't lint `useless_transmute` on types with erased regions

fixes #6356
fixes #3340
fixes #2906

This should get a proper fix at some point, but this at least gets the lint running on some types.

cc #5343

changelog: Don't lint `useless_transmute` on types with erased regions
2022-05-31 15:57:27 +00:00
bors
9add456618 Auto merge of #8876 - Alexendoo:cast-abs-to-different-uint, r=dswij,xFrednet
`cast_abs_to_unsigned`: do not remove cast if it's required

Fixes #8873

If `iX` is not cast to `uX` then keep the cast rather than removing it

changelog: [`cast_abs_to_unsigned`]: do not remove cast if it's required
2022-05-31 15:40:03 +00:00
Jason Newcomb
0c6ebf1c6a Move useless_transmute back to complexity 2022-05-31 10:40:40 -04:00
Jason Newcomb
9c9cca3e66 Don't lint useless_transmute on types with erased regions 2022-05-31 10:39:53 -04:00
bors
2466a0507c Auto merge of #8918 - Jarcho:almost_complete_letter_range, r=llogiq
Add lint `almost_complete_letter_range`

fixes #7269

changelog: Add lint `almost_complete_letter_range`
2022-05-31 05:10:42 +00:00
Jason Newcomb
eb2908b4ea Add lint almost_complete_letter_range 2022-05-30 23:20:04 -04:00
bors
e1607e9d31 Auto merge of #8912 - Alexendoo:needless-late-init-ice, r=giraffate
needless_late_init: fix ICE when all branches return the never type

Fixes #8911

When the assignment is done in a match guard or the if condition and all of the branches return the never type `assignment_suggestions` would return an empty `Vec` which caused the ICE. It now returns `None` in that scenario

Also moves some tests to the top of the file

changelog: ICE Fixes: [`needless_late_init`] #8911
2022-05-31 00:46:52 +00:00
bors
588e1982d3 Auto merge of #8913 - InfRandomness:ICE-#8748, r=giraffate
Fix #8748

Thank you for making Clippy better!

changelog: Fix ICE #8748 in shadow.rs
2022-05-31 00:17:52 +00:00
bors
d9f497830c Auto merge of #8899 - botahamec:use-self-tuple-struct-variants, r=Alexendoo
Fix `[use_self]` false negative with on struct and tuple struct patterns

fixes #8845

changelog: Triggered the warning for ``[`use_self`]`` on `TupleStruct` and `Struct` patterns, whereas currently it's only triggered for `Path` patterns
2022-05-30 22:05:13 +00:00
InfRandomness
0a7f19b547 Fix #8748 2022-05-30 22:46:31 +02:00
Micha White
2aa4569303
Triggered the lint on tuple struct and struct patterns 2022-05-30 13:39:18 -04:00
lengyijun
8430fa2a82 run-rustfix 2022-05-30 01:49:46 +00:00
lyj
c5410150eb needless_deref 2022-05-30 01:46:15 +00:00
Alex Macleod
722f7d28c3 needless_late_init: fix ICE when all branches return the never type 2022-05-29 18:39:27 +00:00
bors
39231b4b50 Auto merge of #8385 - cameron1024:doc_link_with_quotes, r=llogiq
add doc_link_with_quotes lint

I'm not sure about wording, it seems OK to me but happy to change if other people have better ideas

closes #8383

---
changelog: add [`doc_link_with_quotes`] lint
2022-05-28 14:27:51 +00:00
bors
5920fa3516 Auto merge of #8844 - smoelius:fixed-paths, r=Alexendoo
Check `.fixed` paths' existence in `run_ui`

This PR adds a test to check that there exists a `.fixed` file for every `.stderr` file in `tests/ui` that mentions a `MachineApplicable` lint. The test leverages `compiletest-rs`'s `rustfix_coverage` option.

I tried to add `.fixed` files where they appeared to be missing. However, 38 exceptional `.rs` files remain. Several of those include comments indicating that they are exceptions, though not all do. Apologies, as I have not tried to associate the 38 files with GH issues. (I think that would be a lot of work, and I worry about linking the wrong issue.)

changelog: none
2022-05-28 11:28:04 +00:00
llogiq
c9be57dbf3
Merge branch 'master' into doc_link_with_quotes 2022-05-28 10:55:25 +02:00
kyoto7250
6fd2c6de90 fix(lint): check const context
https://github.com/rust-lang/rust-clippy/issues/8898
2022-05-28 14:45:25 +09:00
Andre Bogus
19f94d52b3 remove large_enum_variant suggestion for Copy types 2022-05-28 01:36:05 +02:00
Samuel E. Moelius III
6027255eb2 Ignore crashes dir 2022-05-27 16:44:02 -04:00
bors
1dd55471b4 Auto merge of #8892 - smoelius:fix-empty-line-false-positive, r=Manishearth
Fix `empty_line_after_outer_attribute` false positive

This PR fixes a false positive in `empty_line_after_outer_attribute`.

Here is a minimal example that trigger the FP:
```rust
#[derive(clap::Parser)]
#[clap(after_help = "This ia a help message.

You're welcome.
")]
pub struct Args;
```

changelog: PF: [`empty_line_after_outer_attribute`]: No longer lints empty lines in inner string values.
2022-05-27 20:34:06 +00:00
bors
461a6613cf Auto merge of #8897 - tamaroning:improve_dbg, r=Alexendoo
Introduce `allow-dbg-in-tests` config value

related to: Issue #8758,  PR https://github.com/rust-lang/rust-clippy/pull/8838

changelog: Introduced `allow-dbg-in-tests` config value. [dbg_macro] does not allow `dbg!` in test code by default.
2022-05-27 19:41:39 +00:00
Samuel E. Moelius III
8f49e4127f Fix assert! message 2022-05-27 15:18:46 -04:00
Samuel E. Moelius III
c91a7f0b83 Address review comments 2022-05-27 15:18:46 -04:00
Samuel E. Moelius III
911eb1f4cd Check .fixed paths' existence in run_ui 2022-05-27 15:18:46 -04:00
Preston From
e33d87d4a0 When setting suggestion, add suggestion for MoveAndClone for non-ref
When trying to set the current suggestion, if the type of the expression
is not a reference and it is not trivially pure clone copy, we should still
trigger and emit a lint message. Since this fix may require cloning an
expensive-to-clone type, do not attempt to offer a suggested fix.

This change means that matches generated from TryDesugar and AwaitDesugar
would normally trigger a lint, but they are out of scope for this lint,
so we will explicitly ignore matches with sources of TryDesugar or
AwaitDesugar.

changelog: Update for [`significant_drop_in_scrutinee`] to correctly
emit lint messages for cases where the type is not a reference and
not trivially pure clone copy.
2022-05-27 00:08:49 -06:00
bors
a5ece8132f Auto merge of #8885 - Serial-ATA:rc-clone-in-vec-init-weak, r=llogiq
Support `Weak` in [`rc_clone_in_vec_init`]

changelog: Support `Weak` in [`rc_clone_in_vec_init`]
2022-05-27 04:02:53 +00:00
Serial
fc28f6acc8 Support Weak in [rc_clone_in_vec_init] 2022-05-26 21:52:25 -04:00
Jason Newcomb
7975d41a91 Rework branches_sharing_code 2022-05-26 14:43:33 -04:00
tamaron
ea06a414f1 fix 2022-05-27 01:30:44 +09:00
Alex Macleod
17f7047811 Only return DefIds to Fn-like definitions in clippy_utils::fn_def_id 2022-05-26 14:35:19 +00:00
Samuel E. Moelius III
9ee211af9f Fix empty_line_after_outer_attribute false positive 2022-05-25 19:35:26 -04:00
Micha White
4de301e394
Fixed the test to not use an epsilon 2022-05-24 22:53:35 -04:00
Micha White
d8a281ef73
Added an unused_rounding lint 2022-05-24 22:53:29 -04:00
kyoto7250
e47c5b0e03 ignore clippy::get_first 2022-05-25 09:08:25 +09:00
kyoto7250
b531eb1a7a suggest first() instead of get(0) 2022-05-25 09:08:25 +09:00
kyoto7250
1dd026698d feat(lint): impl lint about use first() instead of get(0) 2022-05-25 09:08:23 +09:00
bors
b97784fd07 Auto merge of #8862 - Alexendoo:get-last-with-len, r=Jarcho,xFrednet
`get_last_with_len`: lint `VecDeque` and any deref to slice

changelog: [`get_last_with_len`]: lint `VecDeque` and any deref to slice

Previously only `Vec`s were linted, this will now catch any usages on slices, arrays, etc. It also suggests `.back()` for `VecDeque`s

Also moves the lint into `methods/`
2022-05-24 21:40:15 +00:00
bors
67a089134d Auto merge of #8880 - hellow554:rustfix_update, r=Manishearth
Add some testcases for recent rustfix update

changelog: none

This adds a testcase for a bugfix that has been fixed by https://github.com/rust-lang/rustfix/tree/v0.6.1

`rustfix` is pulled in by `compiletest_rs`. So to test that the correct rustfix version is used, I added one (and a half) testcase.

I tried to add a testcase for #8734 as well, but interesting enough the rustfix is wrong:

```diff
 fn issue8734() {
     let _ = [0u8, 1, 2, 3]
         .into_iter()
-        .and_then(|n| match n {
+        .flat_map(|n| match n {
+            1 => [n
+                .saturating_add(1)
             1 => [n
                 .saturating_add(1)
                 .saturating_add(1)
                 .saturating_add(1)
                 .saturating_add(1)
                 .saturating_add(1)
                 .saturating_add(1)
                 .saturating_add(1)
                 .saturating_add(1)],
             n => [n],
         });
 }
```

this needs some investigation and then this testcase needs to be enabled by commenting it out

closes #8878
related to #8734
2022-05-24 21:20:57 +00:00
bors
c41c410a90 Auto merge of #8786 - Alexendoo:identity-op-suggestions, r=dswij,xFrednet
`identity_op`: add parenthesis to suggestions where required

changelog: [`identity_op`]: add parenthesis to suggestions where required

Follow up to #8730, wraps the cases we can't lint as-is in parenthesis rather than ignoring them

Catches a couple new FPs with mixed operator precedences and `as` casts

```rust
// such as
0 + { a } * 2;
0 + a as usize;
```

The suggestions are now applied using `span_lint_and_sugg` rather than appearing in just the message and have a `run-rustfix` test
2022-05-24 20:47:34 +00:00
Evan Typanski
257f09776a Fix issue with mismatched parens in suggestion 2022-05-24 14:57:49 -04:00
bors
fbb9e565e3 Auto merge of #8754 - guerinoni:no_effect_replace, r=llogiq
New lint `no_effect_replace`

Closes #1595

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>

changelog: Add [`no_effect_replace`] lint.
2022-05-24 16:55:06 +00:00
Evan Typanski
78f7e3745f Fix manual_range_contains with equal precedence 2022-05-24 11:50:12 -04:00
Marcel Hellwig
04297de2ed prepare test for 8734 2022-05-24 14:42:08 +02:00
Marcel Hellwig
22673bce4c add testcase for #8878 2022-05-24 14:41:23 +02:00
Federico Guerinoni
ea62347a5a New lint no_effect_replace
Closes #1595

changelog: Add no_effect_replace lint.
2022-05-24 11:08:41 +02:00
Alex Macleod
a342f52f91 cast_abs_to_unsigned: do not remove cast if it's required 2022-05-23 12:23:48 +00:00
Jason Newcomb
5cf07c6d29 Set correct ParamEnv for derive_partial_eq_without_eq 2022-05-22 12:19:10 -04:00
Alex Macleod
855849034c get_last_with_len: lint VecDeque and any deref to slice
previously only vecs were supported
2022-05-21 19:52:43 +00:00
xFrednet
4587b6628d Merge 'rust-clippy/master' into clippyup 2022-05-21 13:24:00 +02:00
bors
b312ad7d0c Auto merge of #8856 - xFrednet:rustup, r=Manishearth,Alexendoo
Rustup

`@rust-lang/clippy,` `@Jarcho,` `@dswij,` `@Alexendoo.` Could someone review this? It should be pretty straight forward since it's just a sync. I think it's also fine if either one of `@Jarcho,` `@dswij,` `@Alexendoo` approves this, as these are usually not reviewed. I just want to make sure that I didn't break something obvious 🙃

It should be enough to look at the merge commit 🙃

changelog: none
changelog: move [`significant_drop_in_scrutinee`] to `suspicious`
2022-05-20 21:35:14 +00:00
xFrednet
4e6cf0036e
Merge remote-tracking branch 'upstream/master' into rustup 2022-05-20 20:47:31 +02:00
Alex Macleod
5730fd49fa Lint indirect usages in disallowed_methods 2022-05-20 12:39:15 +00:00
bors
ea96091331 Auto merge of #8838 - tamaroning:fix_dbg, r=Jarcho,xFrednet
[dbg_macro] tolerates use of `dbg!` in items which have `#[cfg(test)]` attribute

fix: #8758
changelog: [dbg_macro] tolerates use of `dbg!` in items with `#[cfg(test)]` attribute
2022-05-19 15:46:35 +00:00
bors
b6ad6fc5aa Auto merge of #8823 - smoelius:unknown-field, r=xFrednet
Improve "unknown field" error messages

Fixes #8806

Sample output:
```
error: error reading Clippy's configuration file `/home/smoelius/github/smoelius/rust-clippy/clippy.toml`: unknown field `foobar`, expected one of
           allow-expect-in-tests              enable-raw-pointer-heuristic-for-send    standard-macro-braces
           allow-unwrap-in-tests              enforced-import-renames                  third-party
           allowed-scripts                    enum-variant-name-threshold              too-large-for-stack
           array-size-threshold               enum-variant-size-threshold              too-many-arguments-threshold
           avoid-breaking-exported-api        literal-representation-threshold         too-many-lines-threshold
           await-holding-invalid-types        max-fn-params-bools                      trivial-copy-size-limit
           blacklisted-names                  max-include-file-size                    type-complexity-threshold
           cargo-ignore-publish               max-struct-bools                         unreadable-literal-lint-fractions
           cognitive-complexity-threshold     max-suggested-slice-pattern-length       upper-case-acronyms-aggressive
           cyclomatic-complexity-threshold    max-trait-bounds                         vec-box-size-threshold
           disallowed-methods                 msrv                                     verbose-bit-mask-threshold
           disallowed-types                   pass-by-value-size-limit                 warn-on-all-wildcard-imports
           doc-valid-idents                   single-char-binding-names-threshold
       at line 1 column 1
```

You can test this by (say) adding `foobar = 42` to Clippy's root `clippy.toml` file, and running `cargo run --bin cargo-clippy`.

Note that, to get the terminal width, this PR adds `termize` as a dependency to `cargo-clippy`. However, `termize` is also [how `rustc_errors` gets the terminal width](481db40311/compiler/rustc_errors/src/emitter.rs (L1607)). So, hopefully, this is not a dealbreaker.

r? `@xFrednet`

changelog: Enhancements: the "unknown field" error messages for config files now wraps the field names.
2022-05-18 17:15:38 +00:00
Samuel E. Moelius III
564725775b Improve "unknown field" error messages 2022-05-18 05:21:10 -04:00
bors
bf2e63104d Auto merge of #8807 - Jarcho:cmp_owned, r=giraffate
Fix `cmp_owned` on copy types

fixes #8803
fixes #7365

changelog: Don't lint `cmp_owned` on `From::from` for copy types
2022-05-18 00:19:36 +00:00
tamaron
b4c3f0f79b fix 2022-05-18 00:37:12 +09:00
bors
d901079ca1 Auto merge of #8814 - yonip23:add-suggestion-to-rc-clone-in-vec-init, r=xFrednet
add suggestions to rc_clone_in_vec_init

A followup to https://github.com/rust-lang/rust-clippy/pull/8769
I also switch the order of the 2 suggestions, since the loop initialization one is probably the common case.

`@xFrednet` I'm not letting you guys rest for a minute 😅
changelog: add suggestions to [`rc_clone_in_vec_init`]
2022-05-17 05:46:00 +00:00
Elliot Bobrow
430575b61a add manual_find lint for function return case 2022-05-16 20:20:49 -07:00
Jason Newcomb
c649d4e8a7 Fix ICE in let_unit_value when calling a static or const callable type 2022-05-16 10:00:32 -04:00
bors
a1632fffc1 Auto merge of #8761 - tamaroning:fix_8505, r=Jarcho
`undocumented_unsafe_blocks` does not trigger on unsafe trait impls

Closes #8505

changelog: This lint checks unsafe impls NOT from macro expansions and checks ones in macro declarations.
~~`unsafe impl`s from macro invocations don't trigger the lint for now.~~
~~This lint checks unsafe impls from/not from macro expansions~~
2022-05-16 00:47:10 +00:00
bors
6ec735962f Auto merge of #8699 - Jarcho:vec_init_then_push_7071, r=dswij,xFrednet
Don't lint `vec_init_then_push` when further extended

fixes #7071

This will still lint when a larger number of pushes are done (four currently). The exact number could be debated, but this is more readable then a sequence of pushes so it shouldn't be too large.

changelog: Don't lint `vec_init_then_push` when further extended.
changelog: Remove `mut` binding from `vec_init_then_push` when possible.
2022-05-15 21:51:24 +00:00
Jason Newcomb
f1574cc131 Update vec_init_then_push docs 2022-05-15 17:39:39 -04:00
Jason Newcomb
50eada16f7 Rename eval_order_dependence to mixed_read_write_in_expression 2022-05-15 17:08:45 -04:00
Alex Macleod
1f79a442e5 Add duplicate_mod lint 2022-05-14 22:31:13 +01:00
bors
2038084cf2 Auto merge of #8813 - evantypanski:redundant_alloc_fat_ptr, r=Alexendoo
Fix redundant_allocation warning for Rc<Box<str>>

changelog: [`redundant_allocation`] Fixes #8604

Fixes false positives where a fat pointer with `str` type was made thin by another allocation, but that thinning allocation was marked as redundant
2022-05-13 15:02:58 +00:00
ydah
4e5f69cc86 Tweak some words improved representation
This PR has implemented improved representation.

- Use "lib" instead of "lifb"
- Use "triggered" instead of "triggere"
- Use "blacklisted_name" instead of "blackisted_name"
- Use "stabilization" instead of "stabilisation"
- Use "behavior" instead of "behaviour"
- Use "target" instead of "tartet"
- Use "checked_add" instead of "chcked_add"
- Use "anti-pattern" instead of "antipattern"
- Use "suggestion" instead of "suggesttion"
- Use "example" instead of "exampel"
- Use "Cheat Sheet" instead of "Cheatsheet"
2022-05-13 14:20:25 +09:00
Evan Typanski
0def44a1c1 Catch other thinning allocations using Ty 2022-05-12 19:15:08 -04:00
yonip23
dc23b5d661 fix indentation + test 2022-05-12 10:06:15 +03:00
bors
a3d1f28849 Auto merge of #8818 - koic:use_rust_2021_prelude, r=flip1995
Use the traits added to the Rust 2021 Edition prelude

Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html

---

changelog: none
2022-05-11 20:16:42 +00:00
yonip23
344888a582 fix review comments 2022-05-11 23:11:52 +03:00
Camille GILLOT
31825326e5 Bless clippy. 2022-05-11 18:51:14 +02:00
Koichi ITO
ae0216d557 Use the traits added to the Rust 2021 Edition prelude
Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-12 00:38:11 +09:00
Serial
554dc41cea Fix match_single_binding for assign expressions 2022-05-10 18:38:51 -04:00
yonip23
f3e01c4f6a add suggestions to rc_clone_in_vec_init 2022-05-11 01:09:45 +03:00
Evan Typanski
631b4ee7a2 Fix redundant_allocation warning for Rc<Box<str>> 2022-05-10 14:21:51 -04:00
tamaron
aaf87c3871 fix 2022-05-10 23:54:42 +09:00
bors
d422baa30c Auto merge of #8796 - nsunderland1:master, r=giraffate
New lint: [`derive_partial_eq_without_eq`]

Introduces a new lint, [`derive_partial_eq_without_eq`].

See: #1781 (doesn't close it though).

changelog: add lint [`derive_partial_eq_without_eq`]
2022-05-10 13:25:27 +00:00
bors
1a11a499d4 Auto merge of #8769 - yonip23:8719, r=xFrednet
introduce rc_clone_in_vec_init lint

Closes #8719

changelog: Introduce [`rc_clone_in_vec_init`] lint
2022-05-10 12:21:12 +00:00
yonip23
feb6d8cf30 introduce rc_clone_in_vec_init lint 2022-05-10 15:10:13 +03:00
nsunderland1
fe84ff3360 New lint: [derive_partial_eq_without_eq] 2022-05-09 22:13:39 -07:00
Alex Macleod
6edf0b4f36 Ignore unfulfilled_lint_expectations in metadata collection 2022-05-09 20:40:37 +01:00
Jason Newcomb
993b4016db Don't lint cmp_owned when From::from results in a copy type. 2022-05-09 12:29:31 -04:00
bors
670bc53c03 Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser
Support tool lints with the `#[expect]` attribute (RFC 2383)

This PR fixes the ICE https://github.com/rust-lang/rust/issues/94953 by making the assert for converted expectation IDs conditional.

Additionally, it moves the lint expectation check into a separate query to support rustdoc and other tools. On the way, I've also added some tests to ensure that the attribute works for Clippy and rustdoc lints.

The number of changes comes from the long test file. This may look like a monster PR, this may smell like a monster PR and this may be a monster PR, but it's a harmless monster. 🦕

---

Closes: https://github.com/rust-lang/rust/issues/94953

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

r? `@wesleywiser`

cc: `@rust-lang/rustdoc`
2022-05-09 00:02:55 +00:00
bors
1d018ce47c Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
Track if a where bound comes from a impl Trait desugar

With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering.

r? `@cjgillot`

cc `@estebank` (as the reviewer of #93803)
2022-05-08 14:10:12 +00:00
xFrednet
21e4765e58 Test expect attribute for tool lints, clippy edition (RFC 2383) 2022-05-08 14:37:16 +02:00
Samuel E. Moelius III
597f61bbe3 Optionally allow expect and unwrap in tests 2022-05-08 07:18:31 -04:00
bors
9c78883fdf Auto merge of #8794 - smoelius:fix-8759, r=llogiq
Address `unnecessary_to_owned` false positive

My proposed fix for #8759 is to revise the conditions that delineate `redundant_clone` and `unnecessary_to_owned`:
```rust
        // Only flag cases satisfying at least one of the following three conditions:
        // * the referent and receiver types are distinct
        // * the referent/receiver type is a copyable array
        // * the method is `Cow::into_owned`
        // This restriction is to ensure there is no overlap between `redundant_clone` and this
        // lint. It also avoids the following false positive:
        //  https://github.com/rust-lang/rust-clippy/issues/8759
        //   Arrays are a bit of a corner case. Non-copyable arrays are handled by
        // `redundant_clone`, but copyable arrays are not.
```
This change causes a few cases that were previously flagged by `unnecessary_to_owned` to no longer be flagged. But one could argue those cases would be better handled by `redundant_clone`.

Closes #8759

changelog: none
2022-05-07 12:31:47 +00:00
tamaron
8d8588941e fix 2022-05-07 19:50:34 +09:00
Preston From
41c7e4d382 Lint for significant drops who may have surprising lifetimes #1
author Preston From <prestonfrom@gmail.com> 1645164142 -0600
committer Preston From <prestonfrom@gmail.com> 1650005351 -0600
2022-05-06 21:48:17 -06:00
Guillaume Gomez
13e8ace73c Rollup merge of #96557 - nbdd0121:const, r=oli-obk
Allow inline consts to reference generic params

Tracking issue: #76001

The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well.

However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have:
```rust
fn foo<T>() {
    let x = [4i32; std::mem::size_of::<T>()];   // NOT ALLOWED (for now)
    let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR!
    let x = [4i32; const { std::mem::size_of::<T>() }];   // NOT ALLOWED (for now)
}
```

This would make inline consts super useful for compile-time checks and assertions:
```rust
fn assert_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) };
}
```

This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do:
```rust
fn assert_zst<T>() {
    struct F<T>(T);
    impl<T> F<T> {
        const V: () = assert!(std::mem::size_of::<T>() == 0);
    }
    let _ = F::<T>::V;
}
```

It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either:
```rust
fn foo<T>() -> usize {
    let (_, size): (PhantomData<T>, usize) = const {
        const fn my_size_of<T>() -> (PhantomData<T>, usize) {
            (PhantomData, std::mem::size_of::<T>())
        }
        my_size_of()
    };
    size
}
```

```@rustbot``` label: F-inline_const
2022-05-06 20:05:37 +02:00
tamaron
5d0ca74c75 Resolved conflicts 2022-05-07 00:05:45 +09:00
Samuel E. Moelius III
91a822c162 Address unnecessary_to_owned false positive 2022-05-06 09:31:27 -04:00
bors
1594e986ea Auto merge of #8763 - arieluy:manual_range_contains, r=xFrednet
Support negative ints in manual_range_contains

fixes: #8721
changelog: Fixes issue where ranges containing ints with different signs would be
incorrect due to comparing as unsigned.
2022-05-06 11:33:47 +00:00
bors
5dad51736c Auto merge of #8778 - sunfishcode:main, r=giraffate
Fix `cast_lossless` to avoid warning on `usize` to `f64` conversion.

Previously, the `cast_lossless` lint would issue a warning on code that
converted a `usize` value to `f64`, on 32-bit targets.

`usize` to `f64` is a lossless cast on 32-bit targets, however there is
no corresponding `f64::from` that takes a `usize`, so `cast_lossless`'s
suggested replacement does not compile.

This PR disables the lint in the case of casting from `usize` or `isize`.

Fixes #3689.

changelog: [`cast_lossless`] no longer gives wrong suggestion on usize,isize->f64
2022-05-06 00:26:18 +00:00
flip1995
ed8458f67a (Partially) Revert "HACK: Move buggy lints to nursery"
This reverts commit bb01aca86f.

Partial: Keep regression tests
2022-05-05 15:20:07 +01:00
flip1995
7cd86aa1be Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup 2022-05-05 15:12:52 +01:00
Gary Guo
f0c2ac8a29 Bless clippy error msg 2022-05-05 14:27:11 +01:00
flip1995
006282964f
Fix ICE in EarlyAttribtues lints 2022-05-05 14:10:06 +01:00
flip1995
bb01aca86f
HACK: Move buggy lints to nursery
Those lints are trait_duplication_in_bounds and
type_repetition_in_bounds. I don't think those can be fixed on the
Clippy side alone, but need changes in the compiler. So let's move them
to nursery to get the sync through and then fix them on the rustc side.

Also adds a regression test that has to be fixed before they can be
moved back to pedantic.
2022-05-05 13:32:31 +01:00
flip1995
3b0c78d283
Merge remote-tracking branch 'upstream/master' into rustup 2022-05-05 13:32:06 +01:00
Alex Macleod
ee8fae3f5d identity_op: add parenthesis to suggestions where required 2022-05-04 21:19:43 +01:00
bors
c7a705a842 Auto merge of #8575 - FoseFx:trim_split_whitespace2, r=flip1995
add `trim_split_whitespace`

Closes #8521

changelog: [`trim_split_whitespace`]
2022-05-04 13:31:19 +00:00
bors
751fd0d735 Auto merge of #8780 - Alexendoo:init-numbered-field-alias, r=flip1995
Ignore type aliases in `init_numbered_fields`

changelog: Ignore type aliases in [`init_numbered_fields`]

Fixes #8638
2022-05-04 13:17:35 +00:00
Max Baumann
fea177fafe
add trim_split_whitespace 2022-05-04 15:04:05 +02:00
Alex Macleod
d53293d52a Ignore type aliases in init_numbered_fields 2022-05-03 14:28:27 +01:00
binggh
7017eb102d cargo dev bless 2022-05-03 17:51:34 +08:00
bors
0ceacbe185 Auto merge of #8730 - tamaroning:fix8724, r=Alexendoo
[FP] identity_op in front of if

fix #8724

changelog: FP: [`identity_op`]: is now allowed in front of if statements, blocks and other expressions where the suggestion would be invalid.

Resolved simular problems with blocks, mathces, and loops.
identity_op always does NOT suggest reducing `0 + if b { 1 } else { 2 } + 3` into  `if b { 1 } else { 2 } + 3` even in the case that the expression is in `f(expr)` or `let x = expr;` for now.
2022-05-03 07:05:51 +00:00
Dan Gohman
6ff77b96f1 Fix cast_lossless to avoid warning on usize to f64 conversion.
Previously, the `cast_lossless` lint would issue a warning on code that
converted a `usize` value to `f64`, on 32-bit targets.

`usize` to `f64` is a lossless cast on 32-bit targets, however there is
no corresponding `f64::from` that takes a `usize`, so `cast_lossless`'s
suggested replacement does not compile.

This PR disables the lint in the case of casting from `usize` or `isize`.

Fixes #3689.

changelog: [`cast_lossless`] no longer gives wrong suggestion on usize->f64
2022-05-02 13:52:13 -07:00
tamaron
6ad810f94e improve identity_op
fix

Update identity_op.rs

ok

update without_loop_counters test

chore

fix

chore

remove visitor and leftmost

fix

add document
2022-05-01 11:03:27 +09:00
bors
32fe4762bf Auto merge of #8625 - Jarcho:rename_lint, r=xFrednet
Add `cargo dev rename_lint`

fixes #7799

changelog: None
2022-04-30 17:22:34 +00:00
bors
ec46992008 Auto merge of #8720 - asquared31415:ptr-cast-ice-fix, r=Alexendoo,xFrednet
fix ICE in `cast_slice_different_sizes`

fixes #8708

changelog: fixes an ICE introduced in #8445
2022-04-30 16:51:01 +00:00
Camille GILLOT
e46c782662 Bless tests. 2022-04-30 13:55:17 +02:00
Ariel Uy
d10296910f Support negative ints in manual_range_contains
Fixes issue where ranges containing ints with different signs would be
incorrect due to comparing as unsigned.
2022-04-29 19:11:00 -07:00
bors
d5c62fd399 Auto merge of #8431 - dswij:8416, r=xFrednet
`redundant_closure` fix FP on coerced closure

Closes https://github.com/rust-lang/rust-clippy/issues/8416,
Closes https://github.com/rust-lang/rust-clippy/issues/7812
Closes https://github.com/rust-lang/rust-clippy/issues/8091

~~Seems like this is fixed in #817 and regressed.~~

Ignore coerced closure false positives, but this will lead to some false negatives on resolvable generics. IMO, this is still an overall improvement

changelog: [`redundant_closure`] ignores coerced closure
2022-04-27 09:47:08 +00:00
bors
18a1831377 Auto merge of #8743 - Alexendoo:useless-attribute-redundant-pub-crate, r=llogiq
ignore `redundant_pub_crate` in `useless_attribute`

changelog: [`useless_attribute`] no longer lints [`redundant_pub_crate`]

As mentioned in https://github.com/rust-lang/rust-clippy/issues/8732#issuecomment-1106489634

> And it turns out I can't even explicitly allow it at the usage site, because then `clippy::useless_attribute` fires (which would also be a FP?), which is deny-by-default.
>
> Though it does work if I then allow `clippy::useless_attribute`. 😂
>
> ```rust
> #[allow(clippy::useless_attribute)]
> #[allow(clippy::redundant_pub_crate)]
> pub(crate) use bit;
> ```
>
> The originally-reported warning now no longer occurs.
2022-04-27 05:43:13 +00:00
dswij
33bf9e9a54 redundant_closure ignore coerced closure 2022-04-27 13:05:01 +08:00
Jason Newcomb
948af01633 Don't lint vec_init_then_push when further extended 2022-04-27 00:38:39 -04:00
bors
95396f61bc Auto merge of #8617 - Alexendoo:relax-needless-late-init, r=giraffate
`needless_late_init`: ignore `if let`, `let mut` and significant drops

No longer lints `if let`, personal taste on this one is pretty split, so it probably shouldn't be warning by default. Fixes #8613

```rust
let x = if let Some(n) = y {
    n
} else {
    1
}
```

No longer lints `let mut`, things like the following are not uncommon and look fine as they are

b169c16d86/src/sixty_four.rs (L88-L93)

Avoids changing the drop order in an observable way, where the type of `x` has a drop with side effects and something between `x` and the first use also does, e.g.

48cc6cb791/tests/test_api.rs (L159-L167)

The implementation of `type_needs_ordered_drop_inner` was changed a bit, it now uses `Ty::has_significant_drop` and reordered the ifs to check diagnostic name before checking the implicit drop impl

changelog: [`needless_late_init`]: No longer lints `if let` statements, `let mut` bindings and no longer significantly changes drop order
2022-04-27 00:11:17 +00:00
Alex Macleod
1d1fecff0f needless_late_init: ignore if let, let mut and significant drops 2022-04-26 13:16:54 +01:00
bors
94623ee882 Auto merge of #8737 - smoelius:extra-impl-lifetimes, r=giraffate
Extend `extra_unused_lifetimes` to handle impl lifetimes

Fixes #6437 (cc: `@carols10cents)`

changelog: fix #6437
2022-04-26 00:06:53 +00:00
bors
760f293d79 Auto merge of #8727 - Serial-ATA:lint-large-includes, r=xFrednet
Add `large_include_file` lint

changelog: Add [`large_include_file`] lint
closes #7005
2022-04-25 17:29:27 +00:00
Samuel E. Moelius III
e6fa163fad Fix false positives 2022-04-25 05:20:08 -04:00
bors
388e6b7854 Auto merge of #8742 - goth-turtle:mistyped-literal-suffix, r=llogiq
mistyped_literal_suffix: improve integer suggestions, avoid wrong float suggestions

This PR fixes 2 things:
- The known problem that integer types are always suggested as signed, by suggesting an unsigned suffix for literals that wouldnt fit in the signed type, and ignores any literals too big for the corresponding unsigned type too.
- The lint would only look at the integer part of any floating point literals without an exponent, this causing #6129. This just ignores those literals.

Examples:
```rust
let _ = 2_32; // still 2_i32
let _ = 234_8; // would now suggest 234_u8

// these are now ignored
let _ = 500_8;
let _ = 123_32.123;
```

changelog: suggest correct integer types in [`mistyped_literal_suffix`], ignore float literals without an exponent
fixes #6129
2022-04-24 20:16:40 +00:00
Serial
a85dc87c4c Add large_include_file lint 2022-04-24 10:08:31 -04:00
goth-turtle
b4a50e9ee5 mistyped_literal_suffixes: ignore floats without exponent
Previously this lint would only look at the integer part of floating
point literals without an exponent, giving wrong suggestions like:

```
  |
8 |     let _ = 123_32.123;
  |             ^^^^^^^^^^ help: did you mean to write: `123.123_f32`
  |
```

Instead, it now ignores these literals.
Fixes #6129
2022-04-24 15:28:36 +02:00
goth-turtle
f290249461 mistyped_literal_suffixes: improve suggestions for integer types
Instead of just always suggesting signed suffixes regardless of size
of the value, it now suggests an unsigned suffix when the value wouldn't
fit into the corresponding signed type, and ignores the literal entirely
if it is too big for the unsigned type as well.
2022-04-24 15:28:36 +02:00
Jason Newcomb
b3de32ba3c Add rename_lint command 2022-04-24 09:15:26 -04:00
bors
6aa3684431 Auto merge of #8738 - tamaroning:fix_wrong_self_convention, r=xFrednet
wrong_self_convention allows `is_*` to take `&mut self`

fix #8480 and #8513
Allowing `is_*` to take `&self` or none is too restrictive.

changelog: FPs: [`wrong_self_convention`] now allows `&mut self` and no self as arguments for `is_*` methods
2022-04-24 12:40:15 +00:00
asquared31415
af9dfa3692 fix ICE by using a type to return the info we want and also fix some bugs in displaying an extra mut when a TypeAndMut was wrong 2022-04-23 13:07:13 -04:00
tamaron
51db157fb4 fix 2022-04-23 22:45:26 +09:00
Alex Macleod
0c164bbfdb ignore redundant_pub_crate in useless_attribute 2022-04-23 12:23:18 +01:00
Samuel E. Moelius III
b35c04f7dc Extend extra_unused_lifetimes to handle impl lifetimes 2022-04-22 20:05:18 -04:00
Serial
f20e890a4b Add macro export exemption to redundant_pub_crate 2022-04-22 18:09:14 -04:00
bors
cef882cc9d Auto merge of #8731 - Alexendoo:dogfood-allow-unknown-lints, r=xFrednet
dogfood: allow unknown lints when not running with `internal` feature

changelog: none

https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/unknown.20lint.20in.20test.20dogfood_clippy

It's only a warning so this wasn't causing the test to fail, but if you had another error somewhere or used `--nocapture` the extra warnings would be shown
2022-04-22 17:11:53 +00:00
Alex Macleod
a96bc7af12 dogfood: allow unknown lints when not running with internal feature 2022-04-22 13:15:11 +01:00
bors
ed22428b72 Auto merge of #8717 - Alexendoo:manual-split-once-manual-iter, r=dswij,xFrednet
`manual_split_once`: lint manual iteration of `SplitN`

changelog: `manual_split_once`: lint manual iteration of `SplitN`

Now lints:

```rust
let mut iter = "a.b.c".splitn(2, '.');
let first = iter.next().unwrap();
let second = iter.next().unwrap();

let mut iter = "a.b.c".splitn(2, '.');
let first = iter.next()?;
let second = iter.next()?;

let mut iter = "a.b.c".rsplitn(2, '.');
let first = iter.next().unwrap();
let second = iter.next().unwrap();

let mut iter = "a.b.c".rsplitn(2, '.');
let first = iter.next()?;
let second = iter.next()?;
```

It suggests (minus leftover whitespace):

```rust
let (first, second) = "a.b.c".split_once('.').unwrap();

let (first, second) = "a.b.c".split_once('.')?;

let (second, first) = "a.b.c".rsplit_once('.').unwrap();

let (second, first) = "a.b.c".rsplit_once('.')?;
```

Currently only lints if the statements are next to each other, as detecting the various kinds of shadowing was tricky, so the following won't lint

```rust
let mut iter = "a.b.c".splitn(2, '.');
let something_else = 1;
let first = iter.next()?;
let second = iter.next()?;
```
2022-04-22 09:57:00 +00:00
Serial
14667d1474 Fix missing whitespace in collapsible_else_if suggestion 2022-04-21 13:45:40 -04:00
Alex Macleod
4424aa444c manual_split_once: lint manual iteration of SplitN 2022-04-21 18:33:54 +01:00
Gryffon Bellish
8de3fb159d
Add empty_drop lint 2022-04-21 10:03:01 +02:00
bors
4c25880f0c Auto merge of #8716 - binggh:stable-sort-message-update, r=giraffate
Less authoritative stable_sort_primitive message

fixes #8241

Hey all - first contribution here so I'm deciding to start with something small.

Updated the linked message to be less authoritative as well as moved the lint grouping from `perf` to `pedantic` as suggested by `@camsteffen` under the issue.

changelog: [`stable_sort_primitive`]: emit less authoritative message and move to `pedantic`
2022-04-21 00:27:13 +00:00
bors
f99ad82f9e Auto merge of #8700 - youknowone:needless_match-false-positive, r=xFrednet
Fix needless_match false positive for if-let when the else block doesn't match to given expr

<!--

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change. Also, it's helpful for us that
the lint name is put into brackets `[]` and backticks `` ` ` ``,
e.g. ``[`lint_name`]``.

If your PR fixes an issue, you can add "fixes #issue_number" into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

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

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.

--->

fix #8695

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

changelog: Fixed ``[`needless_match`]`` false positive when else block expression differs.
2022-04-20 17:16:39 +00:00
bors
e17b97c8e0 Auto merge of #8711 - kyoto7250:new-lint-bytes-count-to-len, r=giraffate
Take over: New lint bytes count to len

take over #8375
close #8083

This PR adds new lint about  considering replacing `.bytes().count()` with `.len()`.

Thank you in advance.

---

r! `@Manishearth`

changelog: adds new lint [`bytes_count_to_len`] to consider replacing `.bytes().count()` with `.len()`
2022-04-19 12:44:07 +00:00
asquared31415
c922bb9443 fix ICE 2022-04-18 22:19:34 -04:00
kyoto7250
f19387d237 add checking type
adding test patterns

cargo dev bless

fix comment

add ;

delete :

fix suggestion code

and update stderr in tests.

use match_def_path when checking method name
2022-04-19 10:48:12 +09:00
Chase Ruskin
df1ec91d95 adds lint logic and test for bytes_count_to_len
formats code with

fixes single match clippy error to replace with if let

swaps ident.name.as_str to ident.name == sym for count fn
2022-04-19 10:48:10 +09:00
bors
cbdf17c884 Auto merge of #8707 - OneSignal:await-invalid-types, r=llogiq
Add `await_holding_invalid_type` lint

changelog: [`await_holding_invalid_type`]

This lint allows users to create a denylist of types which are not allowed to be
held across await points. This is essentially a re-implementation of the
language-level [`must_not_suspend`
lint](https://github.com/rust-lang/rust/issues/83310). That lint has a lot of
work still to be done before it will reach Rust stable, and in the meantime
there are a lot of types which can trip up developers if they are used
improperly.

I originally implemented this specifically for `tracing::span::Entered`, until I discovered #8434 and read the commentary on that PR. Given this implementation is fully user configurable, doesn't tie clippy to any one particular crate, and introduces no additional dependencies, it seems more appropriate.
2022-04-18 18:36:50 +00:00
Lily Mara
7e26edce65 fixup! Add await_holding_invalid_type lint 2022-04-18 11:16:35 -07:00
bing
7a4d07105f Less authoritative stable_sort_primitive message 2022-04-18 14:42:24 +08:00
Jeong YunWon
b94e24e95f Fix needless_match false positive for if-let
when the else block doesn't match to given expr
2022-04-18 14:33:13 +09:00
bors
e5ebece910 Auto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq
Introduce needless_option_take lint

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

Fixes #8618

changelog: Introduce [`needless_option_take`] lint
2022-04-17 18:34:16 +00:00
bors
cb1924a42a Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
Report undeclared lifetimes during late resolution.

First step in https://github.com/rust-lang/rust/pull/91557

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`
2022-04-17 12:56:19 +00:00
Camille GILLOT
e4110cf633 Bless clippy. 2022-04-17 11:03:34 +02:00
bors
cc25cbd243 Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>

cc `@cjgillot`
2022-04-17 08:06:53 +00:00
Lily Mara
3cd8b5a5ef fixup! Add await_holding_invalid_type lint 2022-04-15 14:45:58 -07:00
Lily Mara
4844325faf Add await_holding_invalid_type lint
changelog: [`await_holding_invalid_type`]

This lint allows users to create a denylist of types which are not allowed to be
held across await points. This is essentially a re-implementation of the
language-level [`must_not_suspend`
lint](https://github.com/rust-lang/rust/issues/83310). That lint has a lot of
work still to be done before it will reach Rust stable, and in the meantime
there are a lot of types which can trip up developers if they are used
improperly.
2022-04-15 14:39:10 -07:00
whodi
e475dde097 collapsible <> collspible 2022-04-15 14:19:01 -07:00
whodi
2be7ad5b39 initialization misspell 2022-04-15 14:19:00 -07:00
whodi
29ef80c78a adding spell checking 2022-04-15 14:18:09 -07:00
Jason Newcomb
70f7c624e4 Allow more complex expressions in let_unit_value 2022-04-14 21:34:33 -04:00
Jason Newcomb
48bcc1d95f Move let_unit_value back into style 2022-04-14 21:33:32 -04:00
Jason Newcomb
d68ac9ccce Don't lint let_unit_value when needed for type inferenece 2022-04-14 21:32:51 -04:00
bors
80bcd9bc6e Auto merge of #8614 - pitaj:fix-7597, r=giraffate
assertions_on_constants: ignore indirect `cfg!`

Fixes #7597

changelog: [`assertions_on_constants`] ignore constants indirectly based on `cfg!`
2022-04-14 23:58:51 +00:00
bors
aade96f902 Auto merge of #8626 - pitaj:format_add_string, r=llogiq
New lint `format_add_strings`

Closes #6261

changelog: Added [`format_add_string`]: recommend using `write!` instead of appending the result of  `format!`
2022-04-14 14:29:22 +00:00
bors
ecb3c3fc7e Auto merge of #8677 - xFrednet:8213-manual-bits-suggestion, r=giraffate
Add `usize` cast to `clippy::manual_bits` suggestion

A fix for the suggestion from https://github.com/rust-lang/rust-clippy/pull/8213

changelog: [`manual_bits`]: The suggestion now includes a cast for proper type conversion
2022-04-14 12:59:23 +00:00
infrandomness
2903b56f17 Add tests and docs
This adds test to make sure correct behavior of lint
- The first test's option variable is not a temporary variable
- The second test does not make usage of `take()`
- The third test makes usage of `take()` and uses a temporary variable
2022-04-14 13:16:46 +02:00
infrandomness
8b2b343b23 Delete unused variable y in test
This fixes the errors occuring while running the ui tests
2022-04-14 13:16:06 +02:00
infrandomness
f8f144117d Swap span_lint for span_lint_and_sugg
This implements a machine applicable suggestion to any matched usage of
`.as_ref().take()``
2022-04-14 13:15:51 +02:00
infrandomness
262b35ea2c Introduce option_take_on_temporary lints
This lint checks if Option::take() is used on a temporary value (a value
that is not of type &mut Option and that is not a Place expression) to
suggest omitting take()
2022-04-14 12:41:47 +02:00
Peter Jaszkowiak
67badbeef6 New lint format_add_strings 2022-04-13 22:48:36 -06:00
Peter Jaszkowiak
9f131e5a0b assertions_on_constants: ignore indirect cfg! 2022-04-13 22:47:08 -06:00
bors
38ba05508c Auto merge of #8676 - Alexendoo:local-used-across-loop, r=xFrednet
Check for loops/closures in `local_used_after_expr`

Follow up to #8646, catches when a local is used multiple times because it's in a loop or a closure

changelog: none
2022-04-14 04:44:33 +00:00
xFrednet
ba15cdd3c1
Add usize cast to clippy::manual_bits suggestion 2022-04-13 19:31:24 +02:00
bors
b6645d022e Auto merge of #8670 - yoav-lavi:main, r=giraffate
`pub_use` restriction

[`pub_use`]

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

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

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

changelog: Adds a lint called `pub_use` that restricts the usage of `pub use ...`
2022-04-13 13:03:51 +00:00
Yoav Lavi
66d253f0f2 pub_use 2022-04-13 13:48:27 +02:00
bors
f70c73f5c4 Auto merge of #8692 - kyoto7250:fixing_unnecessary_to_owned, r=giraffate
fix unnecessary_to_owned about msrv

This PR fixes ``[`unnecessary_owned`]``.

## What

```rust
# sample code
fn _msrv_1_35() {
    #![clippy::msrv = "1.35"]
    let _ = &["x"][..].to_vec().into_iter();
}

fn _msrv_1_36() {
    #![clippy::msrv = "1.36"]
    let _ = &["x"][..].to_vec().into_iter();
}
```

If we will check this code using clippy, ``[`unnecessary_owned`]`` will modify the code as follows.

```rust
error: unnecessary use of `to_vec`
  --> $DIR/unnecessary_to_owned.rs:219:14
   |
LL |     let _ = &["x"][..].to_vec().into_iter();
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`

error: unnecessary use of `to_vec`
  --> $DIR/unnecessary_to_owned.rs:224:14
   |
LL |     let _ = &["x"][..].to_vec().into_iter();
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `["x"][..].iter().copied()`
```

This is incorrect. Because `Iterator::copied` was estabilished in 1.36.

## Why

This bug was caused by not separating "copied" and "clone" by reference to msrv.

89ee6aa6e3/clippy_lints/src/methods/unnecessary_to_owned.rs (L195)

So, I added a conditional branch and described the corresponding test.

Thank you in advance.

changelog: fix wrong suggestions about msrv in [`unnecessary_to_owned`]

r! `@giraffate`
2022-04-13 00:57:08 +00:00
bors
06b1695814 Auto merge of #8647 - Jarcho:mut_from_ref_6326, r=giraffate
Only lint `mut_from_ref` when unsafe code is used

fixes #6326

changelog: Only lint `mut_from_ref` when unsafe code is used.
2022-04-13 00:38:54 +00:00
bors
d8c97e6cf3 Auto merge of #8645 - Jarcho:manual_non_exhaustive_5714, r=Jarcho
Don't lint `manual_non_exhaustive` when the enum variant is used

fixes #5714

changelog: Don't lint `manual_non_exhaustive` when the enum variant is used
2022-04-12 18:38:45 +00:00
bors
849668ad71 Auto merge of #8690 - mucinoab:DoNot-rest_pat_in_fully_bound_structs-OnNonExhaustive, r=Manishearth
Do not trigger ``[`rest_pat_in_fully_bound_structs`]`` on `#[non_exhaustive]` structs

fixes #8029

Just adds an additional check to ensure that the`ty::VariantDef` is not marked as `#[non_exhaustive]`.

changelog: Do not apply ``[`rest_pat_in_fully_bound_structs`]`` on structs marked as non exhaustive.
2022-04-12 16:14:13 +00:00
kyoto7250
dfdc5ad7d8 fix unnecessary_to_owned about msrv 2022-04-12 22:59:25 +09:00
bors
b3bd03afcd Auto merge of #8686 - Jarcho:undocumented_unsafe_blocks_8681, r=flip1995
Fix ICE in `undocumented_unsafe_blocks`

fixes #8681

changelog: Fix ICE in `undocumented_unsafe_blocks`
2022-04-12 07:17:57 +00:00
Bruno A. Muciño
739f273739 Do not apply rest_pat_in_fully_bound_structs on #[non_exhaustive] structs 2022-04-11 22:47:04 -05:00
bors
bc069efb1f Auto merge of #8688 - kyoto7250:adding_condition_for_map_clone, r=giraffate
adding condition for map_clone message

This PR fixes the message about `map_clone`.

if msrv >= 1.36, the message is correct.

```bash
$ cat main.rs
fn main() {
  let x: Vec<&i32> = vec![&1, &2];
  let y: Vec<_>  = x.iter().map(|i| *i).collect();
  println!("{:?}", y);
}

$ cargo clippy
warning: you are using an explicit closure for copying elements
 --> main.rs:3:20
  |
3 |   let y: Vec<_>  = x.iter().map(|i| *i).collect();
  |                    ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.iter().copied()`
  |
  = note: `#[warn(clippy::map_clone)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone

warning: `test` (build script) generated 1 warning
warning: `test` (bin "test") generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
```

but, if msrv < 1.36, the suggestion is `cloned`, but the message is `copying`.
```bash
$ cat clippy.toml
msrv = "1.35"

$ cargo clippy
warning: you are using an explicit closure for copying elements
 --> main.rs:3:20
  |
3 |   let y: Vec<_>  = x.iter().map(|i| *i).collect();
  |                    ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.iter().cloned()`
```

I think  the separation of messages will make it more user-friendly.

thank you in advance.

changelog: Fixed a message in map_clone.
2022-04-12 01:11:54 +00:00
kyoto7250
9716a9eff0 adding condition for map_clone message
if msrv < 1.36, the message tells , but the suggestion is
2022-04-12 04:03:48 +09:00
bors
dbcd82885f Auto merge of #8624 - pitaj:is_digit_ascii_radix, r=xFrednet
New lint `is_digit_ascii_radix`

Closes #6399

changelog: Added [`is_digit_ascii_radix`]: recommend `is_ascii_digit()` or `is_ascii_hexdigit()` in place of `is_digit(10)` and `is_digit(16)`
2022-04-11 18:56:21 +00:00