Commit Graph

11306 Commits

Author SHA1 Message Date
Cameron Steffen
5f887d09b8 Add if_chain lints 2021-03-31 14:06:27 -05:00
bors
487c2e8d4e Auto merge of #6913 - camsteffen:method-chain, r=flip1995
Destructure args in `methods`

changelog: none

This changes the main pattern in `methods` to match and destructure the method call args at the same time as the method name, and pass individual arg `Expr`s to the lint impls.

```rust
// before
["expect", ..] => expect::check(cx, expr, arg_lists[0]);
// after
("expect", [arg]) => expect::check(cx, expr, recv, arg);
```

This makes the code safer since there is no risk of out of bounds `args[n]` everywhere. There will be no more collecting `method_names`, `arg_lists`, `method_spans` as a separate step - everything comes out of the `match`es. Chained methods are parsed in a nested `match`. This makes the code more verbose in some ways, but IMO it is much easier to follow.

~Definitely should wait for #6896. Just putting out the idea.~
2021-03-31 18:30:32 +00:00
Cameron Steffen
21083875d2 Destructure args in methods module 2021-03-31 13:25:55 -05:00
bors
775ef473d7 Auto merge of #6342 - bbqbaron:issue-6061, r=flip1995
Lint: filter(Option::is_some).map(Option::unwrap)

Fixes #6061

*Please write a short comment explaining your change (or "none" for internal only changes)*
changelog:
* add new lint for filter(Option::is_some).map(Option::unwrap)

First Rust PR, so I'm sure I've violated some idioms. Happy to change anything.

I'm getting one test failure locally -- a stderr diff for `compile_test`. I'm having a hard time seeing how I could be causing it, so I'm tentatively opening this in the hopes that it's an artifact of my local setup against `rustc`. Hoping it can at least still be reviewed in the meantime.

I'm gathering that since this is a method lint, and `.filter(...).map(...)` is already checked, the means of implementation needs to be a little different, so I didn't exactly follow the setup boilerplate. My way of checking for method calls seems a little too direct (ie, "is the second element of the expression literally the path for `Option::is_some`?"), but it seems like that's how some other lints work, so I went with it. I'm assuming we're not concerned about, eg, closures that just end up equivalent to `Option::is_some` by eta reduction.
2021-03-31 16:19:07 +00:00
bors
c1021b806c Auto merge of #6706 - Y-Nak:excessive-for-each, r=camsteffen
New Lint: needless_for_each

resolves: #6543

changelog: Added pedantic lint: `needless_for_each`
2021-03-31 15:59:55 +00:00
Eric Loren
56fbbf7b8f Suggest flatten instead of is_some -> unwrap 2021-03-31 11:35:24 -04:00
Yoshitomo Nakanishi
e61f9782c8 Tweak a suggestion message of needless_for_each 2021-04-01 00:08:59 +09:00
Yoshitomo Nakanishi
bf1e3f7a9f Skip needless_for_each if an input stmt is local 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
1109dc8838 Fix codes that make dogfood fail 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
f2cc995bcf Remove method_calls 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
527fbbef48 Refactor excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5543c34699 Use ".." as default value of snippet in excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
3843171299 Improve the document of excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
25d8b94cec Add comments to clarify why RetCollector is needed 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
ccd7a60023 Refactor: Remove duplicated codes from excessive_for_each 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
90cbbb2da3 Avoid to suggest using label 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5bb0f16552 Trigger the lint iff exposure's body is ExprKind::Block. 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
54a04711ed Change a category of excessive_for_each: Style -> Restriction 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
30952530c5 Fix codes that fails dogfood 2021-04-01 00:05:42 +09:00
Yoshitomo Nakanishi
5029dc805f New Lint: excessive_for_each 2021-04-01 00:05:42 +09:00
bors
3e42c35b72 Auto merge of #6981 - matthiaskrgr:6803_take_2, r=flip1995
disable upper_case_acronyms for pub items - enum edition

Fixes https://github.com/rust-lang/rust-clippy/issues/6803 (again... 😅  )

My previous fix did not work for enums because enum variants were checked separately in the `check_variant` function but it looks like we can't use that because we can't tell if the enum the variants belong to is declared as public or not (it always said `Inherited` for me)

I went and special-cased enums and iterated over all the variants "manually", but only, if the enums is not public.

---

changelog: fix upper_case_acronyms still firing on public enums (#6803)
2021-03-31 15:02:40 +00:00
bors
2e33bf6347 Auto merge of #6938 - Y-Nak:refactor-types, r=flip1995
Refactor types

r? `@flip1995`
This is the last PR to close #6724 🎉
Also, this fixes #6936.

changelog: `vec_box`: Fix FN in `const` or `static`
changelog: `linkedlist`: Fix FN in `const` or `static`
changelog: `option_option`: Fix FN in `const` or `static`
2021-03-31 14:35:48 +00:00
bors
0b76719638 Auto merge of #7007 - Y-Nak:result_unit_err, r=giraffate
result_unit_err: Fix typo

changelog: result_unit_err: fix typo in a diagnostic message

r? `@giraffate`
fixes https://github.com/rust-lang/rust-clippy/pull/6990#discussion_r603292920.
2021-03-31 04:01:15 +00:00
Yoshitomo Nakanishi
45164de59f result_unit_err: Fix typo 2021-03-31 11:18:48 +09:00
bors
4be72b0936 Auto merge of #7001 - ebobrow:non-octal-file-permissions, r=Manishearth
Add non_octal_unix_permissions lint

fixes #6934

changelog: add new lint that checks for non-octal values used to set unix file permissions
2021-03-30 23:23:50 +00:00
Elliot Bobrow
7fcd155712 Add non_octal_unix_permissions lint 2021-03-30 16:04:16 -07:00
bors
44bf60f62d Auto merge of #7004 - Jarcho:manual_map_if_then_else, r=camsteffen
Fix `manual_map` at the end of an if chain

changelog: Fix `manual_map` suggestion at the end of an if chain
2021-03-30 14:03:54 +00:00
Jason Newcomb
fa689f865e
Fix manual_map at the end of an if chain 2021-03-30 09:58:23 -04:00
bors
0552852d9a Auto merge of #7000 - Jarcho:clone_on_copy_fp, r=llogiq
Improve `clone_on_copy`

This also removes the `clone_on_copy_mut` test as the same thing is covered in the `clone_on_copy` test.

changelog: `copy_on_clone` lint on chained method calls taking self by value
changelog: `copy_on_clone` only lint when using the `Clone` trait
changelog: `copy_on_clone` correct suggestion when the cloned value is a macro call.
2021-03-30 05:25:28 +00:00
bors
1ddeaa6356 Auto merge of #6990 - Y-Nak:refactor-functions, r=giraffate
Organize functions into functions module

Ref: #6680
Rearrange lints in `functions`.

changelog: none
2021-03-30 03:59:45 +00:00
Yoshitomo Nakanishi
541c8b8f69 Improve documents in functions group 2021-03-30 11:45:54 +09:00
bors
a521445000 Auto merge of #7003 - giraffate:use_uppercase_for_msrv, r=camsteffen
Use uppercase for MSRV

A follow-up of <https://github.com/rust-lang/rust-clippy/pull/6977/files#diff-dac623e7b9c58138761aa527bf5f026bf113cda5b22eea61e655b44dd113389e>

changelog: none
2021-03-30 00:55:42 +00:00
Takayuki Nakata
23508a1ae2 Use uppercase for MSRV 2021-03-30 08:42:59 +09:00
Jason Newcomb
d2657769a2
Improve clone_on_copy
Lint on `_.clone().method()` when method takes self by value
Set applicability correctly
Correct suggestion when the cloned value is a macro call. e.g. `m!(x).clone()`
Don't lint when not using the `Clone` trait
2021-03-29 16:10:37 -04:00
bors
0e06b3c5f3 Auto merge of #6996 - Y-Nak:missing_panics_doc, r=Manishearth
Allow missing panics doc if the panics occur only when debug-assertions is specified

fixes #6970

changelog: `missing_panics_doc`: Allow missing panics doc if the panics occur only when `debug-assertions` is specified.
2021-03-29 15:04:27 +00:00
Yoshitomo Nakanishi
31afdfc12b missing_panics_doc: Ignore usage of debug_assert family 2021-03-29 17:20:04 +09:00
Yoshitomo Nakanishi
1f95940c24 Fix inconsistent test name 2021-03-29 16:25:30 +09:00
bors
c07103b4a2 Auto merge of #6993 - Jarcho:expl_impl_clone, r=llogiq
Improve `expl_impl_clone_on_copy`

fixes: #1254

changelog: Check to see if the generic constraints are the same as if using derive for `expl_impl_clone_on_copy`
2021-03-28 23:30:56 +00:00
bors
4bcc552587 Auto merge of #6991 - matthiaskrgr:5396, r=giraffate
redundant_pattern_matching: look inside Refs

look inside refs and detect if let &None = ...

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

changelog:  redundant_pattern_matching: look inside Refs to fix FNs with "if let &None = .. "
2021-03-28 14:20:53 +00:00
Jason Newcomb
879fa5c972
Improve expl_impl_clone_on_copy
Check to see if the generic constraints are the same as if using derive
2021-03-28 07:54:00 -04:00
Matthias Krüger
e006c77d61 redundant_pattern_matching: look inside Refs
look inside refs and detect if let &None = ...

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

changelog:  redundant_pattern_matching: look inside Refs to fix FNs with "if let &None = .. "
2021-03-28 00:04:44 +01:00
Yoshitomo Nakanishi
add3e5094f Move result_unit_err to its own module 2021-03-27 22:49:55 +09:00
Yoshitomo Nakanishi
c37916501d Move lints related to must_use to their own module 2021-03-27 22:49:55 +09:00
Yoshitomo Nakanishi
9782fc4285 move not_unsafe_ptr_arg_deref to its own module 2021-03-27 22:49:55 +09:00
Yoshitomo Nakanishi
7c028de05f Move too_many_lines to its own module 2021-03-27 22:49:55 +09:00
Yoshitomo Nakanishi
febf34e2b4 Move too_many_arguments to its own module 2021-03-27 22:49:55 +09:00
bors
8e56a2b27f Auto merge of #6979 - flip1995:msrv_doc_fix, r=giraffate
Add missing lints to MSRV config doc

r? `@giraffate`

changelog: Add missing lints to MSRV config doc
2021-03-27 13:27:51 +00:00
bors
dcee00d64b Auto merge of #6980 - Jarcho:len_without_is_empty_sig, r=llogiq
`len_without_is_empty` improvements

fixes: #6958
fixes: #6972

changelog: Check the return type of `len`. Only integral types, or an `Option` or `Result` wrapping one.
changelog: Ensure the return type of `is_empty` matches. e.g. `Option<usize>` -> `Option<bool>`
2021-03-27 13:10:43 +00:00
Jason Newcomb
12985afbca
len_without_is_empty improvements
Check the return type of `len`. Only integral types, or an `Option` or `Result` wrapping one.
Ensure the return type of `is_empty` matches. e.g. `Option<usize>` -> `Option<bool>`
2021-03-27 09:04:44 -04:00
Matthias Krüger
ca7e95501c upper_case_acronyms: add ui and ui-toml tests for private/public enums 2021-03-27 01:08:14 +01:00