Commit graph

6156 commits

Author SHA1 Message Date
Ryan Levick
611b74e1fe Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
valentine-mario
44608b1857 added lint to check for full range of vector and suggest append 2021-06-10 09:12:06 +01:00
bors
f7d09b45e9 Auto merge of #7333 - camsteffen:match-var, r=llogiq
Factor out match_var and get_pat_name utils

...because checking vars by name is bad, because of shadowing.

changelog: none
2021-06-10 05:20:56 +00:00
bors
ce7b872341 Auto merge of #7332 - lengyijun:redundant_clone_fix, r=giraffate
redundant_clone: fix comment

changelog: none
2021-06-10 00:54:25 +00:00
bors
c4636abe72 Auto merge of #7315 - DevinR528:disallowed-ty, r=giraffate
Add disallowed_type lint, this adds a field to the conf struct

Fixes #7277

changelog: Add ``[`disallowed_type`]`` a lint that can enforce banning types specified in the config.
2021-06-10 00:30:36 +00:00
Thomas de Zeeuw
0d3f289b66 Add FreeBSD as identifier not needing ticks
For the doc-markdown lint.
2021-06-09 17:16:10 +02:00
Cameron Steffen
b792bb301c Factor out match_var 2021-06-09 09:47:42 -05:00
Devin Ragotzy
ea45e2a9cf Add disallowed_types lint, this adds a field to the Conf struct
Replace use of node_type -> node_type_opt, fix clippy warnings

Don't walk the hir unnecessarily let the visitor do it
2021-06-09 07:21:16 -04:00
bors
dd0246813f Auto merge of #7326 - 1c3t3a:1c3t3a-issue-7324, r=flip1995
Fix false positive on `semicolon_if_nothing_returned`

Currently the [`semicolon_if_nothing_returned`](https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned) lint fires in unwanted situations where a block only spans one line. An example of this was given in #7324. This code:

```rust
use std::mem::MaybeUninit;
use std::ptr;

fn main() {
    let mut s = MaybeUninit::<String>::uninit();
    let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
}
```

yields the following clippy error:
```
error: consider adding a `;` to the last statement for consistent formatting
 --> src/main.rs:6:26
  |
6 |     let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
  |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
  |
  = note: `-D clippy::semicolon-if-nothing-returned` implied by `-D clippy::pedantic`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
```

I updated the lint to check if the statement is inside an `unsafe` block, a closure or a normal block and if the block only spans one line, in that case the lint is not emitted.

This closes #7324.

changelog: enhanced semicolon if nothing returned according to  #7324.
2021-06-09 08:39:56 +00:00
bors
da0538eaca Auto merge of #7330 - xFrednet:0000-refactor-map-identity, r=flip1995
Refactoring identity function lints

I've noticed that we have several lints that all check for identity functions and each used their own check implementation. I moved the `is_expr_identity_function` function to `clippy_utils` and adapted all lints to reuse that one function. This should make the addition of new lints like this also easier in the future.

I've also moved the `map_identity` lint into the `methods` module. It's probably the best to review this PR by checking each commit individually. And that's it, have a great day 🙃

changelog: none
2021-06-09 08:27:05 +00:00
Bastian Kersting
5ec80f32c7 Refactored multiline check 2021-06-09 09:43:25 +02:00
lyj
fe549f711a redundant_clone: fix comment 2021-06-09 15:25:48 +08:00
xFrednet
5336f88403 Move map_identity into the methods module 2021-06-08 19:56:59 +02:00
bors
07217e3370 Auto merge of #7262 - Jarcho:while_let_on_iter_closure, r=xFrednet,flip1995
fix `while_let_on_iterator` suggestion in a closure

fixes: #7249

A future improvement would be to check if the closure is being used as `FnOnce`, in which case the original suggestion would be correct.

changelog: Suggest `&mut iter` inside a closure for `while_let_on_iterator`
2021-06-08 15:52:40 +00:00
xFrednet
9e54ce865c Reuse is_expr_identity_function for filter_map_identity 2021-06-07 23:31:17 +02:00
xFrednet
bb3b58cfcc Reuse is_expr_identity_function for flat_map_identity 2021-06-07 23:20:11 +02:00
xFrednet
967d815a42 Extracting is_expr_identity_function into clippy_utils for reusability 2021-06-07 22:42:11 +02:00
Bastian Kersting
6bf8303c47 Refactored the check for two spans on the same line 2021-06-07 22:05:53 +02:00
Smitty
c864e18678 Remove some last remants of {push,pop}_unsafe!
These macros have already been removed, but there was still some code
handling these macros. That code is now removed.
2021-06-06 17:04:03 -04:00
Yoshitomo Nakanishi
d7a380e4b9 Fix FP in default_numeric_fallback with external macro expansion 2021-06-06 12:43:22 +09:00
Bastian Kersting
790888d520 Fixed failing tests 2021-06-05 18:54:41 +02:00
Bastian Kersting
96747c1a46 Enhance semicolon_if_nothing_returned according to #7324 2021-06-05 18:54:41 +02:00
lyj
896c19e2cf rc_mutex: update doc 2021-06-05 21:42:45 +08:00
lyj
a5ced1fc2b rc_mutex use span_lint instead of span_lint_and_sugg 2021-06-05 21:19:05 +08:00
bors
9991040258 Auto merge of #7289 - camsteffen:needless-collect-shadow, r=Manishearth
Fix needless_collect with binding shadowing

changelog: Fix [`needless_collect`] weird output when a binding is shadowed

Fixes #7200
2021-06-04 15:39:16 +00:00
Joshua Nelson
390893c600 Remove doc(include) 2021-06-04 08:05:54 -04:00
lyj
c0f3c2fe27 correct lint 2021-06-04 10:44:34 +08:00
lyj
84c511facf rc_mutex 2021-06-03 16:25:27 +08:00
flip1995
6c27482115 Merge commit '3ae8faff4d46ad92f194c2a4b941c3152a701b31' into clippyup 2021-06-03 08:41:37 +02:00
Jason Newcomb
cfddf0927b
Fix type checks for manual_str_repeat 2021-05-31 09:37:13 -04:00
Jason Newcomb
97311f0906
Add lint manual_str_repeat 2021-05-30 23:26:48 -04:00
Steven Engler
58491d386a Update message for 'not_unsafe_ptr_arg_deref' lint 2021-05-30 20:19:57 -04:00
bors
d1308aecaf Auto merge of #7292 - Jarcho:suspicious_splitn, r=flip1995
Add lint `suspicious_splitn`

fixes: #7245
changelog: Add lint `suspicious_splitn`
2021-05-30 20:32:22 +00:00
Jason Newcomb
5fa08eaf53
Evaluate constant expressions in suspicious_splitn 2021-05-30 13:25:24 -04:00
Jason Newcomb
898b6a0e07
Add lint suspicious_splitn 2021-05-30 09:49:55 -04:00
Jason Newcomb
4ba6afd192
Fix ICE in too_many_lines due to wrong assumptions on braces. 2021-05-27 22:44:08 -04:00
Cameron Steffen
21c829e0c8 Simplify collect expr_ty 2021-05-27 20:54:56 -05:00
Cameron Steffen
6c1ba7c1bc Fix needless_collect with binding shadowing 2021-05-27 20:39:59 -05:00
Cameron Steffen
29b4b4c10d Do not lint use_self on type parameters 2021-05-27 20:18:07 -05:00
Cameron Steffen
d3c20c835f Some cleanup for use_self 2021-05-27 16:25:17 -05:00
Cameron Steffen
d39a11cbe1 Remove clippy_utils::consts re-export 2021-05-27 08:52:10 -05:00
bors
2fa9362448 Auto merge of #7281 - camsteffen:has-doc-fp, r=flip1995
Fix missing_docs_in_private_items false negative

changelog: Fix [`missing_docs_in_private_items`] false negative when the item has any `#[name = "value"]` attribute

Closes #7247 (decided not to use the rustc method since it calls `Session::check_name`, which is for rustc only)
2021-05-27 08:37:08 +00:00
bors
8066f836ec Auto merge of #7282 - camsteffen:lint-stmt-expr, r=flip1995
Fix allow on some statement lints

changelog: Fix `#[allow(..)]` over statements for [`needless_collect`], [`short_circuit_statement`] and [`unnecessary_operation`]

Fixes #7171
Fixes #7202
2021-05-27 08:23:21 +00:00
bors
9c4651f2ee Auto merge of #7187 - camsteffen:avoid-break-exported, r=flip1995,phansch
Add avoid_breaking_exported_api config option

changelog: Add `avoid_breaking_exported_api` config option for [`enum_variant_names`], [`large_types_passed_by_value`], [`trivially_copy_pass_by_ref`], [`unnecessary_wraps`], [`upper_case_acronyms`] and [`wrong_self_convention`].

changelog: Deprecates [`pub_enum_variant_names`] and [`wrong_pub_self_convention`] as the non-pub variants are now configurable.

changelog: Fix various false negatives for `pub` items that are not exported from the crate.

A couple changes to late passes in order to use `cx.access_levels.is_exported` rather than `item.vis.kind.is_pub`.

I'm not sure how to better document the config option or lints that are (not) affected (see comments in #6806). Suggestions are welcome. cc `@rust-lang/clippy`

I added `/clippy.toml` to use the config internally and `/tests/clippy.toml` to maintain a default config in ui tests.

Closes #6806
Closes #4504
2021-05-27 04:49:56 +00:00
Cameron Steffen
f3e77a454a Fix allow on some statement lints 2021-05-26 22:07:53 -05:00
Cameron Steffen
6eea598645 Fix config file lookup 2021-05-26 21:53:43 -05:00
bors
f205dd176a Auto merge of #7280 - camsteffen:macro-use, r=Manishearth
Add macro_use clippy_utils

changelog: none
2021-05-26 22:15:07 +00:00
Cameron Steffen
55ccc7a8c6 Use break api config for upper_case_acronyms 2021-05-26 16:53:13 -05:00
Cameron Steffen
1ce581d706 Use break api config for unnecessary_wraps 2021-05-26 16:53:13 -05:00
Cameron Steffen
3d77a2b861 Use break api config for enum_variant_names 2021-05-26 16:53:13 -05:00
Cameron Steffen
ee79077d80 Use break api config for pass by value or ref 2021-05-26 16:53:13 -05:00
Cameron Steffen
d7f47f280e Use break api config for wrong_pub_self_convention 2021-05-26 16:53:13 -05:00
Cameron Steffen
2e2021bbda Add avoid_breaking_exported_api config option 2021-05-26 16:35:22 -05:00
Cameron Steffen
c21b965d43 Fix missing_docs_in_private_items FP 2021-05-26 16:25:38 -05:00
Cameron Steffen
5cc6635fcf Add macro_use clippy_utils 2021-05-26 16:11:18 -05:00
mbartlett21
bcebea65c1 Run cargo fmt 2021-05-25 06:05:52 +00:00
mbartlett21
9cad27fce8 Add semicolon in needless_for_each.rs 2021-05-25 02:06:45 +00:00
mbartlett21
6d73777224 Fix same_item_push.rs 2021-05-25 02:03:31 +00:00
mbartlett21
527fb42a32 Add all the semicolons to clippy_lints 2021-05-25 01:46:33 +00:00
mbartlett21
cadad20da1 Add semicolons up to needless_for_each.rs 2021-05-25 00:54:50 +00:00
mbartlett21
1ac7e19b4c Move semicolon_if_nothing_returned to pedantic 2021-05-24 22:09:07 +00:00
Pietro Albini
91aa821745 remove cfg(bootstrap) 2021-05-24 11:07:48 -04:00
Cameron Steffen
24743b3968 Use UnhashMap 2021-05-24 09:48:05 -05:00
Michael Wright
2f78d57d8b Downgrade suspicious_op..._groupings to Nursery
This addresses #6722.
2021-05-24 06:44:38 +02:00
bors
41bb092185 Auto merge of #7255 - whatisaphone:feat/similar-names-wparam-lparam, r=giraffate
Allow wparam and lparam in similar_names

`wparam` and `lparam` are often used as generic parameter names in win32 (for example [WindowProc](https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms633573(v=vs.85))). This PR adds them to the similar_names exception list.

changelog: [`similar_names`] don't treat wparam and lparam as similar
2021-05-24 00:20:17 +00:00
bors
297e7433bf Auto merge of #7264 - yotamofek:from_iter_instead_collect_as_trait, r=llogiq
Fix invalid syntax in `from_iter_instead_of_collect` suggestion

First attempt at contributing, hopefully this is a good start and can be improved. :)

fixes #7259

changelog: [`from_iter_instead_of_collect`] fix invalid suggestion involving "as Trait"
2021-05-22 23:08:51 +00:00
bors
87871864b3 Auto merge of #7263 - Jarcho:redundant_closure_macro, r=llogiq
Fix `redundant_closure` for `vec![]` macro in a closure with arguments

fixes: #7224
changelog: Fix `redundant_closure` for `vec![]` macro in a closure with arguments
2021-05-22 21:41:08 +00:00
Yotam Ofek
ae0d4da764 Fix invalid syntax in from_iter_instead_of_collect suggestion with "as Trait" 2021-05-22 21:47:11 +03:00
Jason Newcomb
60dd2b65dc
Fix redundant_closure for vec![] macro in a closure with arguments 2021-05-21 15:48:29 -04:00
Jason Newcomb
7db0e4f791
Suggest &mut iter inside a closure for while_let_on_iterator 2021-05-21 12:27:40 -04:00
Jason Newcomb
f355aebf10
Move needless_borrow to style 2021-05-21 11:24:52 -04:00
John Simon
2eafec182d Allow wparam and lparam in similar_names 2021-05-20 10:20:14 -04:00
Jason Newcomb
6d4dc35882
Improve needless_borrow lint
Suggest changing usages of ref bindings to match the new type
Split out some cases into new lint `ref_binding_to_reference`
2021-05-20 09:03:47 -04:00
Jason Newcomb
6e03a306ac
Remove fix for rustc bug from needless_borrow
The spans given for derived traits used to not indicate they were from a macro expansion.
2021-05-20 09:03:31 -04:00
flip1995
7304829115
Early return from LintPass registration when collecting metadata
This speeds up the metadata collection by 2-2.5x on my machine. During
metadata collection other lint passes don't have to be registered, only
the lints themselves.
2021-05-20 13:57:52 +02:00
flip1995
97705b7ea6 Merge commit '9e3cd88718cd1912a515d26dbd9c4019fd5a9577' into clippyup 2021-05-20 13:07:57 +02:00
flip1995
451ff5668b
Merge remote-tracking branch 'upstream/master' into rustup 2021-05-20 12:05:02 +02:00
Fridtjof Stoldt
9dc366bc4d
Fixed a type
Co-authored-by: Philipp Krones <hello@philkrones.com>
2021-05-19 17:23:33 +02:00
xFrednet
8036d7f784 Adding the default lint level to the metadata collection
And stripping the clippy:: prefix from the group
2021-05-19 16:42:21 +02:00
bors
4f3b49fffa Auto merge of #84767 - scottmcm:try_trait_actual, r=lcnr
Implement the new desugaring from `try_trait_v2`

~~Currently blocked on https://github.com/rust-lang/rust/issues/84782, which has a PR in https://github.com/rust-lang/rust/pull/84811~~ Rebased atop that fix.

`try_trait_v2` tracking issue: https://github.com/rust-lang/rust/issues/84277

Unfortunately this is already touching a ton of things, so if you have suggestions for good ways to split it up, I'd be happy to hear them.  (The combination between the use in the library, the compiler changes, the corresponding diagnostic differences, even MIR tests mean that I don't really have a great plan for it other than trying to have decently-readable commits.

r? `@ghost`

~~(This probably shouldn't go in during the last week before the fork anyway.)~~ Fork happened.
2021-05-18 20:50:01 +00:00
bors
aa1959b90c Auto merge of #7089 - Jarcho:multiple_impls_generic, r=Jarcho
Don't lint `multiple_inherent_impl` with generic arguments

fixes: #5772
changelog: Treat different generic arguments as different types in `multiple_inherent_impl`
2021-05-18 16:35:48 +00:00
Jason Newcomb
760f70312e
Improve multiple_inherent_impl lint
Treat different generic arguments as different types.
Allow the lint to be ignored on the type definition, or any impl blocks.
2021-05-18 11:45:51 -04:00
Jason Newcomb
a149ba26fa
Fix ICE in implicit_return
async functions always return a value
2021-05-18 10:51:59 -04:00
flip1995
ff452d5ba6
Deny warning in every main sub-crate
This enables the same warnings that are enabled in `clippy_lints` also
in `clippy_utils` and `clippy_dev`. Then it makes sure, that the
`deny-warnings` feature is passed down to `clippy_lints` and
`clippy_utils` when compiling Clippy.
2021-05-18 11:05:48 +02:00
Philipp Krones
99fb776ace
Rollup merge of #7235 - camsteffen:manual-unwrap-or-deref, r=flip1995
Fix another manual_unwrap_or deref FP

changelog: none (since this just piggybacks on #7233)

Fixes #6960
2021-05-18 10:21:55 +02:00
bors
9028173b24 Auto merge of #7201 - mucinoab:master, r=giraffate
Remove powi, "square can be computed more efficiently"

powi(2) produces exactly the same native code as x * x
powi was part of the [`suboptimal_flops`] lint

fixes #7058
changelog: Remove powi [`suboptimal_flops`], "square can be computed more efficiently"
2021-05-18 05:28:42 +00:00
Bruno A. Muciño
be540e6596 Remove powi, "square can be computed more efficiently"
powi(2) produces exactly the same native code as x * x
2021-05-17 21:59:08 -05:00
bors
6fcdb8a297 Auto merge of #7234 - camsteffen:if-let-else-braces, r=flip1995
Remove dead code after #7216

changelog: none
2021-05-17 21:42:21 +00:00
Cameron Steffen
8356c485a9 Fix manual_unwrap_or FP deref reference 2021-05-17 14:20:26 -05:00
Cameron Steffen
ca0f0002a4 Remove dead code after not linting else if let 2021-05-17 14:09:54 -05:00
bors
a3223af9fe Auto merge of #7133 - arya-k:master, r=llogiq
Add `needless_bitwise_bool` lint

fixes #6827
fixes #1594

changelog: Add ``[`needless_bitwise_bool`]`` lint

Creates a new `bitwise_bool` lint to convert `x & y` to `x && y` when both `x` and `y` are booleans. I also had to adjust thh `needless_bool` lint slightly, and fix a couple failing dogfood tests. I made it a correctness lint as per flip1995's comment [here](https://github.com/rust-lang/rust-clippy/pull/3385#issuecomment-434715723), from a previous WIP attempt at this lint.
2021-05-17 18:57:14 +00:00
Cameron Steffen
b2270e1f45 Simplify manual_unwrap_or 2021-05-17 13:54:25 -05:00
bors
1aad7541db Auto merge of #7223 - ThibsG:FpUselessConversion7205, r=camsteffen
Fix FPs about generic args

Fix 2 false positives in [`use_self`] and [`useless_conversion`] lints, by taking into account generic args and comparing them.

Fixes: #7205
Fixes: #7206

changelog: Fix FPs about generic args in [`use_self`] and [`useless_conversion`] lints
2021-05-17 17:40:48 +00:00
bors
cec8d95729 Auto merge of #7233 - giraffate:fix_manual_unwrap_or_fp_with_deref_coercion, r=flip1995
Fix a `manual_unwrap_or` FP with deref coercion

Fix https://github.com/rust-lang/rust-clippy/issues/7228.

changelog: Fix a [`manual_unwrap_or`] FP with deref coercion
2021-05-17 17:13:57 +00:00
ThibsG
2fb35ce4f0 Add generic args for comparison in use_self and useless_conversion lints 2021-05-17 17:27:16 +02:00
Arya Kumar
0dcde71224 Fix missing variable init in lint example 2021-05-17 15:00:15 +00:00
Takayuki Nakata
ebf065e517 Fix a manual_unwrap_or FP with deref coercion 2021-05-17 22:18:50 +09:00
bors
acdf43f257 Auto merge of #7225 - InquisitivePenguin:unnessecary-async, r=llogiq
New lint: `unused_async`

changelog: Adds a lint, `unused_async`, which checks for async functions with no await statements

`unused_async` is a lint that reduces code smell and overhead by encouraging async functions to be refactored into synchronous functions.

Fixes #7176

### Examples

```rust
async fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}
```

Could be written as:

```rust
fn get_random_number() -> i64 {
    4 // Chosen by fair dice roll. Guaranteed to be random.
}
```

Something like this, however, should **not** be caught by clippy:
```rust
#[async_trait]
trait AsyncTrait {
    async fn foo();
}

struct Bar;

#[async_trait]
impl AsyncTrait for Bar {
    async fn foo() {
        println!("bar");
    }
}
```
2021-05-17 06:00:55 +00:00
bors
44e0747664 Auto merge of #7216 - ThibsG:OptionIfLetElse7006, r=llogiq
Stop linting `else if let` pattern in [`option_if_let_else`] lint

For readability concerns, it is counterproductive to lint `else if let` pattern.
Unfortunately the suggested code is much less readable.

Fixes: #7006

changelog: stop linting `else if let` pattern in [`option_if_let_else`] lint
2021-05-17 05:45:24 +00:00
bors
c086676657 Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate

The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea.

Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-17 01:42:03 +00:00