Commit graph

5183 commits

Author SHA1 Message Date
Esteban Kuber
c5287b37fa fix clippy tests 2021-12-13 17:09:16 +00:00
Esteban Kuber
1c3747e7dd Fix rebase and clippy tests 2021-12-13 17:09:16 +00:00
Samuel E. Moelius III
3807905e08 Handle to_vec on for loop expression #8069 2021-12-13 07:04:57 -05:00
Samuel E. Moelius III
290f74be4e Address review comments
* Share a list of methods with `implicit_clone`
* Ensure no overlap with `redundant_clone`
2021-12-13 06:31:17 -05:00
Samuel E. Moelius III
468c86e4a3 Add unnecessary_to_owned lint 2021-12-13 06:31:17 -05:00
Cormac Relf
17c1ff9faa let-else: use hir::Let in clippy
fix clippy format using `cargo fmt -p clippy_{lints,utils}`
manually revert rustfmt line truncations
rename to hir::Let in clippy
Undo the shadowing of various `expr` variables after renaming `scrutinee`
reduce destructuring of hir::Let to avoid `expr` collisions
cargo fmt -p clippy_{lints,utils}
bless new clippy::author output
2021-12-13 14:02:41 +11:00
Amanieu d'Antras
e1139cf570 Fix clippy tests 2021-12-13 00:00:51 +00:00
Ellen
603b865ae4 clippy owo 2021-12-12 12:34:21 +00:00
bors
aa3648af50 Auto merge of #8100 - c410-f3r:blah-blah-blah, r=giraffate
Fix `blocks_in_if_conditions` false positive

Fix #8099

changelog: Fix [`blocks_in_if_conditions`] false positive with an empty closure
2021-12-09 23:50:02 +00:00
Caio
392b2eff4b Fix blocks_in_if_conditions false positive 2021-12-08 20:02:28 -03:00
bors
53059792e9 Auto merge of #8071 - GuillaumeGomez:method-must-use, r=xFrednet
Add new lint to warn when #[must_use] attribute should be used on a method

This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions).

Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312

I think it would reduce the number of cases of API misuses quite a lot.

What do you think?

---

changelog: Added new [`return_self_not_must_use`] lint
2021-12-08 19:09:25 +00:00
bors
3c8f90bd5a Auto merge of #8030 - WaffleLapkin:ignore_trait_assoc_types_type_complexity, r=llogiq
Ignore associated types in traits when considering type complexity

changelog: Ignore associated types in traits when checking ``[`type_complexity`]`` lint.

fixes #1013
2021-12-08 11:54:03 +00:00
Maybe Waffle
c176568abd Ignore associated items in trait *implementations* when considering type complexity 2021-12-08 14:38:59 +03:00
Guillaume Gomez
2b35edbb84 Update other UI tests as well 2021-12-08 11:16:14 +01:00
Guillaume Gomez
8dfb3ec8a4 Add new lint to warn when #[must_use] attribute should be used on a method 2021-12-08 11:16:14 +01:00
bors
86cea73449 Auto merge of #8086 - dswij:7991, r=giraffate
Fix bad suggestion on `option_if_let_else` when there is complex subpat

closes #7991

Prefer not warning any complex subpat in `option_if_let_else` rather than suggesting obscure suggestions.

changelog: [`option_if_let_else`] does not warn when complex subpat is present
2021-12-07 23:45:58 +00:00
Yechan Bae
c0fd250c62 Fix grammar issues 2021-12-07 10:08:22 -05:00
Yechan Bae
ee0d71e103 Clarify the purpose of the lint 2021-12-07 10:06:34 -05:00
dswij
b5fa5b37cc option_if_let_else Do not warn when complex subpat is present 2021-12-07 15:47:28 +08:00
bors
f615ea474b Auto merge of #8080 - dswij:8019, r=giraffate
Fix FP on `question_mark` if returned object is not local

Closes #8019

changelog: [`question_mark`] Fix FP when returned object is not local
2021-12-07 00:07:46 +00:00
bors
9e0852705e Auto merge of #8066 - rust-lang:needless_bool_parenthesize, r=camsteffen
Parenthesize blocks in `needless_bool` suggestion

Because the `if .. {}` statement already puts the condition in expression scope, contained blocks would be parsed as complete
statements, so any `&` binary expression whose left operand ended in a block would lead to a non-compiling suggestion.

We identify such expressions and add parentheses. Note that we don't make a difference between normal and unsafe blocks because the parsing problems are the same for both.

This fixes #8052.

---

changelog: none
2021-12-06 15:15:26 +00:00
Andre Bogus
4a39707795 Parenthesize blocks in needless_bool suggestion
Because the `if .. {}` statement already puts the condition in
expression scope, contained blocks would be parsed as complete
statements, so any `&` binary expression whose left operand ended in a
block would lead to a non-compiling suggestion.

This adds a visitor to identify such expressions and add parentheses.

This fixes #8052.
2021-12-06 13:15:31 +01:00
flip1995
8fea1d94f3 Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
dswij
01ca66cbd7 Fix FP on question_mark if returned object is not local 2021-12-06 17:51:00 +08:00
nixx quality
e3c60444ce
fix some false negatives for single_char_pattern 2021-12-05 17:33:52 +01:00
bors
907f6d9294 Auto merge of #8074 - Qwaz:send_nonnull, r=xFrednet
Consider NonNull as a pointer type

PR 1/2 for issue #8045. Add `NonNull` as a pointer class to suppress false positives like `UnsafeCell<NonNull<()>>`. However, this change is not sufficient to handle the cases shared in gtk-rs and Rug in the issue.

changelog: none

r? `@xFrednet`
2021-12-04 17:19:07 +00:00
bors
9eabec9f07 Auto merge of #8054 - camsteffen:map-flatten-style, r=giraffate
Upgrade map_flatten to complexity

changelog: upgrade [`map_flatten`] to complexity

Resolves #7999
2021-12-04 13:30:09 +00:00
Yechan Bae
844996b42e Consider NonNull as a pointer type 2021-12-03 19:11:40 -05:00
Cameron Steffen
de9de4fef1 Upgrade map_flatten to complexity 2021-12-03 13:21:48 -06:00
bors
be1a73b894 Auto merge of #8061 - vallentin:fix-same-name-method-desc, r=flip1995
Fixed same_name_method description

Noticed some odd phrasing, while checking out the new release.

changelog: none
2021-12-03 00:37:52 +00:00
frobiac
5cc451bc6c Escape backslash for singe_char_pattern.rs 2021-12-02 23:47:23 +01:00
bors
d5d830a50f Auto merge of #7463 - ThibsG:find_any_7392, r=xFrednet
Fix `any()` not taking reference in `search_is_some` lint

`find` gives reference to the item, but `any` does not, so suggestion is broken in some specific cases.

Fixes: #7392

changelog: [`search_is_some`] Fix suggestion for `any()` not taking item by reference
2021-12-02 17:27:54 +00:00
vallentin
f26821c969
Fixed same_name_method description 2021-12-02 18:25:09 +01:00
flip1995
abddd6c491
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-02 09:32:09 +00:00
bors
8ad56c8fb7 Auto merge of #8049 - surechen:fixes_7946, r=flip1995
Add test for pattern_type_mismatch.

This issue has been fixed by [commit](8c1c763c2d)
This PR is used for close #7946(Fixes #7946).

changelog: Add test for pattern_type_mismatch.
2021-12-01 09:58:54 +00:00
homersimpsons
522f3f901f
no_std_swap: Remove obsolete TODO from test 2021-12-01 09:43:35 +00:00
surechen
bd63686e0f Add test for pattern_type_mismatch.
This issue has been fixed by [commit](8c1c763c2d)
This PR is used for close #7946(Fixes #7946).

changelog: Add test for pattern_type_mismatch.
2021-12-01 17:37:50 +08:00
bors
908815ce98 Auto merge of #8001 - Jarcho:unprefixed_strlen, r=giraffate
Improve `strlen_on_c_string`

fixes: #7436

changelog: lint `strlen_on_c_string` when used without a fully-qualified path
changelog: suggest removing the surrounding unsafe block for `strlen_on_c_string` when possible
2021-11-29 01:03:48 +00:00
bors
4e84dd121f Auto merge of #8006 - togami2864:generalize-copied, r=camsteffen
apply iter_cloned_collect to collect() using copied()

fix: #6703

changelog: apply `iter_cloned_collect` to `collect()` using`copied()`
2021-11-28 20:59:20 +00:00
togami2864
f51bbc7db9 apply iter_cloned_collect to copied() 2021-11-28 23:59:31 +09:00
Aaron Hill
3c8b644d0d Only check for errors in predicate when skipping impl assembly
Prior to PR #91205, checking for errors in the overall obligation
would check checking the `ParamEnv`, due to an incorrect
`super_visit_with` impl. With this bug fixed, we will now
bail out of impl candidate assembly if the `ParamEnv` contains
any error types.

In practice, this appears to be overly conservative - when an error
occurs early in compilation, we end up giving up early for some
predicates that we could have successfully evaluated without overflow.
By only checking for errors in the predicate itself, we avoid causing
additional spurious 'type annotations needed' errors after a 'real'
error has already occurred.

With this PR, the diagnostic changes caused by PR #91205 are reverted.
2021-11-27 11:33:55 -06:00
bors
3720735f9a Auto merge of #7995 - Alexendoo:needless_late_init, r=giraffate
Add `needless_late_init` lint

examples:

```rust
let a;
a = 1;
// to
let a = 1;
```
```rust
let b;
match 3 {
    0 => b = "zero",
    1 => b = "one",
    _ => b = "many",
}
// to
let b = match 3 {
    0 => "zero",
    1 => "one",
    _ => "many",
};
```
```rust
let c;
if true {
    c = 1;
} else {
    c = -1;
}
// to
let c = if true {
    1
} else {
    -1
};
```

changelog: Add [`needless_late_init`]
2021-11-27 14:24:02 +00:00
Alex Macleod
d346ec94fe Add async/const fn tests for needless-late-init
+nits
2021-11-26 14:27:53 +00:00
bors
6b997b6576 Auto merge of #91205 - Aaron1011:visit_param_env, r=lcnr
Visit `param_env` field in Obligation's `TypeFoldable` impl

This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-26 09:55:06 +00:00
togami2864
e8ef6ca5e3 fix stderr 2021-11-26 18:49:14 +09:00
togami2864
140ba610e4 add test suit 2021-11-26 18:34:07 +09:00
Aaron Hill
9274ec5691 Visit param_env field in Obligation's TypeFoldable impl
This oversight appears to have gone unnoticed for a long time
without causing issues, but it should still be fixed.
2021-11-25 15:33:37 -06:00
Esteban Kuber
5fc61a24c4 Fix clippy test 2021-11-25 18:39:32 +00:00
Maybe Waffle
40a6c519b4 Update tests for type_complexity lint 2021-11-25 12:47:29 +03:00
Maybe Waffle
063f8aa094 Ignore associated types in traits when considering type complexity 2021-11-25 12:08:18 +03:00
Dharma Saputra Wijaya
c0bad8bcab Add more descriptive help info for needless_question_mark 2021-11-25 14:01:14 +08:00
Jason Newcomb
a135347f5d Run rustfix for strlen_on_c_strings tests 2021-11-24 20:16:27 -05:00
Alex Macleod
3957244120 Add needless_late_init lint 2021-11-23 15:08:49 +00:00
flip1995
5740230ec7
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-23 11:22:34 +01:00
dswij
ec3d1c8ca3 Fix FP on if_then_some_else_none when there is early return 2021-11-23 10:11:30 +08:00
bors
57a8804ef9 Auto merge of #8007 - birkenfeld:octal_escapes, r=xFrednet
Add new lint `octal_escapes`

This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.

Fixes #7981

---

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

changelog: Add new lint [`octal_escapes`], which checks for literals like `"\033[0m"`.
2021-11-22 20:29:53 +00:00
Georg Brandl
0bc25d04c6 octal_escapes: emit only one lint for all cases found each literal 2021-11-22 21:00:19 +01:00
Georg Brandl
850e7f533e octal_escapes: updates from review, fix byte string prefix 2021-11-22 18:02:17 +01:00
bors
5fbfdfa319 Auto merge of #8009 - xFrednet:8004-suboptimal-flops-in-const, r=giraffate
Allow `suboptimal_flops` in const functions

This PR allows `clippy::suboptimal_flops` in constant functions. The check also effects the `clippy::imprecise_flops` lint logic. However, this doesn't have any effects as all functions checked for are not const and can therefore not be found in such functions.

---

changelog: [`suboptimal_flops`]: No longer triggers in constant functions

Closes: rust-lang/rust-clippy#8004
2021-11-22 00:01:49 +00:00
bors
de2208a351 Auto merge of #7997 - surechen:Fixes_7915, r=giraffate
Fixes shadow_same's false positive for #7915

Fix shadow_same's false positive for async function's params(Fixes #7915):

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's false positive for async function's params
2021-11-21 23:48:24 +00:00
Cameron Steffen
e58ffb88e6 Fix Clippy with changed for loop desugar 2021-11-21 08:16:09 -06:00
surechen
846c0bef07 Fixes #7915
Fix shadow_same's positive false for async function's params:

Example Code:
```rust
#![deny(clippy::shadow_same)]

pub async fn foo(_a: i32) {
}
```
Output:
```
error: `_a` is shadowed by itself in `_a
```

Hir:
```rust
pub async fn foo(_a: i32)
 ->
     /*impl Trait*/ #[lang = "from_generator"](move |mut _task_context|
                                                   {
                                                       let _a = _a;
                                                       { let _t = { }; _t }
                                                   })
```

Skip checking async function's params.

changelog: Fix shadow_same's positive false for async function's params
2021-11-21 14:28:44 +08:00
Georg Brandl
0c4055c283 Avoid inline hints with double backticks for doc-markdown 2021-11-20 18:13:24 +01:00
xFrednet
1c8085d705
Allow suboptimal_flops in const functions 2021-11-20 15:39:29 +01:00
Georg Brandl
982124acfa Add new lint octal_escapes
This checks for sequences in strings that would be octal character
escapes in C, but are not supported in Rust.  It suggests either
to use the `\x00` escape, or an equivalent hex escape if the octal
was intended.
2021-11-20 11:57:25 +01:00
togami2864
ec7364f227 add test suit 2021-11-20 18:49:30 +09:00
ThibsG
5ebede0c14 Fix full projection identifier + move applicability to MaybeIncorrect 2021-11-20 09:40:11 +01:00
ThibsG
1176b8e5e9 Handle closures with type annotations on args 2021-11-20 09:40:11 +01:00
ThibsG
7221999181 Add tests with closure 2021-11-20 09:40:11 +01:00
ThibsG
268ef407a6 Add test case for references bindings 2021-11-20 09:40:11 +01:00
ThibsG
90a72f506c Handle args taken by ref also for MethodCall 2021-11-20 09:40:11 +01:00
ThibsG
7a55407cc3 Fix suggestions when call functions involved taking by ref 2021-11-20 09:40:11 +01:00
ThibsG
6d1ccbf466 Correct suggestion when dereferencing enough, calling a function 2021-11-20 09:40:11 +01:00
ThibsG
ac45a83ad5 Handle multiple reference levels into binding type and add more tests 2021-11-20 09:40:11 +01:00
ThibsG
91dd9c46de Handle other projection kinds 2021-11-20 09:40:11 +01:00
ThibsG
ddcbac37ae Split tests (too long for CI) 2021-11-20 09:40:10 +01:00
ThibsG
b38f173aa3 Build suggestion within visitor + add more tests 2021-11-20 09:40:10 +01:00
ThibsG
5ed93af9c4 Use ExprUseVisitor and multipart suggestion to avoid iffy String replacement 2021-11-20 09:40:10 +01:00
ThibsG
f4c75cde5e Fix any() not taking reference in search_is_some lint 2021-11-20 09:40:10 +01:00
Jason Newcomb
0d1f1cec44 Remove surrounding unsafe block in strlen_on_c_strings when possible 2021-11-19 21:14:51 -05:00
Jason Newcomb
c443f8fb95 Fix strlen_on_c_strings when not used with a full path 2021-11-19 20:02:49 -05:00
Jason Newcomb
1429949f9f Don't check for a nightly toolchain in fmt test 2021-11-19 19:43:31 -05:00
bors
38bd2514ad Auto merge of #7984 - phansch:disallowed-type-rename, r=xFrednet
Pluralize `disallowed_type` lint

This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types

changelog: Rename nursery lint [`disallowed_type`] to [`disallowed_types`].
2021-11-19 13:39:08 +00:00
togami2864
cd81bb9dc3 fix stderr 2021-11-19 16:17:17 +09:00
togami2864
abb7155387 add test case for result_map_or_into_option 2021-11-19 16:12:46 +09:00
bors
2776076efa Auto merge of #7977 - Jarcho:multi_needless_borrow, r=xFrednet
Improve `needless_borrow` lint

fixes: #5327
fixes: #1726
fixes: #1212

This is merging `needless_borrow` into the `dereference` pass in preparation for `explicit_auto_deref`. `explicit_auto_deref` needs to implement most of what `needless_borrow` implements in order to work.

There is a minor regression here where `let x: &str = &x.deref()` will trigger `needless_borrow` without triggering `explicit_deref_methods`. Removing the redundant borrow will cause `explicit_deref_methods` to trigger. This will be fixed when `explicit_auto_deref` is implemented.

changelog: Lint `needless_borrow` when a borrow is auto-derefed more than once
changelog: Lint `needless_borrow` in the trailing expression of a block for a match arm
2021-11-18 23:35:03 +00:00
flip1995
9b38fb7b71
Also pluralize disallowed_method(s) lint
To stay consistent with the sister lint disallowed_type, also rename the
disallowed_method lint to disallowed_methods.
2021-11-18 17:37:06 +01:00
Philipp Hansch
a0d81d1327
Pluralize disallowed_type lint filenames
This way they match up with the pluralized lint name as well.
2021-11-18 17:37:06 +01:00
Philipp Hansch
b7f18916fa
Pluralize disallowed_type lint
This was brought up in [Zulip] and is also mentioned in the lint naming
conventions. Since this is still a nursery lint, I think there shouldn't
be any problem in renaming it.

[Zulip]: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/disallow_type.20vs.20disallowed-types
2021-11-18 17:37:02 +01:00
flip1995
731dfde267
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-18 12:22:00 +01:00
bors
bb58dc84c1 Auto merge of #7968 - Jarcho:manual_map_unsafe, r=xFrednet
Fix `manual_map` with unsafe functions

fixes: #7820
changelog: Fix `manual_map` suggestion when used with unsafe functions and unsafe blocks
2021-11-17 16:20:04 +00:00
bors
6ac42fe6fa Auto merge of #7971 - togami2864:fix/option-map-or-none, r=llogiq
fix suggestion in option_map_or_none

fix: #7960
changelog: change suggestion in the lint rule `option_map_or_none`
2021-11-17 16:01:55 +00:00
togami2864
8e317f5283 fix suggestion message 2021-11-18 00:43:49 +09:00
Jason Newcomb
5f861ee1ae Addition manual_map test for unsafe blocks 2021-11-17 10:39:53 -05:00
bors
d550e5f5e6 Auto merge of #7988 - giraffate:fix_ice_on_undocumented_unsafe_blocks, r=flip1995
Fix ICE on `undocumented_unsafe_blocks`

fix https://github.com/rust-lang/rust-clippy/issues/7979

changelog: Fix ICE on `undocumented_unsafe_blocks`
2021-11-17 15:24:07 +00:00
togami2864
e34927ecf6 add multi-line test case 2021-11-18 00:13:55 +09:00
bors
94ca94fa5f Auto merge of #7898 - F3real:unit_struct, r=camsteffen
Don't show no_effect warning on unit structs implementing fn_once

Fixes #7792

changelog: Don't show [`no_effect`] or [`unecessary_operation`] warning for unit struct implementing FnOnce
2021-11-17 14:09:51 +00:00
Takayuki Nakata
3f3d7c2005 Fix ICE on undocumented_unsafe_blocks 2021-11-17 22:35:01 +09:00
bors
46687f1313 Auto merge of #7896 - surechen:fix_manual_split_once, r=camsteffen
Fix for #7889 and add new lint needless_splitn

fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 01:46:58 +00:00
surechen
c051656c83 fixes: #7889
1. Fix the problem of manual_split_once changing the original behavior.
2. Add a new lint needless_splitn.

changelog: Fix the problem of manual_split_once changing the original behavior and add a new lint needless_splitn.
2021-11-17 08:38:45 +08:00