Commit graph

14828 commits

Author SHA1 Message Date
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
bors
3e594de8ec Auto merge of #9349 - Alexendoo:format-args-expn, r=flip1995
Refactor `FormatArgsExpn`

It now for each format argument `{..}` has:
- The `Expr` it points to, and how it does so (named/named inline/numbered/implicit)
- The parsed `FormatSpec` (format trait/fill/align/etc., the precision/width and any value they point to)
- Many spans

The caller no longer needs to pair up arguments to their value, or separately interpret the `specs` `Expr`s when it isn't `None`

The gist is that it combines the result of [`rustc_parse_format::Parser`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_parse_format/struct.Parser.html) with the macro expansion itself

This unfortunately makes the code a bit longer, however we need to use both as neither have all the information we're after. `rustc_parse_format` doesn't have the information to resolve named arguments to their values. The macro expansion doesn't contain whether the positions are implicit/numbered/named, or the spans for format arguments

Wanted by #9233 and #8518 to be able to port the changes from #9040

Also fixes #8643, previously the format args seem to have been paired up with the wrong values somehow

changelog: [`format_in_format_args`]: Fix false positive due to misattributed arguments

r? `@flip1995`
cc `@nyurik`
2022-08-19 15:55:05 +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
bors
477c16d45b Auto merge of #8957 - Jarcho:more_pass_merges, r=flip1995
More lint pass merges

changelog: None
2022-08-19 15:08:49 +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
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
bors
eeaaba3713 Auto merge of #9348 - lukaslueg:issue9347, r=Alexendoo
Don't lint on match pattern-binding in ´question_mark`

Fixes #9347

Technically it is possible to have a blank match-pattern that does nothing, and we fail to lint. But it's easier to be safe than sorry here.

changelog: [`question_mark`]: don't lint `if let`s with subpatterns
2022-08-18 18:13:39 +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
bors
dc497c82ff Auto merge of #9345 - cherryblossom000:patch-1, r=flip1995
Fix typo in as_undescore docs

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

changelog: none
2022-08-17 09:18:14 +00:00
bors
4235b6480c Auto merge of #9344 - Jarcho:opt_target_dir, r=flip1995
Handle `CARGO_TARGET_DIR` not being set in compile-test

changelog: None
2022-08-17 08:56:35 +00:00
cherryblossom
aadd014863
Fix typo in as_undescore docs
du -> due
2022-08-17 18:56:06 +10:00
Jason Newcomb
48cb816530 Handle CARGO_TARGET_DIR not being set in compile-test 2022-08-16 21:22:29 -04: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
032f112745 Fix adjacent code 2022-08-16 18:34:51 -04:00
Samuel E. Moelius III
a05cb74d30 Enhance needless_borrow to consider trait implementations 2022-08-16 18:34:51 -04:00
bors
a3317662f2 Auto merge of #9343 - Serial-ATA:compiletest-target-env, r=Manishearth
Use `CARGO_TARGET_DIR` in compile-test

changelog: none

I have a global `CARGO_TARGET_DIR` set, but forgot to delete the old target dir. `compile-test` was getting tripped up on an outdated `rustfix_missing_coverage.txt` I had in there, keeping me from running tests 😄.
2022-08-16 21:39:45 +00:00
Serial
343476df0f Use CARGO_TARGET_DIR in compile-test 2022-08-16 17:17:21 -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
Sosthène Guédon
c1e04352bd unwrap_used and expect_used: trigger on uses of their _err variants 2022-08-16 18:31:57 +02:00
bors
048e4d004a Auto merge of #9340 - alex-semenyuk:box_t, r=dswij
Fix example

The example didn't show the actual problem [playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9d0e0727ca5bbd854767f50da693ca0f)
changelog: none
2022-08-16 13:27:10 +00:00
bors
86ac6e88a8 Auto merge of #9040 - miam-miam100:unused_named_parameter, r=dswij
Add new lint [`positional_named_format_parameters`]

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

changelog: Add new lint [`positional_named_format_parameters`] to warn when named parameters in format strings are used as positional arguments.
2022-08-16 13:11:27 +00:00
alexey semenyuk
9e9b3ddf69
Fix example 2022-08-16 12:50:53 +03:00
bors
a427b12803 Auto merge of #9328 - stanislav-tkach:borrow_deref_ref-remove-extra-deref-from-example, r=giraffate
Remove extra dereference from the borrow_deref_ref lint example

I don't think such minor change should be mentioned in the changelog.

changelog: none
2022-08-16 00:19:21 +00:00