Commit Graph

3934 Commits

Author SHA1 Message Date
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
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
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
F3real
e9bf5ec659 Don't show no_effect warning on unit structs implementing fn* traits 2021-11-17 00:50:07 +01:00
bors
83ad51108b Auto merge of #7982 - Blckbrry-Pi:master, r=llogiq
Fix `needless_collect`'s tendency to suggest code requiring multiple mutable borrows of the same value.

Fixes error specified in #7975.

changelog: [`needless_collect`] no longer suggests removal of `collect` when removal would create code requiring mutably borrowing a value multiple times.
2021-11-16 23:01:02 +00:00
Skyler Calaman
5b3c00f012 Successfully generalize prevention of suggestions causing multiple mutable borrows.
Also add some more tests to check that it's working.
2021-11-16 09:18:49 -05:00
Jason Newcomb
2938ffd0d9 Improve heuristics for determining whether eager of lazy evaluation is preferred 2021-11-15 20:54:13 -05:00
Jason Newcomb
8ded385ddc Improve needless_borrow lint.
* Lint when a borrow is auto dereferenced more than once
* Lint when the expression is used as the expression of a block for a match arm

Moves `needless_borrow` and `ref_binding_to_reference` to `dereference`
lint pass in preperation for `explicit_auto_deref` lint.
2021-11-15 13:17:59 -05:00
togami2864
300282c09a fix fmt 2021-11-16 02:53:35 +09:00
togami2864
02e0726149 fix a bug that the closure arguments are not displayed 2021-11-16 02:29:02 +09:00
togami2864
bbffe825ed add reduce_unit_expression 2021-11-16 02:06:31 +09:00
bors
0def42fd7b Auto merge of #7974 - matthiaskrgr:7973_opt_map_or_else_dont_expand_sugg_macro, r=flip1995
option_if_let_else: don't expand macros in suggestion

Fixes #7973

changelog: don't expand macros in suggestion of clippy::option_if_let_else
2021-11-15 10:27:29 +00:00
togami2864
4f71ff3f84 add test case for option_map_or_none 2021-11-15 15:47:57 +09:00
bors
f82bf470d0 Auto merge of #7957 - surechen:fix_for_7854, r=giraffate
Support suggestion for #7854

I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.(Fixes #7854)

changelog: Make let_underscore_lock support parking_lot
2021-11-15 00:50:28 +00:00
surechen
634e79c655 Support suggestion for #7854
I think the detection of parking_lot's mutex and rwlock is valuable, so submit this pr, please help judge and review, thank you.

Make let_underscore_lock support parking_lot.

changelog: Make let_underscore_lock support parking_lot
2021-11-15 08:36:36 +08:00
Skyler Calaman
3e20e300f6 Fix specific code outlined in issue #7975.
Still needs to generalize to other mixes of let bindings, `map` method calls, etc.
2021-11-14 18:18:43 -05:00
Matthias Krüger
3fe11e776c option_if_let_else: don't expand macros in suggestion
Fixes #7973

changelog: don't expand macros in suggestion of clippy::option_if_let_else
2021-11-13 23:17:21 +01:00
togami2864
2ed4a8a3e6 fix suggestion in option_map_or_none 2021-11-13 22:38:28 +09:00
Jason Newcomb
80a263d469 Fix manual_map suggestion when used with unsafe functions and unsafe blocks. 2021-11-12 19:12:17 -05:00
bors
4f82dd83df Auto merge of #7948 - 5225225:castlosslessbool, r=llogiq
Lint for bool to integer casts in `cast_lossless`

The lint description says

> Checks for casts between *numerical* types that may be replaced by safe conversion functions.

Which is strictly speaking being violated here, but it seems within the spirit of the lint. I think it is still a useful lint to have, and having a different lint for just this feels excessive. Thoughts?

Fixes #7947

changelog: Lint for bool to integer casts in [`cast_lossless`]
2021-11-12 18:17:18 +00:00
5225225
d4c8cb63a4 Change cast_lossless message for bools only 2021-11-12 17:01:35 +00:00
bors
8b84a760ca Auto merge of #7956 - camsteffen:author, r=llogiq
Author improvements

changelog: none

Various aspects of the author implementation are re-imagined to be much less repetitive. Also fixes some bugs. I hope this makes author more fun to work on for future contributors.

The last commit is pretty heavy but I tried to at least separate some changes so that the test file diffs per commit are simple.
2021-11-11 19:33:06 +00:00
xFrednet
e444cbe5d6
New index_refutable_slice lint
* Finding pattern slices for `avoidable_slice_indexing`
* `avoidable_slice_indexing` analysing slice usage
* Add configuration to `avoidable_slice_indexing`
* Emitting `avoidable_slice_indexing` with suggestions
* Dogfooding and fixing bugs
* Add ui-toml test for `avoidable_slice_indexing`
* Correctly suggest `ref` keywords for `avoidable_slice_indexing`
* Test and document `mut` for `avoid_slice_indexing`
* Handle macros with `avoidable_slice_indexing` lint
* Ignore slices with sub patterns in `avoidable_slice_indexing`
* Update lint description for `avoidable_slice_indexing`
* Move `avoidable_slice_indexing` to nursery
* Added more tests for `avoidable_slice_indexing`
* Update documentation and message for `avoidable_slice_indexing`
* Teach `avoidable_slice_indexing` about `HirId`s and `Visitors`
* Rename lint to `index_refutable_slice` and connected config
2021-11-11 17:34:02 +01:00
Cameron Steffen
27a1763eac Make author DRYer 2021-11-11 09:38:00 -06:00
dswij
dcd1a16dd0 Add test for swap lint when no_std is present
Adds additional test to check for `swap` suggestion when `no_std` is present
2021-11-11 12:30:07 +08:00