Commit graph

8042 commits

Author SHA1 Message Date
Philipp Krones
1f75845a8f
Reduce indentation and add comment about lint name 2022-08-21 10:29:26 +02:00
J-ZhengLi
ffe7125163
and check for Result 2022-08-21 10:24:30 +02:00
J-ZhengLi
5d403c0b85
allow check for match in lint [option_if_let_else]
and add test case for `Result`
2022-08-21 10:24:27 +02:00
bors
5820addb24 Auto merge of #9269 - nahuakang:collapsible_str_replace, r=flip1995
Lint `collapsible_str_replace`

fixes #6651

```
changelog: [`collapsible_str_replace`]: create new lint `collapsible_str_replace`
```

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`
2022-08-20 13:44:35 +00:00
Nahua Kang
b070b4045f Simplify lint logic and address code review comments 2022-08-20 12:09:09 +02:00
alex-semenyuk
2781ad0e9e Fix typos 2022-08-20 12:31:29 +03:00
bors
2091142f5d Auto merge of #9258 - Serial-ATA:unused-peekable, r=Alexendoo
Add [`unused_peekable`] lint

changelog: Add [`unused_peekable`] lint
closes: #854
2022-08-19 18:30:13 +00:00
Nahua Kang
fb30b64f63 Adjust test cases; run cargo dev bless 2022-08-19 20:00:20 +02:00
Nahua Kang
c989746ccf Remove checks on char slice; improve lint suggestion 2022-08-19 20:00:20 +02:00
Nahua Kang
a9bd0bd321 Handle repeated str::replace calls with single char kind to str 2022-08-19 20:00:19 +02:00
Nahua Kang
6e86687529 Handle replace calls with char slices 2022-08-19 19:55:28 +02:00
Nahua Kang
a4413f75bf Register new lint collapsible_str_replace to methods 2022-08-19 19:49:15 +02:00
bors
3a54117ffc Auto merge of #8804 - Jarcho:in_recursion, r=Alexendoo
Rework `only_used_in_recursion`

fixes #8782
fixes #8629
fixes #8560
fixes #8556

This is a complete rewrite of the lint. This loses some capabilities of the old implementation. Namely the ability to track through tuple and slice patterns, as well as the ability to trace through assignments.

The two reported bugs are fixed with this. One was caused by using the name of the method rather than resolving to the `DefId` of the called method. The second was cause by using the existence of a cycle in the dependency graph to determine whether the parameter was used in recursion even though there were other ways to create a cycle in the graph.

Implementation wise this switches from using a visitor to walking up the tree from every use of each parameter until it has been determined the parameter is used for something other than recursion. This is likely to perform better as it avoids walking the entire function a second time, and it is unlikely to walk up the HIR tree very much. Some cases would perform worse though.

cc `@buttercrab`

changelog: Scale back `only_used_in_recursion` to fix false positives
changelog: Move `only_used_in_recursion` back to `complexity`
2022-08-19 16:11:48 +00:00
Jason Newcomb
39f4bee98e Move only_used_in_recursion back into complexity 2022-08-19 11:42:14 -04:00
Jason Newcomb
d95b67560c Rework only_used_in_recursion 2022-08-19 11:42:14 -04:00
Alex Macleod
4f049f5a69 Refactor FormatArgsExpn 2022-08-19 15:35:26 +00:00
Jason Newcomb
d8808db006 Move VerboseFileReads into Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
8acc4d2f1e Move VecResizeToZero into Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
d8d4a135ea Move UnnecessarySortBy into Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
bb0584dfb4 Move UnitHash into Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
e213b6ee35 Move TransmutingNull into Transmute lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
e834855950 Move StableSortPrimitive to Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
06d752e28d Move RepeatOnce into Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
fd5376194a Move range_zip_with_len into Methods lint pass 2022-08-19 10:54:55 -04:00
Jason Newcomb
226f135a03 Move PathBufPushOverwrite into Methods lint group 2022-08-19 10:32:31 -04:00
Jason Newcomb
0cc01cef30 Move OpenOptions into Methods lint pass 2022-08-19 10:32:16 -04:00
Jason Newcomb
508cf6bdbc Move MutMutexLock into Methods lint pass 2022-08-19 10:32:16 -04:00
Jason Newcomb
2f0ed0a0b1 Move MapErrIgnore into Methods lint pass 2022-08-19 10:32:15 -04:00
Jason Newcomb
452395485b Move MapClone into Methods lint pass 2022-08-19 10:31:41 -04:00
Jason Newcomb
5bc8813cdd Move ManualOkOr into Methods lint pass 2022-08-19 10:31:41 -04:00
Jason Newcomb
a8d80d531f Move GetFirst into Methods lint pass 2022-08-19 10:29:55 -04:00
Jason Newcomb
e3b77974d0 Move CaseSensitiveFileExtensionComparisons into Methods lint pass 2022-08-19 10:29:55 -04:00
Jason Newcomb
ba6a459528 Move BytesCountToLen into Methods lint pass 2022-08-19 10:28:59 -04:00
Jason Newcomb
2502898686 Move ByteCount into Methods lint pass 2022-08-19 10:28:59 -04:00
Jason Newcomb
21f595433e Move BorrowAsPtr into Casts lint pass 2022-08-19 10:24:58 -04:00
Jason Newcomb
8ab2f880d0 Move AsUnderscore into Casts lint pass 2022-08-19 10:23:19 -04:00
Serial
0efafa4a6e Better handle method/function calls 2022-08-19 08:18:34 -04:00
Serial
2666c38acb Add [unused_peekable] lint 2022-08-19 08:05:59 -04:00
bors
868dba9f65 Auto merge of #9295 - Guilherme-Vasconcelos:manual-empty-string-creation, r=dswij
Add `manual_empty_string_creations` lint

Closes #2972

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

changelog: [`manual_empty_string_creations`]: Add lint for empty String not being created with `String::new()`
2022-08-19 11:19:06 +00:00
Lukas Lueg
e87a5a1cc5 Dont lint on match pattern-binding
Fixes #9347

Technically it is possible to have a blank match-pattern that does
nothing, and we fail to lint. But its easier to be safe than sorry here.
2022-08-18 19:30:56 +02:00
bors
c419d0a8b5 Auto merge of #9136 - smoelius:enhance-needless-borrow, r=Jarcho
Enhance `needless_borrow` to consider trait implementations

The proposed enhancement causes `needless_borrow` to suggest removing `&` from `&e` when `&e` is an argument position requiring trait implementations, and `e` implements the required traits. Example:
```
error: the borrowed expression implements the required traits
  --> $DIR/needless_borrow.rs:131:51
   |
LL |     let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap();
   |                                                   ^^^^^^^^^^^^^ help: change this to: `["-a", "-l"]`
```

r? `@Jarcho`

changelog: Enhance `needless_borrow` to consider trait implementations
2022-08-18 15:57:37 +00:00
bors
849c1c0465 Auto merge of #9338 - sgued:9331-unwrap-err-used, r=giraffate
unwrap_used and expect_used: trigger on uses of their _err variants

changelog: [`unwrap_used`]: lint uses of `unwrap_err`
changelog: [`expect_used`]: lint uses of `expect_err`

fixes #9331
2022-08-17 23:35:44 +00:00
Sosthène Guédon
ab91d5a540 unwrap_used: Fix error message for unwrap_err when expect_used is allowed 2022-08-17 18:58:17 +02:00
bors
84fb7e0395 Auto merge of #9287 - Jarcho:trans_undefined, r=xFrednet
`transmute_undefined_repr` fix

changelog: Don't lint `transmute_undefined_repr` when the the first field of a `repr(C)` type is compatible with the other type
2022-08-17 13:14:55 +00:00
cherryblossom
aadd014863
Fix typo in as_undescore docs
du -> due
2022-08-17 18:56:06 +10:00
bors
18c681893e Auto merge of #9341 - bmc-msft:suggest-map_or-instead-of-unwrap_or, r=giraffate
suggest map_or in case_sensitive_file_extension_comparisons

changelog: [`case_sensitive_file_extension_comparisons `]: updated suggestion in the example to use `map_or`

Currently, case_sensitive_file_extension_comparisons suggests using `map(..).unwrap_or(..)` which trips up the `map_unwrap_or` lint.  This updates the suggestion to use `map_or`.
2022-08-17 00:30:41 +00:00
Samuel E. Moelius III
a05cb74d30 Enhance needless_borrow to consider trait implementations 2022-08-16 18:34:51 -04:00
bors
f4f5bb4328 Auto merge of #9327 - Serial-ATA:non_ascii_literal_macro, r=Alexendoo
Fix [`non_ascii_literal`] in tests

changelog: Don't lint [`non_ascii_literal`] when using non-ascii comments in tests
changelog: Don't lint [`non_ascii_literal`] when `allow`ed on tests

closes: #7739
closes: #8263
2022-08-16 20:22:39 +00:00
Brian Caswell
bfeaae8930 suggest map_or in case_sensitive_file_extension_comparisons
Currently, case_sensitive_file_extension_comparisons suggests using
`map(..).unwrap_or(..)` which trips up `map_unwrap_or`.  This updates
the suggestion to use map_or.
2022-08-16 16:03:23 -04:00
Serial
bd121eff8a Fix [non_ascii_literal] in tests 2022-08-16 15:53:01 -04:00