Commit graph

8240 commits

Author SHA1 Message Date
Philipp Krones
98bf99e2f8 Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup 2022-09-09 13:36:26 +02:00
Michael Goulet
854f751b26 Appease clippy again 2022-09-09 01:31:46 +00:00
Michael Goulet
ac1c68a5e6 Make clippy happy 2022-09-09 01:31:45 +00:00
Jack Huey
b640eaa71d Remove ReEmpty 2022-09-08 20:55:55 -04:00
bors
b52fb5234c Auto merge of #9446 - mikerite:fix-9431-2, r=giraffate
Fix `range_{plus,minus}_one` bad suggestions

Fixes #9431.

The current `range_plus_one` and `range_minus_one` suggestions are completely incorrect when macros are involved.

This commit resolves this by disabling the lints for any range expression that is expanded from a macro. The reasons for this are that it is very difficult to create a correct suggestion in this case and that false negatives are less important for pedantic lints.

changelog: Fix `range_{plus,minus}_one` bad suggestions
2022-09-08 23:48:08 +00:00
Alex Macleod
6fc6d87fd0 Migrate write.rs to a late pass 2022-09-08 20:18:02 +00:00
Philipp Krones
4ee55c5528
Merge remote-tracking branch 'upstream/auto' into rustup 2022-09-08 21:27:09 +02:00
Michael Wright
a6d8afd958 Fix range_{plus,minus}_one bad suggestions
Fixes #9431.

The current `range_plus_one` and `range_minus_one` suggestions
are completely incorrect when macros are involved.

This commit resolves this by disabling the lints for any range
expression that is expanded from a macro. The reasons for this
are that it is very difficult to create a correct suggestion in
this case and that false negatives are less important for
pedantic lints.
2022-09-08 20:04:43 +02:00
bors
f47a1e24c7 Auto merge of #101577 - Dylan-DPC:rollup-l9xw7i7, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #98933 (Opaque types' generic params do not imply anything about their hidden type's lifetimes)
 - #101041 (translations(rustc_session): migrates rustc_session to use SessionDiagnostic - Pt. 2)
 - #101424 (Adjust and slightly generalize operator error suggestion)
 - #101496 (Allow lower_lifetime_binder receive a closure)
 - #101501 (Allow lint passes to be bound by `TyCtxt`)
 - #101515 (Recover from typo where == is used in place of =)
 - #101545 (Remove unnecessary `PartialOrd` and `Ord`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-09-08 15:53:14 +00:00
Dylan DPC
9faa588446 Rollup merge of #101501 - Jarcho:tcx_lint_passes, r=davidtwco
Allow lint passes to be bound by `TyCtxt`

This will allow storing things like `Ty<'tcx>` inside late lint passes. It's already possible to store various id types so they're already implicitly bound to a specific `TyCtxt`.

r? rust-lang/compiler
2022-09-08 20:48:36 +05:30
Caio
51d8b6c664 Rename the arithmetic lint 2022-09-08 12:04:55 -03:00
bors
30a5815505 Auto merge of #101467 - nnethercote:shrink-hir-Ty-Pat, r=spastorino
Shrink `hir::Ty` and `hir::Pat`

r? `@ghost`
2022-09-08 13:11:57 +00:00
Dylan DPC
c3db185c52 Rollup merge of #101498 - petrochenkov:visparam, r=cjgillot
rustc: Parameterize `ty::Visibility` over used ID

It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-08 11:55:09 +05:30
Nicholas Nethercote
c86a9c077c Introduce DotDotPos.
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-08 15:25:50 +10:00
bors
617417e9ad Auto merge of #9365 - c410-f3r:arith, r=Alexendoo
[Arithmetic] Consider literals

Fixes https://github.com/rust-lang/rust-clippy/issues/9307 and makes the `arithmetic` lint behave like `integer_arithmetic`.

It is worth noting that literal integers of a binary operation (`1 + 1`, `i32::MAX + 1`), **regardless if they are in a constant environment**, won't trigger the lint. Assign operations also have similar reasoning.

changelog: Consider literals in the arithmetic lint
2022-09-07 19:55:34 +00:00
Jason Newcomb
15859323ea Fix hang in vec_init_then_push 2022-09-07 15:26:44 -04:00
bors
567e1bbca7 Auto merge of #101432 - nnethercote:shrink-PredicateS, r=lcnr
Shrink `PredicateS`

r? `@ghost`
2022-09-07 13:49:58 +00:00
Caio
0d078c9fd6 [Arithmetic] Consider literals 2022-09-07 10:00:45 -03:00
Vadim Petrochenkov
9136096629 rustc: Parameterize ty::Visibility over used ID
It allows using `LocalDefId` instead of `DefId` when possible, and also encode cheaper `Visibility<DefIndex>` into metadata.
2022-09-07 13:35:41 +04:00
bors
7babd1b099 Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
Suggest `unwrap_or_default` when closure returns `"".to_string`

Closes https://github.com/rust-lang/rust-clippy/issues/9420

changelog: [`unwrap_or_else_default`]: suggest `unwrap_or_default()` instead of `unwrap_or_else` with a closure that returns an empty `to_string`.
2022-09-06 23:44:38 +00:00
Jason Newcomb
abd3e7eabb Allow lint passes to be bound by TyCtxt 2022-09-06 14:23:03 -04:00
xphoniex
b21d9d307b
Suggest unwrap_or_default when closure returns "".to_string
Signed-off-by: xphoniex <xphoniex@users.noreply.github.com>
2022-09-06 04:38:29 +00:00
bors
ce339b219a Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
`BindingAnnotation` refactor

* `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`)
* `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)`
* Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}`

One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`.

I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
2022-09-06 03:16:29 +00:00
bors
2ccf843471 Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, r=cjgillot
Separate the receiver from arguments in HIR

Related to #100232

cc `@cjgillot`
2022-09-05 16:21:40 +00:00
Takayuki Maeda
8931da40e3 use propagate_through_exprs instead of propagate_through_expr
fix `ExprKind` static_assert_size

fix hir-stats
2022-09-05 23:11:34 +09:00
bors
5ea99770d8 Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petrochenkov
Simplify `hir::PathSegment`

r? `@petrochenkov`
2022-09-05 13:36:54 +00:00
Takayuki Maeda
097ef517fe refactor: remove unnecessary variables 2022-09-05 22:31:02 +09:00
Takayuki Maeda
4bcaddeeb2 separate the receiver from arguments in HIR under /clippy 2022-09-05 22:25:57 +09:00
Dylan DPC
9ae329232b Rollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco
Improve HIR stats

#100398 improve the AST stats collection done by `-Zhir-stats`. This PR does the same for HIR stats collection.

r? `@davidtwco`
2022-09-05 14:15:51 +05:30
Nicholas Nethercote
2d4349c22d Pack Term in the same way as GenericArg.
This shrinks the `PredicateS` type, which is instanted frequently.
2022-09-05 15:08:52 +10:00
Nicholas Nethercote
25f6f18834 Make hir::PathSegment::res non-optional. 2022-09-05 14:20:25 +10:00
relrelb
f0e586c251 Suggest Entry::or_default for Entry::or_insert(Default::default())
Unlike past similar work done in #6228, expand the existing `or_fun_call`
lint to detect `or_insert` calls with a `T::new()` or `T::default()`
argument, much like currently done for `unwrap_or` calls. In that case,
suggest the use of `or_default`, which is more idiomatic.

Note that even with this change, `or_insert_with(T::default)` calls
aren't detected as candidates for `or_default()`, in the same manner
that currently `unwrap_or_else(T::default)` calls aren't detected as
candidates for `unwrap_or_default()`.

Also, as a nearby cleanup, change `KNOW_TYPES` from `static` to `const`,
since as far as I understand it's preferred (should Clippy have a lint
for that?).

Fixes #3812.
2022-09-04 23:43:17 +03:00
bors
90804d35fe Auto merge of #9425 - kraktus:patch-1, r=xFrednet
fix wording for `derivable_impls`

While looking at the explanation as to why this lint was not automatically applicable, found the explanation a bit clunky grammatically.

 Feel free to close if you consider the wording was correct in the first place.

changelog: none
2022-09-04 15:32:09 +00:00
kraktus
2cc20e3245 fix wording for derivable_impls 2022-09-04 17:20:54 +02:00
Michael Wright
750a2d57bd Fix unnecessary_to_owned false positive
Fixes #9351.

Note that this commit reworks that fix for #9317. The change
is to check that the type implements `AsRef<str>` before regarding
`to_string` as an equivalent of `to_owned`. This was suggested
by Jarcho in the #9317 issue comments.

The benefit of this is that it moves some complexity out of
`check_other_call_arg` and simplifies the module as a whole.
2022-09-03 17:00:44 +02:00
Lukas Lueg
584000a792 Use approx_ty_size for large_enum_variant 2022-09-03 00:16:28 +02:00
bors
c36696ac02 Auto merge of #9418 - lukaslueg:issue9415, r=llogiq
Fix `mut_mutex_lock` when Mutex is behind immutable deref

I *think* the problem here is the `if let ty::Ref(_, _, Mutability::Mut) = cx.typeck_results().expr_ty(recv).kind()` line tries to check if the `Mutex` can be mutably borrowed (there already is a test for `Arc<Mutex<_>>`), but gets bamboozled by the `&mut Arc` indirection. And I *think* checking the deref-adjustment to filter immutable-adjust (the deref through the `Arc`, starting from `&mut Arc`) is the correct fix.

Fixes #9415

changelog: Fix `mut_mutex_lock` when Mutex is behind immutable deref
2022-09-02 18:54:06 +00:00
Lukas Lueg
ffc75af4cd Fix mut_mutex_lock for Mutex behind imm deref
Fixes #9415
2022-09-02 20:39:47 +02:00
bors
958a9cf297 Auto merge of #9417 - Jarcho:ice_9414, r=Alexendoo
Don't use `hir_ty_to_ty` in `result_large_err`

fixes #9414

This occurs starting with 2022-09-01. I checked that this does fix the ICE on rust-lang/rust@9353538. Not sure which pr caused the late-bound region to leak through `hir_ty_to_ty`.

changelog: None
2022-09-02 18:07:38 +00:00
Cameron Steffen
e5f30f4dfa clippy: BindingAnnotation change 2022-09-02 13:03:11 -05:00
Jason Newcomb
bd70ccf915 Don't use hir_ty_to_ty in result_large_err as it sometimes leaves late-bound lifetimes. 2022-09-02 13:40:35 -04:00
Dmitrii Lavrov
b1f86a49ea
New lint bool_to_int_with_if 2022-09-01 23:23:56 +02:00
bors
a80e278036 Auto merge of #9404 - lukaslueg:issue9402, r=giraffate
Fix `suboptimal_float` not linting on `{const}.powf({const})`

There used to be an early return if the receiver was an effective const but the method was not linted, not taking into account later cases where the receiver and the arguments are both effective consts for different methods. Removed the early return.

Fixes #9402
Fixes #9201

changelog: Fix `suboptimal_flops`, `imprecise_flops` not linting on `{const}.powf({const})` et al
2022-09-01 13:18:17 +00:00
Lukas Lueg
6e14e60af4 Fix {subopt,imprec}_float not lint const.*(const)
Fixes #9402
Fixes #9201
2022-09-01 12:51:13 +02:00
Jason Newcomb
d4a0785464 Correctly handle unescape warnings 2022-09-01 00:00:37 -04:00
Jason Newcomb
7bd5b012c7 Use CountIsStart in clippy 2022-08-31 09:45:51 -04:00
Jason Newcomb
fb41bfa774 Merge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup 2022-08-31 09:24:45 -04:00
Tim Siegel
28a055dcea
match_wild_err_arm: Fix typo in note text 2022-08-31 09:09:11 -04:00
bors
f51aade56f Auto merge of #9397 - Jarcho:trait_dup_order, r=dswij
Fix the emission order of `trait_duplication_in_bounds`

Makes the lint emit in source order rather than whatever order the hash map happens to be in. This is currently blocking the sync into rustc.

changelog: None
2022-08-31 08:07:33 +00:00
Lukas Lueg
66a97055b2 Initial implementation of result_large_err 2022-08-30 17:39:40 +02:00
Jason Newcomb
19ef04ff5d Fix the order of trait_duplication_in_bounds
* Emit the lint in source order
* Make suggestions with multiple traits be in source order rather than alphabetical
2022-08-30 00:33:56 -04:00
bors
4df6032100 Auto merge of #9394 - lukaslueg:issue9391, r=Jarcho
Fix missing parens in `suboptimal_flops` suggestion

Fixes #9391. The problem is simple enough, I didn't check if the same problem occurs elsewhere, though.

changelog: fix missing parenthesis in `suboptimal_flops` suggestion
2022-08-30 00:37:45 +00:00
Lukas Lueg
9ffc5a5c8d Fix more parens for suboptimal_flops suggs 2022-08-29 22:36:11 +02:00
Nilstrieb
ce847beb47 Revert let_chains stabilization
This reverts commit 326646074940222d602f3683d0559088690830f4.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
clubby789
cc9f203543
Update clippy_lints/src/casts/mod.rs
Co-authored-by: Alex Macleod <alex@macleod.io>
2022-08-29 15:17:23 +01:00
clubby789
30979bfe83 Add lint cast_slice_from_raw_parts 2022-08-29 14:10:17 +01:00
Lukas Lueg
26a6891925 Fix missing parens in suboptimal_flops sugg
Fixes #9391
2022-08-29 13:56:03 +02:00
bors
58bbb1a95d Auto merge of #9385 - rust-lang:unnecessary-cast-remove-parens, r=Alexendoo
remove parenthesis from `unnecessary_cast` suggestion

This fixes #9380.

---

changelog: none
2022-08-29 11:49:08 +00:00
bors
28ec27b33a Auto merge of #9388 - Jarcho:rustup, r=Jarcho
Rustup

Hopefully this is done right.

changelog: None
2022-08-29 01:51:23 +00:00
Nicholas Nethercote
3ce109e12d Use &'hir Ty everywhere.
For consistency, and because it makes HIR measurement simpler and more
accurate.
2022-08-29 06:35:14 +10:00
Nicholas Nethercote
3b80e994d5 Use &'hir Expr everywhere.
For consistency, and because it makes HIR measurement simpler and more
accurate.
2022-08-29 06:35:14 +10:00
Jason Newcomb
9790a3291b Fixes for latest nightly 2022-08-28 06:44:22 -04:00
Jason Newcomb
3ad398d9b0 Merge branch 'master' into rustup 2022-08-28 06:44:13 -04:00
Lukas Lueg
c542f1fe3f Don't lint literal None from expansion 2022-08-28 12:18:50 +02:00
bors
8d9da4d7c7 Auto merge of #9276 - dswij:9164, r=flip1995
Ignore `match_like_matches_macro` when there is comment

Closes #9164

changelog: [`match_like_matches_macro`] is ignored when there is some comment inside the match block.

Also add `span_contains_comment` util to check if given span contains comments.
2022-08-28 07:08:18 +00:00
bors
2d4d8e16cd Auto merge of #8984 - xanathar:pr/suspicious_to_owned, r=llogiq
Implemented `suspicious_to_owned` lint to check if `to_owned` is called on a `Cow`

changelog: Add lint ``[`suspicious_to_owned`]``

-----------------
Hi,
posting this unsolicited PR as I've been burned by this issue :)
Being unsolicited, feel free to reject it or reassign a different lint level etc.

This lint checks whether `to_owned` is called on `Cow<'_, _>`. This is done because `to_owned` is very similarly named to `into_owned`, but the effect of calling those two methods is completely different (one makes the `Cow::Borrowed` into a `Cow::Owned`, the other just clones the `Cow`). If the cow is then passed to code for which the type is not checked (e.g. generics, closures, etc.) it might slip through and if the cow data is coming from an unsafe context there is the potential for accidentally cause undefined behavior.
Even if not falling into this painful case, there's really no reason to call `to_owned` on a `Cow` other than confusing people reading the code: either `into_owned` or `clone` should be called.

Note that this overlaps perfectly with `implicit_clone` as a warning, but `implicit_clone` is classified pedantic (while the consequences for `Cow` might be of a wider blast radius than just pedantry); given the overlap, I set-up the lint so that if `suspicious_to_owned` triggers `implicit_clone` will not trigger. I'm not 100% sure this is done in the correct way (I tried to copy what other lints were doing) so please provide feedback on it if it isn't.

### Checklist

- \[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`
2022-08-27 17:38:40 +00:00
dswij
b07d72b69e Ignore when there is comment 2022-08-28 00:07:00 +08:00
Andre Bogus
90fe3bea52 remove parenthesis from unnecessary_cast suggestion 2022-08-27 12:04:19 +02:00
Marco Mastropaolo
de028e2fb9 Implemented suspicious_to_owned lint to check if to_owned is called on a Cow.
This is done because `to_owned` is very similarly named to `into_owned`, but the
effect of calling those two methods is completely different. This creates
confusion (stemming from the ambiguity of the 'owned' term in the context of
`Cow`s) and might not be what the writer intended.
2022-08-26 17:41:17 -07:00
Lukas Lueg
fe93b8d001 Don't lint needless_return if return has attrs
Fixes #9361
2022-08-26 19:06:07 +02:00
bors
602bec26b0 Auto merge of #9374 - sk1p:patch-1, r=Jarcho
uninit_vec: Vec::spare_capacity_mut is stable

Quick documentation fix: `Vec::spare_capacity_mut` no longer needs nightly.

changelog: none
2022-08-26 13:15:58 +00:00
Tomasz Miąsko
e4eddc611a Replace Body::basic_blocks() with field access 2022-08-26 14:27:08 +02:00
bors
21f103abcc Auto merge of #9379 - royrustdev:multi_assignments, r=llogiq
new lint

This fixes #6576

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
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog: add [`multi_assignments`] lint
2022-08-26 12:05:57 +00:00
royrustdev
fb7dffeac9 add multi_assignments lint 2022-08-26 17:05:52 +05:30
Alexander Clausen
61aa4efbf1
uninit_vec: Vec::spare_capacity_mut is stable
Quick documentation fix: `Vec::spare_capacity_mut` no longer needs nightly.
2022-08-25 14:10:55 +02:00
bors
79a439a48a Auto merge of #9370 - mikerite:20220824_ty_contains, r=Jarcho
Replace `contains_ty(..)` with `Ty::contains(..)`

This removes some code we don't need and the method syntax is
also more readable IMO.

changelog: none
2022-08-24 13:34:32 +00:00
Michael Wright
a0afbdfbec Replace contains_ty(..) with Ty::contains(..)
This removes some code we don't need and the method syntax is
also more readable IMO.
2022-08-24 08:11:29 +02:00
Alex Macleod
2cb5318e97 Rename manual_empty_string_creation and move to pedantic 2022-08-23 14:19:46 +00:00
Nicholas Nethercote
06d7119f40 Remove the symbol from ast::LitKind::Err.
Because it's never used meaningfully.
2022-08-23 16:56:24 +10:00
Samuel E. Moelius III
0bc26c811c needed_ref -> needs_ref 2022-08-21 19:38:09 +00:00
Samuel E. Moelius III
687fcf14c4 Fix to_string_in_format_args false positive 2022-08-21 19:38:09 +00:00
bors
cc637bacfa Auto merge of #9092 - tamaroning:fix-needless-match, r=llogiq
Fix false positives of needless_match

closes: #9084
made needless_match take into account arm in the form of `_ if => ...`

changelog: none
2022-08-21 13:22:21 +00:00
bors
e19a05cbb3 Auto merge of #8992 - kyoto7250:fix_8753, r=flip1995
feat(fix): Do not lint if the target code is inside a loop

close #8753

we consider the following code.

```rust
fn main() {
    let vec = vec![1];
    let w: Vec<usize> = vec.iter().map(|i| i * i).collect();  // <- once.

    for i in 0..2 {
        let _ = w.contains(&i);
    }
}
```

and the clippy will issue the following warning.

```rust
warning: avoid using `collect()` when not needed
 --> src/main.rs:3:51
  |
3 |     let w: Vec<usize> = vec.iter().map(|i| i * i).collect();
  |                                                   ^^^^^^^
...
6 |         let _ = w.contains(&i);
  |                 -------------- the iterator could be used here instead
  |
  = note: `#[warn(clippy::needless_collect)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_collect
help: check if the original Iterator contains an element instead of collecting then checking
  |
3 ~
4 |
5 |     for i in 0..2 {
6 ~         let _ = vec.iter().map(|i| i * i).any(|x| x == i);
```

Rewrite the code as indicated.

```rust
fn main() {
    let vec = vec![1];

    for i in 0..2 {
        let _ = vec.iter().map(|i| i * i).any(|x| x == i);  // <- execute `map` every loop.
    }
}
```

this code is valid in the compiler, but, it is different from the code before the rewrite.
So, we should not lint, If `collect` is outside of a loop.

Thank you in advance.

---

changelog: Do not lint if the target code is inside a loop in `needless_collect`
2022-08-21 09:58:24 +00:00
Philipp Krones
318ed05920
Reduce code duplication
Only check for the kind of loop once instead of re-desugaring it.
2022-08-21 11:03:54 +02:00
kyoto7250
5048af7a3a
feat(fix): Do not lint if the target code is inside a loop 2022-08-21 10:47:03 +02:00
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
Matthias Krüger
37eeed701a Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkov
Clean up `LitKind`

r? ``@petrochenkov``
2022-08-17 12:32:49 +02: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
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
Nicholas Nethercote
e92183c286 Rename some things related to literals.
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is
  `token::Lit`, which is not a token. (This has been confusing me for a
  long time.)
  reasonable because we have an `ast::token::Lit` inside an `ast::Lit`.
- Rename `LitKind::{from,to}_lit_token` as
  `LitKind::{from,to}_token_lit`, to match the above change and
  `token::Lit`.
2022-08-16 13:41:34 +10:00
Nicholas Nethercote
6e5f90ae46 Shrink ast::Attribute. 2022-08-16 11:10:13 +10: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
bors
0fc95e88f5 Auto merge of #9318 - lukaslueg:ifletmutexref, r=xFrednet
Fix if_let_mutex not checking Mutexes behind refs

Fixes #9193

We can always peel references because we are looking for a method-call, for which autoderef applies.

---

changelog: [`if_let_mutex`]: detect calls to `Mutex::lock()` if mutex is behind a ref
changelog: [`if_let_mutex`]: Add labels to the two instances of the same Mutex that will deadlock
2022-08-15 21:31:37 +00:00
Stanislav Tkach
7727c303e5
Simplify the borrow_deref_ref lint example 2022-08-15 20:48:40 +02:00
lukaslueg
6de4bdfa8e Fix label not starting with lcase-letter
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2022-08-15 20:24:30 +02:00
bors
8c9040ceaa Auto merge of #9329 - xphoniex:fix-#9317, r=flip1995
Skip `unnecessary_to_owned` when `t != t.to_string()`

Fixes #9317

changelog: [`unnecessary_to_owned`]: none
2022-08-15 10:01:20 +00:00
bors
86a0a18179 Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillot
Visit attributes in more places.

This adds 3 loosely related changes (I can split PRs if desired):

- Attribute checking on pattern struct fields.
- Attribute checking on struct expression fields.
- Lint level visiting on pattern struct fields, struct expression fields, and generic parameters.

There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-15 05:50:54 +00:00
xphoniex
1a2aaf68de
Skip unnecessary_to_owned when t != t.to_string()
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2022-08-14 16:29:26 +00:00
Guilherme-Vasconcelos
1bf8841479 Update all tests to comply with clippy::manual_empty_string_creations 2022-08-14 12:53:15 -03:00