Commit graph

6291 commits

Author SHA1 Message Date
Caio
51d8b6c664 Rename the arithmetic lint 2022-09-08 12:04:55 -03: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
Caio
0d078c9fd6 [Arithmetic] Consider literals 2022-09-07 10:00:45 -03: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
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
Takayuki Maeda
4bcaddeeb2 separate the receiver from arguments in HIR under /clippy 2022-09-05 22:25:57 +09: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
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
dswij
f0d642ea38 Use macro source when creating Sugg helper 2022-09-01 18:46:53 +08:00
Jason Newcomb
d4a0785464 Correctly handle unescape warnings 2022-09-01 00:00:37 -04:00
bors
5b784f8ed2 Auto merge of #101249 - matthiaskrgr:rollup-wahnoz8, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #100787 (Pretty printing give proper error message without panic)
 - #100838 (Suggest moving redundant generic args of an assoc fn to its trait)
 - #100844 (migrate rustc_query_system to use SessionDiagnostic)
 - #101140 (Update Clippy)
 - #101161 (Fix uintended diagnostic caused by `drain(..)`)
 - #101165 (Use more `into_iter` rather than `drain(..)`)
 - #101229 (Link “? operator” to relevant chapter in The Book)
 - #101230 (lint: avoid linting diag functions with diag lints)
 - #101236 (Avoid needless buffer zeroing in `std::sys::windows::fs`)
 - #101240 (Fix a typo on `wasm64-unknown-unknown` doc)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-08-31 21:45:18 +00:00
Jason Newcomb
fb41bfa774 Merge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup 2022-08-31 09:24:45 -04:00
Ralf Jung
7298de2568 fix a clippy test 2022-08-31 15:24:40 +02: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
bors
7ba06ec9c5 Auto merge of #98919 - 5225225:stricter-invalid-value, r=RalfJung
Strengthen invalid_value lint to forbid uninit primitives, adjust docs to say that's UB

For context: https://github.com/rust-lang/rust/issues/66151#issuecomment-1174477404=

This does not make it a FCW, but it does explicitly state in the docs that uninit integers are UB.

This also doesn't affect any runtime behavior, uninit u32's will still successfully be created through mem::uninitialized.
2022-08-30 20:39:01 +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
5225225
98fe5f7c7d Fix tests due to stricter invalid_value 2022-08-29 21:28:35 +01:00
bors
e1ecdb621c Auto merge of #9395 - Alexendoo:suspicious-to-owned-test, r=Manishearth
Fix `suspicious_to_owned` test when `c_char` is `u8`

e.g. on aarch64 linux

changelog: none
2022-08-29 19:26:22 +00: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
30979bfe83 Add lint cast_slice_from_raw_parts 2022-08-29 14:10:17 +01:00
Alex Macleod
c5a82304cf Fix suspicious_to_owned test when c_char is u8 2022-08-29 12:17:08 +00: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
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
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
Joshua Nelson
345c42a2d6 Stabilize #![feature(label_break_value)]
# Stabilization proposal

The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now).
There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`.

There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed).
1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234
2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176
3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630

Many different examples of code that's simpler using this feature have been provided:
- A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014
- A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize).
- Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395
- Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733
- An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569
- Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006

Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249

nrc later resolved their concern, mostly because of the aforementioned macro problems.
joshtriplett suggested that macros could be able to generate IR directly
(https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs,
and the design space seems rather speculative.

joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804

withoutboats has regrettably left the language team.

joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353

[issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+

 ## Report

+ Feature gate:
    - d695a497bb/src/test/ui/feature-gates/feature-gate-label_break_value.rs
+ Diagnostics:
    - 6b2d3d5f3c/compiler/rustc_parse/src/parser/diagnostics.rs (L2629)
    - f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L749)
    - f65bf0b2bb/compiler/rustc_resolve/src/diagnostics.rs (L1001)
    - 111df9e6ed/compiler/rustc_passes/src/loops.rs (L254)
    - d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L2079)
    - d695a497bb/compiler/rustc_parse/src/parser/expr.rs (L1569)
+ Tests:
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs
    - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs

 ## Interactions with other features

Labels follow the hygiene of local variables.

label-break-value is permitted within `try` blocks:
```rust
let _: Result<(), ()> = try {
    'foo: {
        Err(())?;
        break 'foo;
    }
};
```

label-break-value is disallowed within closures, generators, and async blocks:
```rust
'a: {
    || break 'a
    //~^ ERROR use of unreachable label `'a`
    //~| ERROR `break` inside of a closure
}
```

label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]:
```rust
fn labeled_match() {
    match false 'b: { //~ ERROR block label not supported here
        _ => {}
    }
}

macro_rules! m {
    ($b:block) => {
        'lab: $b; //~ ERROR cannot use a `block` macro fragment here
        unsafe $b; //~ ERROR cannot use a `block` macro fragment here
        |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here
    }
}

fn foo() {
    m!({});
}
```

[_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html
[_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23 21:14:12 -05:00
Nahua Kang
4eaadd622d Run cargo dev bless to update fixes & stderr 2022-08-23 20:02:58 +02:00
Nahua Kang
5ee1c24f28 Lint suggests matches macro if PartialEq trait is not implemented 2022-08-23 19:46:04 +02:00
Alex Macleod
2cb5318e97 Rename manual_empty_string_creation and move to pedantic 2022-08-23 14:19:46 +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
070b0350df
Improve error if rustfix coverage test spuriously fails 2022-08-21 11:57:05 +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
tamaron
f7a376e4fc Update needless_match.stderr 2022-08-21 17:26:39 +09: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
Samuel E. Moelius III
6f3d398e13 Add test for #8855 2022-08-20 15:21:32 +00: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
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
89698b9613 Extend and improve initial test cases for collapsible_str_replace 2022-08-19 19:49:16 +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
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
8acc4d2f1e Move VecResizeToZero into Methods lint pass 2022-08-19 10:54:55 -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
Jason Newcomb
48cb816530 Handle CARGO_TARGET_DIR not being set in compile-test 2022-08-16 21:22:29 -04: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
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
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
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
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
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
Guilherme-Vasconcelos
80826c3944 Implement clippy::manual_empty_string_creations lint 2022-08-14 12:45:24 -03:00
bors
679fa9f2bf Auto merge of #9187 - sgued:iter-once, r=flip1995
Add lint recommending using `std::iter::once` and `std::iter::empty`

```
changelog: [`iter_once`]: add new lint
changelog: [`iter_empty`]: add new lint
```

fixes #9186

- \[ ] 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`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

The lint doesn't really follow the naming conventions. I don't have any better idea so I'm open to suggestions.
2022-08-14 15:45:17 +00:00
bors
84df61c06e Auto merge of #9167 - aldhsu:fix-trait-duplication-false-pos, r=flip1995
Fixes [`trait_duplication_in_bounds`] false positives

Fixes #9076 #9151 #8757.
Partially fixes #8771.

changelog: [`trait_duplication_in_bounds`]: Reduce number of false positives.
2022-08-14 14:46:26 +00:00
bors
05fc1c7dbc Auto merge of #9289 - mkrasnitski:9094, r=xFrednet
Extend `if_then_some_else_none` to also suggest `bool::then_some`

Closes #9094.

changelog: Extend `if_then_some_else_none` to also suggest `bool::then_some`
2022-08-12 06:25:59 +00:00
Allen Hsu
8bae517c2d Lint trait duplication in one pass. 2022-08-12 12:51:58 +10:00
Philipp Krones
dc29cfb8d5 Merge commit '2b2190cb5667cdd276a24ef8b9f3692209c54a89' into clippyup 2022-08-11 19:42:16 +02:00
Philipp Krones
879855bbaf
Merge remote-tracking branch 'upstream/master' into rustup 2022-08-11 19:26:04 +02:00
tamaron
45084eeefb give up when gurad has side effects 2022-08-11 15:07:39 +09:00
tamaron
459821b191 fix 2022-08-11 15:07:38 +09:00
Lukas Lueg
0428f0d234 Add labels to if_let_mutex 2022-08-10 21:07:07 +02:00
Lukas Lueg
6a73a45418 Fix if_let_mutex not checking Mutexes behind refs
Fixes #9193
2022-08-10 19:40:42 +02:00
miam-miam100
9ffddf563c
Add new lint [positional_named_format_parameters] 2022-08-09 21:03:41 +01:00
dAxpeDDa
8d4f2ac381
Use check_proc_macro for missing_const_for_fn 2022-08-09 03:41:59 +02:00
bors
3af9072bc6 Auto merge of #9288 - lukaslueg:partialeqnone, r=Jarcho
Add partialeq_to_none lint

Initial implementation of #9275, adding lint `partialeq_to_none`. This is my first time working on `clippy`, so please review carefully.

I'm unsure especially about the `Sugg`, as it covers the entire `BinOp`, instead of just covering one of the sides and the operator (see the multi-line example). I was unsure if pinpointing the suggestion wouldn't be brittle...

changelog: [`PARTIALEQ_TO_NONE`]: Initial commit
2022-08-09 00:12:29 +00:00
Sosthène Guédon
af4885c0cd Rename new lints to iter_on_empty_collections and iter_on_single_items 2022-08-08 21:05:27 +02:00
Sosthène Guédon
b247594a39 Prevent some false positives 2022-08-08 21:04:44 +02:00
Sosthène Guédon
f30d7c2495 Improve suggestions 2022-08-08 21:04:44 +02:00
Sosthène Guédon
f3f86d8fd9 Move iter_once and iter_empty to methods as a late pass
This enables more thorough checking of types to avoid triggering on
custom Some and None enum variants
2022-08-08 21:04:44 +02:00
Sosthène Guédon
73cd95465e Add iter_once and iter_empty lints 2022-08-08 21:04:41 +02:00
Lukas Lueg
657b0da912 Add partialeq_to_none lint
Fixes #9275
2022-08-08 20:17:13 +02:00
Federico Guerinoni
f6cab94bd0 Rename logic_bug to overly_complex_bool_expr
Closes #1916
2022-08-08 18:38:39 +02:00
bors
4912c0ece4 Auto merge of #9126 - Jarcho:auto_deref_sugg, r=Manishearth
`explicit_auto_deref` changes

fixes #9123
fixes #9109
fixes #9143
fixes #9101

This avoid suggesting code which hits a rustc bug. Basically `&{x}` won't use auto-deref if the target type is `Sized`.

changelog: Don't suggest using auto deref for block expressions when the target type is `Sized`
changelog: Include the borrow in the suggestion for `explicit_auto_deref`
changelog: Don't lint `explicit_auto_deref` on `dyn Trait` return
changelog: Don't lint `explicit_auto_deref` when other adjustments are required
changelog: Lint `explicit_auto_deref` in implicit return positions for closures
2022-08-08 15:20:24 +00:00
Jason Newcomb
ecb51fe6a5 Lint explicit_auto_deref in implicit return positions for closures 2022-08-08 10:25:05 -04:00
Jason Newcomb
5285928bc0 Fix ICE when checking the HIR ty of closure args. 2022-08-08 10:09:05 -04:00
bors
0ee702514e Auto merge of #9303 - Jarcho:ice_9297, r=Alexendoo
Fix ICE when reading literals with weird proc-macro spans

fixes #9297
changelog: Fix ICE when reading literals with weird proc-macro spans
2022-08-08 11:36:27 +00:00
Jason Newcomb
99abd4a9f6 Fix ICE when reading literals with weird proc-macro spans 2022-08-07 22:22:17 -04:00
Jason Newcomb
670efd5720 Don't lint default_trait_access in proc-macro expansions 2022-08-07 21:55:08 -04:00
Jason Newcomb
4ae582ef88 Don't lint missing_docs_in_private_items on proc-macro output 2022-08-07 21:53:51 -04:00
Jason Newcomb
2ae8b300a7 Don't lint unit_arg when expanded from a proc-macro 2022-08-07 21:52:25 -04:00
Jason Newcomb
99e77d07b2 Allow type erasure using *const/mut int_type in transmute_undefined_repr 2022-08-07 17:58:31 -04:00
bors
5721ca9a13 Auto merge of #9294 - alex-semenyuk:enable_def_id_nocore_on_windows, r=xFrednet
Enable test for def_id_nocore for windows

Verified that it actully works on windows
changelog: none
2022-08-05 21:08:19 +00:00
alex-semenyuk
1e1193f4fa Enable test for def_id_nocore for windows 2022-08-05 23:24:50 +03:00
bors
57731f1dd7 Auto merge of #9292 - alex-semenyuk:typos_fixed, r=Alexendoo
Fix some typos

changelog: none
2022-08-05 09:19:07 +00:00
alex-semenyuk
f63b324ab1 Fix some typos 2022-08-05 00:59:21 +03:00
bors
2dc7d2f7f5 Auto merge of #9266 - alex-semenyuk:cast_abs_to_unsigned_paren_fix, r=Jarcho
Fix cast_abs_to_unsigned with code in parens

Close #9185
changelog: none
2022-08-04 18:45:32 +00:00
alex-semenyuk
0e1d65850a Fix cast_abs_to_unsigned generates non-compiling code when original code is in parens 2022-08-04 21:30:50 +03:00
alex-semenyuk
7062a013e7 Fix some typos 2022-08-04 19:53:07 +03:00
Michael Krasnitski
80f0f280df Extend if_then_some_else_none to also suggest bool::then_some 2022-08-03 23:18:59 -04:00
Jason Newcomb
b426bd52a1 Don't lint transmute_undefined_repr when the the first field of a repr(C) type is compatible with the other type 2022-08-03 14:41:32 -04:00
bors
71777465cc Auto merge of #9284 - lengyijun:typo, r=dswij
fix typo in tests/ui/redundant_allocation.rs

changelog: none
2022-08-03 10:33:45 +00:00
Fabian Wolff
f232402057 Warn about dead tuple struct fields 2022-08-03 12:17:23 +02:00
lengyijun
b50ba06a83 fix typo in tests/ui/redundant_allocation.rs 2022-08-03 04:57:36 +00:00
Daniel Macovei
503c03c558 clean up 2022-08-02 12:06:22 -05:00
Daniel Macovei
145ebb1cd7 add paren before '?' when suggesting deref 2022-08-02 10:39:35 -05:00
bors
05e7d5481b Auto merge of #9053 - AaronC81:fix-9052, r=flip1995
Fix suggestions for `async` closures in redundant_closure_call

Fixes #9052

changelog: Fix suggestions given by [`redundant_closure_call`] for async closures
2022-08-02 12:39:37 +00:00
Allen Hsu
3ddc04f4db Add extra test cases from #8771, #8757, #9076. 2022-08-02 22:00:04 +10:00
Allen Hsu
b96842d7d7 Split unfixable lints. 2022-08-02 22:00:04 +10:00
Allen Hsu
171d082433 Compare where predicates to trait bounds.
- only compare where predicates to trait bounds when generating where
  clause specific message to fix #9151
- use comparable_trait_ref to account for trait bound generics to fix #8757
2022-08-02 22:00:04 +10:00
bors
00e59cdad0 Auto merge of #9264 - guerinoni:instant-elapsed, r=Alexendoo
Add `elapsed_instant` lint

Closes #8603

- \[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: [`elapsed_instant`]: Add lint
2022-08-02 11:16:47 +00:00
bors
367d09fc4e Auto merge of #9254 - alex-semenyuk:enable_empty_loop_no_std_on_windows, r=dswij
Enable test empty_loop_no_std on windows

Verified that it actully works on windows
changelog: none
2022-08-02 06:44:03 +00:00
Federico Guerinoni
0696624ba7 Add elapsed_instant lint
Closes #8603

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
2022-08-01 23:39:00 +02:00
bors
a5a6c95da8 Auto merge of #9273 - tabokie:assert_ok_fp, r=flip1995
Move [`assertions_on_result_states`] to restriction

Close #9263

This lint causes regression on readability of code and log output. And printing runtime values is not particularly useful for majority of tests which should be reproducible.

changelog: Move [`assertions_on_result_states`] to restriction and don't lint it for unit type

Signed-off-by: tabokie <xy.tao@outlook.com>
2022-08-01 12:16:45 +00:00
tabokie
48ad9d8bc7 do not apply [assertions_on_result_states] to unwrap unit type
Signed-off-by: tabokie <xy.tao@outlook.com>
2022-08-01 20:13:33 +08:00
bors
a591e725a6 Auto merge of #9223 - sgued:unwrap-expect-used, r=giraffate
unwrap_used: Don't recommend using `expect` when the `expect_used` lint is not allowed

Fixes #9222

```
changelog: [`unwrap_used`]: Don't recommend using `expect` when the `expect_used` lint is not allowed
```
2022-08-01 01:27:03 +00:00
Andy Caldwell
56c9cc458d
Add deprecation test for old configuration entry 2022-07-29 19:39:20 +01:00
Andy Caldwell
66b46749e6
Change lint name to plural 2022-07-29 19:35:39 +01:00
Andy Caldwell
2f48257cfb
Rename "blacklisted name" to "disallowed name" throughout 2022-07-29 19:35:18 +01:00
bors
53a09d4855 Auto merge of #9252 - Metaswitch:use-deprecated-config, r=Jarcho
Read and use deprecated configuration (as well as emitting a warning)

Original change written by `@flip1995` I've simply rebased to master and fixed up the formatting/tests.  This change teaches the configuration parser which config key replaced a deprecated key and attempts to populate the latter from the former.  If both keys are provided this fails with a duplicate key error (rather than attempting to guess which the user intended).

Currently this on affects `cyclomatic-complexity-threshold` -> `cognitive-complexity-threshold` but will also be used in #8974 to handle `blacklisted-names` -> `disallowed-names`.

```
changelog: deprecated configuration keys are still applied as if they were provided as their non-deprecated name.
```

- [x] `cargo test` passes locally
- [x] Run `cargo dev fmt`
2022-07-29 00:54:10 +00:00
Andy Caldwell
ea25ef10cf
Harden duplicates checking and add tests 2022-07-28 23:05:24 +01:00
Philipp Krones
67c405cc1d Merge commit '3c7e7dbc1583a0b06df5bd7623dd354a4debd23d' into clippyup 2022-07-28 19:08:22 +02:00
Philipp Krones
0905ec465d
Merge remote-tracking branch 'upstream/master' into rustup 2022-07-28 18:55:32 +02:00
alex-semenyuk
38e80132d5 Enable test empty_loop_no_std on windows 2022-07-28 10:57:01 +03:00
Philipp Krones
08e7ec4047
Read and use deprecated configuration (as well as emitting a warning)
Co-authored-by: Andy Caldwell <andycaldwell@microsoft.com>
2022-07-27 17:47:20 +01:00
bors
d72e5f2e10 Auto merge of #9241 - Jarcho:ice_9238, r=xFrednet
Fix ICE in `miri_to_const`

fixes #9238
changelog: Fix ICE when using `#![feature(generic_const_exprs)]` in various lints
2022-07-25 22:14:55 +00:00
bors
8882578a67 Auto merge of #9130 - c410-f3r:arith, r=llogiq
Add `Arithmetic` lint

Fixes https://github.com/rust-lang/rust-clippy/issues/8903

r? `@llogiq`

changelog: Add `Arithmetic` lint
2022-07-25 21:26:15 +00:00
bors
c76db5c04e Auto merge of #9243 - Jarcho:std_core, r=Manishearth
Don't lint `std_instead_of_core` on `std::env`

fixes #9239

This also reorders the execution of the lint to do as little as possible in the case where the path doesn't start with `std` or `alloc`.

changelog: [`std_instead_of_core`](https://rust-lang.github.io/rust-clippy/master/#std_instead_of_core): Don't lint on `use std::env`
changelog: [`std_instead_of_alloc`](https://rust-lang.github.io/rust-clippy/master/#std_instead_of_alloc): Don't lint `use std::vec` twice
2022-07-25 15:19:41 +00:00
bors
1cce0477e4 Auto merge of #9225 - tabokie:assert_ok, r=Jarcho
add `[assertions_on_result_states]` lint

Close #9162

changelog: add `[assertions_on_result_states]` lint

Signed-off-by: tabokie <xy.tao@outlook.com>
2022-07-25 15:00:27 +00:00
tabokie
8454602cef Add [assertions_on_result_states] lint
Signed-off-by: tabokie <xy.tao@outlook.com>
2022-07-25 22:42:41 +08:00
bors
a14edd571e Auto merge of #9246 - kyoto7250:reopen_issue_8493, r=Jarcho
check macro statements in `[non_copy_const]`

close #8493
close #9224

This PR fixes false positives in `[non_copy_const]`.

changelog: fix false positives in`[non_copy_const]`

---

r? `@Jarcho`
2022-07-25 14:26:27 +00:00
kyoto7250
b6c301055e fixed tests to not use tokio 2022-07-25 23:04:18 +09:00
kyoto7250
477356460b check macro statements in non_copy_const.rs 2022-07-25 22:28:49 +09:00
bors
f847795bb2 Auto merge of #9245 - alex-semenyuk:enable_multiple_config_files_on_windows, r=Alexendoo
Enable test multiple_config_files on windows

Verified that it actully works on windows
changelog: none
2022-07-25 12:24:41 +00:00
alex-semenyuk
b5e5b42815 Enable test multiple_config_files on windows 2022-07-25 13:57:26 +03:00
Jason Newcomb
6bc024df18 Improve [std|alloc]_instead_of_[alloc|core] lints
* Don't call `TyCtxt::crate_name` unless necessary
* Don't lint on `use std::env`
* Only lint once on `use std::vec`
2022-07-24 23:15:39 -04:00
Jason Newcomb
2255cfd2ab Fix ICE in question_mark 2022-07-24 23:12:29 -04:00
Jason Newcomb
ab6463e9d9 Fix ICE in miri_to_const 2022-07-24 18:23:33 -04:00
Alex Macleod
d60d5e8bde Fix useless_format spans for format!("{foo}") 2022-07-24 16:47:17 +00:00
Michael Goulet
632f9945d6 Do not resolve associated const when there is no provided value 2022-07-22 18:58:07 +00:00
Sosthène Guédon
3e52031471 unwrap_used: Fix help, "an None" -> "None" 2022-07-22 19:14:58 +02:00
Sosthène Guédon
6ee03e2b01 unwrap_used: Stop recommending using expect when the expect_used lint is not allowed 2022-07-21 22:50:54 +02:00
bors
05a51e5730 Auto merge of #9214 - Jarcho:assign_op_prim, r=Manishearth
Check `assign_op_pattern` for conflicting borrows

fixes #9180

changelog: [`assign_op_pattern`](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern): Don't lint when the suggestion would cause borrowck errors.
2022-07-21 17:00:40 +00:00
bors
fa3c293db4 Auto merge of #9215 - alex-semenyuk:enable_test_entrypoint_recursion, r=Jarcho
Enable test for entrypoint_recursion for windows

Verified that this test actually works on windows
changelog: none
2022-07-21 15:45:50 +00:00
bors
bc903cd3c2 Auto merge of #9216 - smoelius:master, r=flip1995
Add `ui_cargo_toml_metadata` test

This PR adds a test to check the metadata of packages in the `ui_cargo` directory.

A recent change to Cargo causes it to warn when it finds multiple packages with the same name in a git dependency (the issue is described [here](https://github.com/rust-lang/cargo/issues/10752)).

Many (if  not all) Dylint libraries depend upon `clippy_utils`. As a result of the change, one now sees the following when building a Dylint library:
```
warning: skipping duplicate package `fail` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/module_style/pass_mod`
warning: skipping duplicate package `fail` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/module_style/fail_no_mod`
warning: skipping duplicate package `cargo_common_metadata` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_common_metadata/fail_publish_true`
warning: skipping duplicate package `fail-cargo` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/pass_cargo`
warning: skipping duplicate package `fail-clippy` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/fail_clippy`
warning: skipping duplicate package `fail-both-same` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/fail_both_same`
warning: skipping duplicate package `fail-file-attr` found at `/home/smoelius/.cargo/git/checkouts/rust-clippy-4b72815e96774b3d/0cb0f76/tests/ui-cargo/cargo_rust_version/fail_file_attr`
```
There appear to be two contributing factors:
- Some packages in `ui_cargo` could have a `publish = false` added to them.
- Some packages in `ui_cargo` seem to be inconsistently named.

The new test checks that each package in the `ui_cargo` directory has a name matching one of its parent directories, and `publish = false` in its metadata (with a few exceptions).

Note that the packages in `cargo_common_metadata` require special care because `publish` is the subject of some of the `cargo_common_metadata` tests.

Also note that this PR adds `walkdir` as a dev dependency to the `clippy` package. However, it was already a dependency of `clippy_dev` and `lintcheck`. So hopefully this is acceptable.

Our continued thanks for making `clippy_utils` available, BTW. :)

r? `@flip1995`

changelog: none
2022-07-21 07:58:27 +00:00
alex-semenyuk
27d49b08d5 Enable test for entrypoint_recursion for windows 2022-07-20 21:41:12 +03:00
Jason Newcomb
a2f9b93116 Don't lint assign_op_pattern when the suggestion would cause borrowck errors 2022-07-20 10:23:07 -04:00
bors
7c8e1bff90 Auto merge of #9207 - Jarcho:todo_arm, r=giraffate
Check for `todo!` on every expression in `SpanlessEq`

fixes #9204
changelog: [`match_same_arms`](https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms): Don't lint on arms with `todo!`
2022-07-20 01:38:00 +00:00
Evan Typanski
40340745a8 Use parens around [needless_borrow] field calls 2022-07-19 15:17:24 -04:00
Jason Newcomb
95c759157c Check for todo! on every expression in SpanlessEq 2022-07-19 09:57:18 -04:00
Michael Goulet
30a9533570 Mention first and last macro in backtrace 2022-07-19 03:07:54 +00:00
Caio
31e5465f8a Add Arithmetic lint 2022-07-18 14:29:45 -03:00
bors
cce617165d Auto merge of #9148 - arieluy:then_some_unwrap_or, r=Jarcho
Add new lint `obfuscated_if_else`

part of #9100, additional commits could make it work with `then` and `unwrap_or_else` as well

changelog: Add new lint `obfuscated_if_else`
2022-07-18 12:45:11 +00:00
bors
bf70865cf4 Auto merge of #9199 - Xiretza:unused-self-exported-api, r=Jarcho
unused_self: respect avoid-breaking-exported-api

```
changelog: [`unused_self`]: Now respects the `avoid-breaking-exported-api` config option
```

Fixes #9195.

I mostly copied the implementation from `unnecessary_wraps`, since I don't have much understanding of rustc internals.
2022-07-18 12:29:22 +00:00
bors
f4c9183531 Auto merge of #9146 - arieluy:type_params, r=dswij
Fix `mismatching_type_param_order` false positive

changelog: Don't lint `mismatching_type_param_order` on complicated generic params

fixes #8962
2022-07-18 10:13:39 +00:00
Xiretza
7a5965b459 unused_self: respect avoid-breaking-exported-api 2022-07-18 10:57:08 +02:00
Philipp Krones
7d4daaa8fa Merge commit 'fdb84cbfd25908df5683f8f62388f663d9260e39' into clippyup 2022-07-18 09:39:37 +02:00
Samuel E. Moelius III
5b3300dc29 Add ui_cargo_toml_metadata test 2022-07-17 22:17:58 -04:00
Ariel Uy
9ff7c91100 Add new lint obfuscated_if_else
New lint suggests using `if .. else ..` instead of
`.then_some(..).unwrap_or(..)`.
2022-07-17 18:44:49 -07:00
Ariel Uy
8cf39a8c19 Fix mismatching_type_param_order false positive
Previously was giving false positive when an impl had a nontrivial
generic argument such as a tuple. Don't lint on these cases.
2022-07-17 11:23:09 -07:00
Jason Newcomb
d602ab1445 Don't lint exlipicit_auto_deref when other adjustments are needed 2022-07-17 11:14:08 -04:00
Jason Newcomb
84e03b6215 Don't lint explicit_auto_deref on dyn Trait return 2022-07-17 11:14:07 -04:00
Jason Newcomb
9ce0f82b8a Include the borrow in the suggestion for explicit_auto_deref 2022-07-17 11:14:07 -04:00
Jason Newcomb
c990e2922a Don't suggest using auto deref for block expressions 2022-07-17 11:14:07 -04:00
Caio
f88a1399bb Stabilize let_chains 2022-07-16 20:17:58 -03:00
Aaron Christiansen
4c43aa7053 Fix suggestion for async in redundant_closure_call
Fix redundant_closure_call for single-expression async closures

Add Sugg::asyncify

Use Sugg for redundant_closure_call implementation
2022-07-15 15:49:04 +01:00
bors
aa0706bf20 Auto merge of #9178 - alex-semenyuk:match_like_matches_macro_fix, r=Jarcho
match_like_matches_macro does not trigger when one arm contains conta…

Close #9163
changelog: none
2022-07-15 13:57:46 +00:00
bors
fe6814508f Auto merge of #9174 - flip1995:rustup, r=Jarcho
Rustup

r? `@ghost`

changelog: none
2022-07-15 13:38:01 +00:00
Philipp Krones
f074034590
Merge remote-tracking branch 'upstream/master' into rustup 2022-07-15 09:49:15 +02:00
alex-semenyuk
2894df3409 match_like_matches_macro does not trigger when one arm contains contains a block with only a bool literal 2022-07-15 09:15:31 +03:00
i509VCB
2f825db578
std_instead_of_core, std_instead_of_alloc, alloc_instead_of_core 2022-07-14 16:05:52 -05:00
bors
0f5a38f2d6 Auto merge of #9170 - Rqnsom:box_collection, r=Jarcho
[`box_collection`]: raise warn for all std collections

So far, only [`Vec`, `String`, `HashMap`] were considered.

Extend collection checklist for this lint with:
- `HashSet`
- `VecDeque`
- `LinkedList`
- `BTreeMap`
- `BTreeSet`
- `BinaryHeap`

changelog: [`box_collection`]: raise warn for all std collections
2022-07-14 13:02:06 +00:00
Ralf Jung
eee0bf459d add array tests, cleanup, tidy, and bless 2022-07-13 18:31:29 -04:00
bors
a7162f29b4 Auto merge of #9134 - Jarcho:while_let_iter_closure, r=dswij
Improve `while_let_on_iterator` suggestion inside an `FnOnce` closure

changelog: Improve `while_let_on_iterator` suggestion inside an `FnOnce` closure
2022-07-13 16:20:14 +00:00
Korlo
467e1b23aa box_collection: raise warn for all std collections
So far, only [Vec, String, Hashmap] were considered.

Extend collection checklist for this lint with:
- HashSet
- VecDeque
- LinkedList
- BTreeMap
- BTreeSet
- BinaryHeap
2022-07-13 17:02:09 +02:00
bors
0db9280783 Auto merge of #9159 - alex-semenyuk:fix_typos, r=dswij
Fix typos

changelog: none
2022-07-13 14:48:32 +00:00
bors
0930ac91b9 Fix typos
changelog: none
2022-07-13 14:48:32 +00:00
Alex Macleod
018684dd9a Use LazyLock for lint_message_convention regexes 2022-07-13 14:10:39 +00:00
bors
f78292a4ad Auto merge of #9156 - Rqnsom:manual_flatten, r=Alexendoo
fix [`manual_flatten`] help texts order

fixes  #8948

Whenever suggestion for this lint does not fit in one line,
legacy solution has some unexpected/unhandled behavior:
lint will then generate two help messages which seem to be shown in the wrong order.
The second help message in that case will contain the suggestion.

The first help message always refers to a suggestion message,
and **it should adapt** depending on the location of the suggestion:
- inline suggestion within the error/warning message
- suggestion separated into a second help text

This is my first contribution here, so I hope I didn't miss anything for creating this PR.

changelog: fix [`manual_flatten`] help texts order
2022-07-13 12:52:08 +00:00
Korlo
852c38c543 fix for manual_flatten help texts order
Whenever suggestion for this lint does not fit in one line,
lint will generate two help messages. The second help message
will always contain the suggestion.

The first help message refers to suggestion message,
and it should adapt depending on the location of the suggestion:
- inline suggestion within the error/warning message
- suggestion separated into second help text
2022-07-13 09:33:17 +02:00
bors
9ebacd4874 Auto merge of #8703 - aldhsu:add_repeated_where_clause_or_trait_bound, r=flip1995
Add `repeated_where_clause_or_trait_bound` lint

I thought I would try and scratch my own itch for #8674.

1. Is comparing the `Res` the correct way for ensuring we have the same trait?
2. Is there a way to get the spans for the bounds and clauses for suggestions?
I tried to use `GenericParam::bounds_span_for_suggestions` but it only gave me an empty span at the end of the spans.
I tried `WhereClause::span_for_predicates_or_empty_place` and it included the comma.
3. Is there a simpler way to get the trait names? I have used the spans of the traits because I didn't see a way to get it off the `Res` or `Def`.

changelog: Add ``[`repeated_where_clause_or_trait_bound`]`` lint.
2022-07-12 15:48:55 +00:00
Allen Hsu
8878d674b1 Lint for repeated traits within trait bounds or where clauses. 2022-07-12 22:03:55 +10:00
bors
3206fb4eb1 Auto merge of #9138 - Jarcho:branches_sharing_code_2, r=giraffate
Fixes for `branches_sharing_code`

fixes #7198
fixes #7452
fixes #7555
fixes #7589

changelog: Don't suggest moving modifications to locals used in any of the condition expressions in `branches_sharing_code`
changelog: Don't suggest moving anything after a local with a significant drop in `branches_sharing_code`
2022-07-12 00:38:54 +00:00
bors
8a62b6f523 Auto merge of #9144 - alex-semenyuk:or_fun_call_span_fix, r=giraffate
Fix span for or_fun_call

Closes #9033
changelog: [`or_fun_call`]: span points to the `unwrap_or` only instead of through the entire method chain expression
2022-07-11 09:03:20 +00:00
bors
7ea4592a8b Auto merge of #9056 - Jarcho:let_unit_indirect, r=llogiq
Allow `let_unit_value` in more cases

fixes #8998

changelog: Lint `let_unit_value` less aggressively when the type is specified
2022-07-10 18:58:09 +00:00
alex-semenyuk
97cd46fa33 Fix span for or_fun_call 2022-07-10 13:11:19 +03:00
Jason Newcomb
95b78799c3 Ignore the IntoIterator::into_iter call from for loops in significant_drop_in_scrutinee 2022-07-09 08:15:13 -04:00
Jason Newcomb
55563f9ce1 Fixes for branches_sharing_code
* Don't suggest moving modifications to locals used in any of the condition expressions
* Don't suggest moving anything after a local with a significant drop
2022-07-08 20:07:55 -04:00
bors
49f73e14a9 Auto merge of #8356 - J-ZhengLi:master-issue8288, r=dswij
Simplify if let statements

fixes: #8288

---

changelog: Allowing [`qustion_mark`] lint to check `if let` expressions that immediatly return unwrapped value
2022-07-08 16:12:00 +00:00
bors
d0b8f7508c Simplify if let statements
fixes: #8288

---

changelog: Allowing [`qustion_mark`] lint to check `if let` expressions that immediatly return unwrapped value
2022-07-08 16:12:00 +00:00
Matthias Krüger
1e033a9818 Rollup merge of #99026 - anall:buffix/clippy-9131, r=xFrednet
Add test for and fix rust-lang/rust-clippy#9131

This lint seems to have been broken by #98446 -- but of course, there was no clippy test for this case at the time.

`expr.span.ctxt().outer_expn_data()` now has `MacroKind::Derive` instead of `MacroKind::Attr` for something like:

```
#[derive(Clone, Debug)]
pub struct UnderscoreInStruct {
    _foo: u32,
}
```

---

changelog: none

closes: https://github.com/rust-lang/rust-clippy/issues/9131
2022-07-08 08:00:41 +02:00
bors
bee9da14cd Auto merge of #98482 - cjgillot:short-struct-span-closure, r=estebank
Shorten def_span of closures to just their header

Continuation of https://github.com/rust-lang/rust/pull/93967.
2022-07-08 03:05:15 +00:00
Jason Newcomb
9fa12def3c Improve while_let_on_iterator suggestion inside an FnOnce closure 2022-07-07 22:10:24 -04:00
Jason Newcomb
2872b7e0a4 Allow let () = .. as type inference for let_unit_value 2022-07-07 20:06:37 -04:00
Jason Newcomb
196174ddad Changes to let_unit_value
* View through locals in `let_unit_value` when determining if inference is required
* Don't remove typed let bindings for more functions
2022-07-07 20:06:36 -04:00
bors
54feac18d1 Auto merge of #8958 - Alexendoo:simple_filter_map, r=giraffate
Lint simple expressions in `manual_filter_map`, `manual_find_map`

changelog: Lint simple expressions in [`manual_filter_map`], [`manual_find_map`]

The current comparison rules out `.find(|a| a.is_some()).map(|b| b.unwrap())` because `a` being a reference can effect more complicated expressions, this adds a simple check for that case and adds the necessary derefs

There's some overlap with `option_filter_map` so `lint_filter_some_map_unwrap` now returns a `bool` to indicate it linted
2022-07-07 23:39:12 +00:00
Andrea Nall
782b484b79 Fix ICE in sugg::DerefDelegate with (named) closures
rustc comiler internals helpfully tell us how to fix the issue:

  to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`

Fixes ICE in #9041
2022-07-07 16:10:36 -05:00
Andrea Nall
3388787615 Add test for and fix rust-lang/rust-clippy#9131
This lint seems to have been broken by #98446
2022-07-07 19:30:37 +00:00
Dylan DPC
4f9933afbd Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, r=wesleywiser
Finishing touches for `#[expect]` (RFC 2383)

This PR adds documentation and some functionality to rustc's lint passes, to manually fulfill expectations. This is needed for some lints in Clippy. Hopefully, it should be one of the last things before we can move forward with stabilizing this feature.

As part of this PR, I've also updated `clippy::duplicate_mod` to showcase how this new functionality can be used and to ensure that it works correctly.

---

changelog: [`duplicate_mod`]: Fixed lint attribute interaction

r? `@wesleywiser`

cc: https://github.com/rust-lang/rust/issues/97660, https://github.com/rust-lang/rust/issues/85549

And I guess that's it. Here have a magical unicorn 🦄
2022-07-07 18:06:50 +05:30
Alex Macleod
307b8cd825 Lint simple expressions in manual_filter_map, manual_find_map 2022-07-07 11:51:42 +00:00
Marcel Hellwig
ead2c4f122 fix incorrect suggestion for maybe trait bounds 2022-07-07 12:43:16 +02:00
Camille GILLOT
347d999b97 Shorten span for closures. 2022-07-07 09:27:42 +02:00
bors
afb34eb261 Auto merge of #9096 - Jarcho:needless_borrow_subs, r=Manishearth
Fix `needless_borrow` 9095

fixes #9095
changelog: Don't lint `needless_borrow` on method receivers when it would change which trait impl is called
2022-07-06 21:26:46 +00:00
xFrednet
0d443d17eb Fix #[expect] and #[allow] for clippy::duplicate_mod 2022-07-06 22:01:40 +02:00
Takayuki Maeda
e34ee2484b fix miri-opt tests 2022-07-06 19:09:50 +09:00
bors
f93d418f17 Auto merge of #9099 - joshtriplett:unnecessary-lazy-eval-then-some, r=flip1995
Extend unnecessary_lazy_eval to cover `bool::then` -> `bool::then_some`

fixes #9097

changelog: Extend `unnecessary_lazy_eval` to convert `bool::then` to `bool::then_some`
2022-07-06 09:20:55 +00:00
Josh Triplett
528308b5aa Extend unnecessary_lazy_eval to cover bool::then -> bool::then_some 2022-07-06 00:48:51 -07:00
Jason Newcomb
3db0e00bdc Lint shadow_* lints in anon const blocks 2022-07-05 15:21:27 -04:00
bors
462136ac68 Auto merge of #9121 - alex-semenyuk:fix_ui_test_cast_32_bits, r=flip1995
Fix stderr for cast_size_32bit

changelog: fix stderr for cast_size_32bit
2022-07-05 08:57:12 +00:00
alexey semenyuk
2ccb05487c
Fix stderr for cast_size_32bit 2022-07-05 09:43:29 +03:00
bors
48e527e4bd Auto merge of #9117 - Jarcho:unsafe_block_closure, r=giraffate
Fix `undocumented_unsafe_blocks` in closures

fixes #9114
changelog: Fix `undocumented_unsafe_blocks` not checking for comments before the start of a closure
2022-07-05 00:20:33 +00:00
Jason Newcomb
975667945c Fix undocumented_unsafe_blocks in closures 2022-07-04 13:53:42 -04:00
Alex Macleod
fec4593082 new_without_default: ignore const generics/lifetime params on fn new 2022-07-04 14:03:11 +00:00
bors
b15f06e74f Auto merge of #9093 - Jarcho:deref_ice, r=giraffate
Fix ICE in `dereference.rs`

fixes #9089
changelog: Fix ICE when dereferencing or borrowing on explicit returns from closures
2022-07-04 00:22:17 +00:00