Commit Graph

12173 Commits

Author SHA1 Message Date
bors
95d91d64db Auto merge of #7617 - xFrednet:0000-link-diag-item-docs, r=giraffate
Reference new diagnostic item docs in our docs :)

The title says it all. The rustc dev guide now has some information about diagnostic items that are worthwhile linking to 🙃

---

changelog: none
2021-09-02 01:04:40 +00:00
xFrednet
0fa9bf4a40 Reference new diagnostic item docs in our docs :) 2021-09-01 21:55:08 +02:00
bors
87c375fa62 Auto merge of #7605 - xordi:issue-7548-fix, r=giraffate
Issue 7548 fix

Close #7548

changelog: [`bool_assert_comparison`] fixes should be emitted only in case they are comparing a value of a type that implements the `Not` trait with an output of type `bool` against a boolean literal.
2021-08-31 13:36:20 +00:00
xordi
83f1454ade Fix function and variable names 2021-08-31 09:06:14 +02:00
xordi
aee4f1fc0c Fix CI errors 2021-08-31 08:56:53 +02:00
xordi
abbcea86ff Add new ui tests 2021-08-31 08:56:53 +02:00
xordi
f75d1b2bc5 Check for Not trait implementation 2021-08-31 08:56:53 +02:00
bors
fd30241281 Auto merge of #7573 - Jarcho:option_if_let_else, r=giraffate
Fix `option_if_let_else`

fixes: #5822
fixes: #6737
fixes: #7567

The inference from #6137 still exists so I'm not sure if this should be moved from the nursery. Before doing that though I'd almost want to see this split into two lints. One suggesting `map_or` and the other suggesting `map_or_else`.

`map_or_else` tends to have longer expressions for both branches so it doesn't end up much shorter than a match expression in practice. It also seems most people find it harder to read. `map_or` at least has the terseness benefit of being on one line most of the time, especially when the `None` branch is just a literal or path expression.

changelog: `break` and `continue` statments local to the would-be closure are allowed in `option_if_let_else`
changelog: don't lint in const contexts  in `option_if_let_else`
changelog: don't lint when yield expressions are used  in `option_if_let_else`
changelog: don't lint when the captures made by the would-be closure conflict with the other branch  in `option_if_let_else`
changelog: don't lint when a field of a local is used when the type could be pontentially moved from  in `option_if_let_else`
changelog: in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure  in `option_if_let_else`
2021-08-30 13:57:21 +00:00
bors
5e1e9b0c6e Auto merge of #7600 - xFrednet:0000-update-issue-templates, r=camsteffen
Updated issue templates(formatting and rustbot label reference)

This PR updates our issue templates. The changes are:

1. **Make the *Meta* section smaller and not indented**

    The current format sometimes gets messed up when a user simply pasts the rustc version into the issue without indenting it to match the code block. Removing the indention should hopefully help with formatting in the future.

    <details><summary>Example of messed up formatting </summary>

    ![image](https://user-images.githubusercontent.com/17087237/130811809-2b9bc58e-c13f-4338-b34e-18648a5de413.png)

    </details>

    Additionally, I've removed the Version of Clippy from the template. Every issue that I have seen had matching rustc and Clippy versions, and just asking for `rustc -Vv` makes the issue look cleaner IMO.

2. **Add a comment explaining how additional labels can be added with ``@rustbot` label +<label>`. The explanation looks like this:**

    ```
    <!--
    Additional labels can be added to this issue by including the following command:

    `@rustbot` label +<label>

    Common labels for this issue type are:
    * `I-suggestion-causes-error`
    -->
    ```

    The example ``@rustbot`` call can sadly not be marked as code inside a comment block. But the example will not cause the bot to add any labels. See rust-lang/rust-clippy#7599

---

changelog: none

cc: `@rust-lang/clippy`
2021-08-27 15:42:09 +00:00
Jason Newcomb
3e5dcba2ee
Small cleanup of option_if_let_else and additional tests. 2021-08-26 11:44:36 -04:00
bors
a4a3f61c9f Auto merge of #7602 - flip1995:needless_collect_appl, r=xFrednet
Set applicability of needless_collect to MaybeIncorrect

Fixes rust-lang/rust#88333

changelog: Set applicability of [`needless_collect`] to MaybeIncorrect
2021-08-26 11:42:47 +00:00
bors
387dbd7da9 Auto merge of #7583 - dswij:match-trait-docs, r=xFrednet
Tweak common tool docs on type-implement-trait check

See https://github.com/rust-lang/rust-clippy/pull/7562#issuecomment-898240963.

changelog: none
2021-08-26 10:04:12 +00:00
dswij
f0cb8a789a
Update doc/common_tools_writing_lints.md
Add missing import `paths` for the doc example.

Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2021-08-26 18:01:41 +08:00
dswij
86e92c0033 Update common tool docs on type implement trait check
Common tool documentation uses `match_trait_method` which is deprecated.
Additionally, adds information on why `is_trait_method` is not the
preferred way.
2021-08-26 17:29:28 +08:00
flip1995
c6e420266a
Set applicability of needless_collect to MaybeIncorrect 2021-08-26 10:01:11 +01:00
bors
de80188c64 Auto merge of #7543 - DevinR528:disallowed-mod, r=Manishearth
Add module_style lint to style

changelog: Add new [`module_style`] style lint

This is a configurable (no mod file/mod file) lint that determines if `mod.rs` is used consistently or if `mod.rs` is never used (using the new mod layout).
2021-08-25 15:20:28 +00:00
xFrednet
10909ae390 Updated issue templates(formatting and rustbot label reference) 2021-08-25 16:39:09 +02:00
bors
305177342f Auto merge of #7453 - F3real:assume_function_calls_have_side_effect, r=flip1995
Don't report function calls as unnecessary operation if used in array index

Attempts to fix: #7412

changelog: Don't report function calls used in indexing as unnecessary operation. [`unnecessary_operation`]
2021-08-25 08:31:20 +00:00
Devin Ragotzy
31738b1da3 Add module_style lint to restriction
Add tests for disallowed_mod in ui-cargo test section

Use correct algorithm to determine if mod.rs is missing

Move to two lints and remove config option

Switch lint names so they read "warn on ..."

Emit the same help info for self_named_mod_file warnings

Bail when both lints are Allow

Reword help message for both module_style lints
2021-08-24 15:53:58 -04:00
bors
87c6f32756 Auto merge of #7592 - lengyijun:redundant_allocation, r=camsteffen
redundant_allocation: fix 7487

Fixes #7487

changelog: [`redundant_allocation`] - allow `Box<Box<dyn T>>` which replaces wide pointers with thin pointers
2021-08-24 12:32:01 +00:00
lengyijun
641be558fc redundant_allocation: fix 7487 2021-08-24 13:03:48 +08:00
bors
15b1c6f1a2 Auto merge of #7595 - camsteffen:branches-sharing-nursery, r=Manishearth
Move branches_sharing_code to nursery

changelog: Move [`branches_sharing_code`] to nursery

...since there are quite a few [open bugs](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+is%3Aopen+branches_sharing_code).
2021-08-23 19:18:09 +00:00
Cameron Steffen
2f73776525 Move branches_sharing_code to nursery 2021-08-23 13:40:04 -05:00
bors
6ca00075ee Auto merge of #7593 - camsteffen:remove-stderr-limit, r=Manishearth
Remove stderr limit

changelog: none

Discussed at https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Increase.20test.20stderr.20length.20limit.3F
2021-08-23 16:14:50 +00:00
Cameron Steffen
68b4a43e23 Remove stderr limit 2021-08-23 11:02:03 -05:00
bors
22606e7358 Auto merge of #7539 - Labelray:master, r=camsteffen
Add new lint `negative_feature_names` and `redundant_feature_names`

Add new lint [`negative_feature_names`] to detect feature names with prefixes `no-` or `not-` and new lint [`redundant_feature_names`] to detect feature names with prefixes `use-`, `with-` or suffix `-support`
changelog: Add new lint [`negative_feature_names`] and [`redundant_feature_names`]
2021-08-23 13:56:18 +00:00
Labelray
0a021d5900 Add new lints negative_feature_names and redundant_feature_names 2021-08-23 21:05:44 +08:00
bors
1fc1aee7be Auto merge of #7565 - Jarcho:manual_split_once, r=llogiq
New lint `manual_split_once`

This is a WIP because it still needs to recognize more patterns. Currently handles:

```rust
s.splitn(2, ' ').next();
s.splitn(2, ' ').nth(0)
s.splitn(2, ' ').nth(1);
s.splitn(2, ' ').skip(0).next();
s.splitn(2, ' ').skip(1).next();
s.splitn(2, ' ').next_tuple(); // from itertools

// as well as `unwrap()` and `?` forms
```

Still to do:

```rust
let mut iter = s.splitn(2, ' ');
(iter.next().unwrap(), iter.next()?)

let mut iter = s.splitn(2, ' ');
let key = iter.next().unwrap();
let value = iter.next()?;
```

Suggestions on other patterns to check for would be useful. I've done a search on github for uses of `splitn`. Still have yet to actually look through the results.

There's also the question of whether the lint shouold trigger on all uses of `splitn` with two values, or only on recognized usages. The former could have false positives where it couldn't be replaced, but I'm not sure how common that would be.

changelog: Add lint `manual_split_once`
2021-08-17 21:15:48 +00:00
bors
cde7e6b8d3 Auto merge of #7578 - xFrednet:7172-update-some-docs, r=camsteffen
Small documentation update for the new metadata_collector

Just small documentation updates after the merge of the new metadata collection. I'm also here to deliver on the promised fairy tale:

*Once upon a time, there was a world with many languages. One of the oldest was C a very versatile language that gave great power for the cost of great complexity and manual work. C was so powerful that it was able to create new languages. There is Java a versatile language often used by companies and in formal settings. Python that focused on readability and rapid prototyping capabilities. JavaScript which has some interesting edge cases but was still loved and widely used in the world. Together they build the foundation of our world and continue to shape the interactions between kingdoms worldwide.*

*C ruled as the king of Linux and other operating systems alongside the Queen C++. Together they were powerful leaders, in fact so powerful that they have been ruling this world for over 49 years. They remain happy together and loved by the community. However, with great power comes great responsibility! The two of them have a dark secret. To tell the truth, they sometimes suffer from memory loss and even worse in some instances from race conditions.*

*A mystical creature called Firefox lead to the creation of Mozilla, a global organization fighting for privacy and for their market share in the browser marked. As part of this fight, they started to modify parts of Firefox and eventually created Servo. A completely new creature with a new language called Rust. This new form of communication was focussed on correctness, speed and a new model of memory management.*

*Rust grew up over several years with modification to syntax, content among other things. Finally, in 2015 Rust has reached adulthood which enabled it to take part in the global discourse and shape the future of our world. Some even say that this was the start of a new area withing language design.*

*Rust had already started to build its kingdom and was now the head of a complete organization, with teams being in charge of individual tools used for further development. One team focussing on further improving Rust when it comes to complexity, style and performance was **The Clippy Team**. Its members were a friendly bunch, with mages and wizards among them.*

*With the goal of giving more power to Rust, they identified a Python tool inside Clippy that could be rewritten. This led to the creating of the **Metadata collection monster**. This monster soon replaced the old Python tool and allowed for new creative additions inside Clippy's lint list. With the eradication of the old tool, there came a possibility to update the configuration documentation to span over a lager area. This was done, but some doc comments remained until now in memory of the old tool. This is now the PR that removes these doc comments.*

---

I have to stop now, this already took way longer than the actual changes. It probably also contains some spelling mistakes, but oh well. I hope you get the gist of it 🙃.

---

r? `@camsteffen`

changelog: none
2021-08-17 17:55:28 +00:00
xFrednet
c01aa64591 Small documentation update for the new metadata_collector 2021-08-17 14:51:56 +02:00
bors
c50e6e4203 Auto merge of #7574 - Jarcho:expl_impl_clone_on_copy_doc, r=giraffate
Update docs for `expl_impl_clone_on_copy`

The known issue was fixed in #6993. I missed updating the docs then, so it's happening now.

changelog: None
2021-08-17 00:23:43 +00:00
Jason Newcomb
3c6c7d5de9
Update docs for expl_impl_clone_on_copy. Bug was fixed in 879fa5c9721c89c27be6a9db5f51d935a51f549b1~ 2021-08-16 19:57:14 -04:00
Jason Newcomb
8b3ca9a315
Fix option_if_let_else
* `break` and `continue` statments local to the would-be closure are allowed
* don't lint in const contexts
* don't lint when yield expressions are used
* don't lint when the captures made by the would-be closure conflict with the other branch
* don't lint when a field of a local is used when the type could be pontentially moved from
* in some cases, don't lint when scrutinee expression conflicts with the captures of the would-be closure
2021-08-16 16:12:00 -04:00
Jason Newcomb
aab3267412
Update docs for manual_split_once 2021-08-16 09:35:03 -04:00
Jason Newcomb
a7f376fbd3
Add lint manual_split_once 2021-08-16 09:34:58 -04:00
Jason Newcomb
8cf6dae0ca
Add for_each_local_usage. Switch LocalUsedVisitor to a function. 2021-08-16 09:34:42 -04:00
bors
983e5b877e Auto merge of #7566 - dswij:manual-flatten-use, r=xFrednet
Check expr usage for  `manual_flatten`

Fixes #6784
Fixes #7538

`manual_flatten` should not trigger when `if let` match expression will be used.

changelog: [`manual_flatten`] checks for expr usage after `if let`
2021-08-16 08:35:06 +00:00
dswij
a09bc1b6fe Check if let expr usage in manual_flatten
`manual_flatten` should not trigger when match expression in `if let` is
going to be used.
2021-08-16 16:25:10 +08:00
dswij
711c5cb6d2 Add false positive test for manual_flatten
Add a scenario where `manual_flatten` is triggered when match expression will still be used after the match in `if let`.
2021-08-16 16:24:44 +08:00
bors
3f0c97740f Auto merge of #7531 - Jarcho:manual_map_7413, r=camsteffen
Manual map 7413

fixes: #7413

This only fixes the specific problem from #7413, not the general case. The full fix requires interacting with the borrow checker to determine the lifetime of all the borrows made in the function. I'll open an issue about it later.

changelog: Don't suggest using `map` when the option is borrowed in the match, and also consumed in the arm.
changelog: Locals declared within the would-be closure will not prevent the closure from being suggested in `manual_map` and `map_entry`
2021-08-16 01:48:01 +00:00
Jason Newcomb
f0444d73de
Use each_binding_or_first in capture_local_usage 2021-08-15 20:32:47 -04:00
bors
d4e2fcabb1 Auto merge of #7521 - rukai:fix_lintcheck_local_path_handling, r=camsteffen
lintcheck always copies in a fresh crate when provided with a crate path

changelog: none

When lintcheck is run on local crates it copies the crate to `target/lintcheck/sources/crate_name` on the first run only.
Then in subsequent runs of lintcheck it reuses this same copy.
This caching behaviour makes sense when dealing with immutable crates.io releases and git commits.
However it is quite surprising that the changes to my local crate are not used when I run lintcheck.

To fix this I removed the copy, instead clippy runs directly off the provided crate folder.
I have tested this and have not observed any negative effects from doing this.
But maybe i'm missing something as im not familiar with clippy!

Alternatively we could make it copy the entire crate every run, but that seems problematic to me as multi-gigabyte target folders will take a long time to copy and wear down SSDs for developers who frequently run lintcheck.
2021-08-16 00:20:31 +00:00
Lucas Kent
997ddbbfd8 Lintcheck always copies in a fresh crate when provided with a crate path
but skips directories containing CACHEDIR.TAG e.g. the target/ dir
2021-08-16 10:18:24 +10:00
bors
5449e23e67 Auto merge of #7568 - dtolnay-contrib:ifletelse, r=llogiq
Downgrade option_if_let_else to nursery

I believe that this lint's loose understanding of ownership (#5822, #6737) makes it unsuitable to be enabled by default in its current state, even as a pedantic lint.

Additionally the lint has known problems with type inference (#6137), though I may be willing to consider this a non-blocker in isolation if it weren't for the ownership false positives.

A fourth false positive involving const fn: #7567.

But on top of these, for me the biggest issue is I basically fully agree with https://github.com/rust-lang/rust-clippy/issues/6137#issuecomment-705605688. In my experience this lint universally makes code worse even when the resulting code does compile.

---

changelog: remove [`option_if_let_else`] from default set of enabled lints
2021-08-15 12:02:24 +00:00
Jason Newcomb
10c0460a47
update stderr messages 2021-08-14 19:52:59 -04:00
Jason Newcomb
5e4d8b44f9
Improve doc for can_move_expr_to_closure_no_visit 2021-08-14 19:50:01 -04:00
Jason Newcomb
9500974bdb
Fix tracking of which locals would need to be captured in a closure.
* Captures by sub closures are now considered
* Copy types are correctly borrowed by reference when their value is used
* Fields are no longer automatically borrowed by value
* Bindings in `match` and `let` patterns are now checked to determine how a local is captured
2021-08-14 19:49:57 -04:00
Jason Newcomb
251dd30d77
Improve manual_map
In some cases check if a borrow made in the scrutinee expression would prevent creating the closure used by `map`
2021-08-14 19:49:54 -04:00
Jason Newcomb
4838c78ba4
Improve manual_map and map_entry
Locals which can be partially moved created within the to-be-created closure shouldn't block the use of a closure
2021-08-14 19:49:45 -04:00
David Tolnay
3c8eaa8b2c
Downgrade option_if_let_else to nursery 2021-08-14 05:47:01 -07:00