Commit graph

5712 commits

Author SHA1 Message Date
bors
8f0ba1f2e0 Auto merge of #10563 - nyurik:handle-all-fmt2, r=llogiq
Partial no-op refactoring of #9948

This contains some prep work for #9948 to keep that change to the minimum, and make it easier to review it.

This should be a noop, but it has some tests from that PR discussion, and should help in the future with the corner case format handling.

cc: `@Alexendoo` `@llogiq` `@xFrednet`  as the 3 people who reviewed the parent PR

----

changelog: none
2023-04-02 17:08:20 +00:00
blyxyas
36047b0216
Fix nonminimal_bool #[allow] attributes. 2023-04-02 16:18:03 +02:00
Caio
05650b7215 [arithmetic_side_effects] Fix #10583 2023-04-02 07:50:25 -03:00
blyxyas
b2856a763e
Add tests_outside_test_module lint 2023-04-02 00:35:46 +02:00
bors
ac4838c554 Auto merge of #10534 - samueltardieu:lines-filter-map-ok, r=llogiq
Flag `bufreader.lines().filter_map(Result::ok)` as suspicious

This lint detects a problem that happened recently in https://github.com/uutils/coreutils and is described in https://github.com/rust-lang/rust/issues/64144.

changelog: [`lines_filter_map_ok`]: new lint
2023-04-01 12:41:08 +00:00
bors
29987062d9 Auto merge of #10536 - mkrasnitski:suggestions, r=flip1995
Add suggestions to `extra_unused_type_parameters`

Change the `extra_unused_type_parameters` lint to provide machine applicable suggestions rather than just help messages. Exception to this are cases when any unused type parameters appear bounded in where clauses - for now I've deemed these cases unfixable and separated them out. Future work might be able to provide suggestions in these cases.

Also, added a test case for the `avoid_breaking_exported_api` config option.

r? `@flip1995`

changelog: [`extra_unused_type_parameters`]: Now provides fixable suggestions.
2023-03-31 16:16:36 +00:00
Samuel "Sam" Tardieu
6601d85c22 Flag bufreader.lines().filter_map(Result::ok) as suspicious 2023-03-31 14:43:30 +02:00
Alex Macleod
17f80456d1 Ignore file!() macro in print_literal, write_literal 2023-03-30 16:20:04 +00:00
bors
799732cbd8 Auto merge of #10414 - csmoe:large-future, r=xFrednet
add large future lint

Closes #5263

---

changelog: new lint: [`large_futures`]
[#10414](https://github.com/rust-lang/rust-clippy/pull/10414)
<!-- changelog_checked -->
2023-03-30 08:51:29 +00:00
bors
ef3867f394 Auto merge of #9102 - botahamec:unused-box, r=xFrednet
Added the `[unnecessary_box_returns]` lint

fixes #5

I'm not confident in the name of this lint. Let me know if you can think of something better

---

changelog: New lint: ``[`unnecessary_box_returns`]``
[#9102](https://github.com/rust-lang/rust-clippy/pull/9102)
<!-- changelog_checked -->
2023-03-30 08:22:16 +00:00
Elliot Bobrow
a2165533e1 fix single_component_path_imports FP 2023-03-29 18:19:29 -07:00
bors
c5011e9d42 Auto merge of #10553 - Nilstrieb:better-uninit, r=Alexendoo
In uninit checking, add fallback for polymorphic types

After #10520, we always assumed that polymorphic types do not allow to be left uninitialized. But we can do better, by peeking into polymorphic types and adding a few special cases for going through tuples, arrays (because the length may be polymorphic) and blanket allowing all unions (like MaybeUninit).

fixes #10551

changelog: [uninit_vec]: fix false positive for polymorphic types
changelog: [uninit_assumed_init]: fix false positive for polymorphic types
2023-03-29 18:26:35 +00:00
Nilstrieb
51b4d2a1e8 In uninit checking, add fallback for polymorphic types 2023-03-29 19:46:44 +02:00
csmoe
4f5a019d6e Update clippy_lints/src/large_futures.rs
Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>
2023-03-29 08:47:32 +00:00
Yuri Astrakhan
783879e6fe Partial no-op refactoring of #9948
This contains preparatory work for #9948 to keep that change to the
minimum, and make it easier to review it.
2023-03-28 21:08:06 -04:00
bors
84e42fb363 Auto merge of #10484 - Alexendoo:format-args-ast-2, r=Manishearth
Migrate `format_args.rs` to `rustc_ast::FormatArgs`

changelog: none

Part of https://github.com/rust-lang/rust-clippy/issues/10233

Empty precision specifiers are no longer linted as the span for that isn't present in [`FormatOptions`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/format/struct.FormatOptions.html)

```rust
format!("{:.}", ...)
```

That could be fixed later with some hackery or a change upstream

r? `@flip1995`
2023-03-28 18:33:02 +00:00
bors
d9821e1d9d Auto merge of #10542 - Alexendoo:items-after-statements, r=giraffate
Fix allow attribute, items from macros in `items_after_statements`

Fixes #10540

changelog: [`items_after_statements`]: Fixes `#[allow(clippy::items_after_statements)]` when applied to an item, and ignores items after statements from different macro contexts
2023-03-28 13:21:14 +00:00
Alex Macleod
3259b48568 Migrate format_args.rs to rustc_ast::FormatArgs
No longer lints empty precisions `{:.}` as the spans aren't available
2023-03-28 12:22:22 +00:00
Jamen Marz
28b80059ed Add notes to non-structural const in pattern error message 2023-03-27 11:08:11 -04:00
bluthej
df65d21f4c Include tests where the iterator is used later 2023-03-27 11:11:40 +02:00
Micha White
76d13bb7fa
Don't lint functions with "box" in their name 2023-03-26 17:49:57 -04:00
Micha White
a143fb7a11
Avoid breaking exported API 2023-03-26 17:49:57 -04:00
Micha White
1b55c81db5
Lint on trait declarations, not implementations 2023-03-26 17:49:56 -04:00
Micha White
022f76d432
Added the new lint with some docs and tests 2023-03-26 17:49:46 -04:00
bluthej
3966580c9d Add tests with usize::MIN 2023-03-26 19:12:37 +02:00
bluthej
ee0de538d4 Add some tests 2023-03-26 19:12:36 +02:00
bluthej
1d168b31c3
Merge branch 'rust-lang:master' into clear-with-drain 2023-03-26 19:11:38 +02:00
bors
5ed64d4c61 Auto merge of #10496 - J-ZhengLi:issue_10366, r=Alexendoo
fix [`cast_possible_truncation`] offering wrong suggestion for casting float to integer

fixes: #10366

---

changelog: [`cast_possible_truncation`] Fix incorrect suggestions when casting from float types or to `_`
2023-03-25 13:11:46 +00:00
bors
f1b9105f87 Auto merge of #10454 - Alexendoo:transmutes-expressible-as-ptr-casts-parens, r=Jarcho
Wrap `transmutes_expressible_as_ptr_casts` suggestions in parentheses

changelog: [`transmutes_expressible_as_ptr_casts`]: Fix suggestion missing wrapping parentheses

Fixes #10449

r? `@Jarcho`

Is this the best way to go about this? `unused_parens` will catch the unnecessary ones but emitting them in the first place isn't ideal
2023-03-25 02:29:54 +00:00
J-ZhengLi
52c4dc65d9 fix [cast_possible_truncation] offering wrong suggestion when casting from float
suggest `try_into` when casting to wildcard type;
fix [`cast_possible_truncation`] suggesting useless parenthesis;

remove suggesting for float to float conversion in [`cast_possible_truncation`]

style nit
2023-03-25 09:26:43 +08:00
Alex Macleod
b13f99c7e7 Fix allow attribute, items from macros in items_after_statements 2023-03-24 15:33:14 +00:00
Philipp Krones
8df896c076 Merge commit 'd5e2a7aca55ed49fc943b7a07a8eba05ab5a0079' into clippyup 2023-03-24 14:26:19 +01:00
Philipp Krones
62cba5d971
Merge remote-tracking branch 'upstream/master' into rustup 2023-03-24 13:36:09 +01:00
Michael Krasnitski
50d92d0b60 Add suggestions to extra_unused_type_parameters 2023-03-23 23:56:31 -04:00
bors
c72c914d21 Auto merge of #10489 - samueltardieu:issue-10476, r=giraffate
New lint: detect unnecessary struct building

Fixes #10476.

Running this lint on the top 500 crates produced one hit (in `rust-lang/rust-bindgen`) and [a PR has been submitted there](https://github.com/rust-lang/rust-bindgen/pull/2440).

changelog: [`unnecessary_struct_initialization`]: new lint
2023-03-24 00:12:02 +00:00
Samuel "Sam" Tardieu
d7d3dbf060 New lint: detect unnecessary struct building 2023-03-23 20:56:45 +01:00
Alex Macleod
ecc201253e Wrap transmutes_expressible_as_ptr_casts suggestions in parentheses 2023-03-23 18:58:10 +00:00
bors
1d1e72308e Auto merge of #10527 - samueltardieu:issue-10523, r=dswij
Do not propose to simplify a not expression coming from a macro

Fixes #10523

changelog: FP [`nonminimal_bool`]: do not propose to change code coming from a macro
2023-03-22 15:46:08 +00:00
bluthej
d56c941792
Merge branch 'rust-lang:master' into clear-with-drain 2023-03-22 11:15:23 +01:00
bluthej
e8ec242a61 Finish tests - add rustfix 2023-03-22 11:01:57 +01:00
bluthej
1d0acce984 Add test for partial range 2023-03-22 11:01:57 +01:00
bluthej
589d7e1ab4 Add tests to cover all cases 2023-03-22 11:01:57 +01:00
bors
583962150b Auto merge of #10490 - samueltardieu:issue-10482, r=xFrednet
Do not propose to remove `async move` if variables are captured by ref

Fixes #10482

changelog: FP [`redundant_async_block`] Do not propose to remove `async move` if variables are captured by ref
2023-03-22 08:19:39 +00:00
Samuel "Sam" Tardieu
b138bb587b Do not propose to simplify a not expression coming from a macro 2023-03-22 01:12:52 +01:00
Samuel "Sam" Tardieu
349708655e Do not propose to remove async move if variables are captured by ref 2023-03-22 00:29:17 +01:00
bluthej
7f44530f54 Create clear_with_drain lint 2023-03-21 22:51:51 +01:00
Nilstrieb
84b6049eb9 Use uninit checking from rustc
rustc has proper heuristics for actually checking whether a type allows
being left uninitialized (by asking CTFE). We can now use this for our
helper instead of rolling our own bad version with false positives.
2023-03-21 18:28:06 +01:00
csmoe
4fdae81c70 add large future lint 2023-03-20 22:51:01 +08:00
bors
e64c5961dc Auto merge of #10456 - samueltardieu:issue-10450, r=Manishearth
Issue function modifiers in the right order in manual_async_fn lint

Fixes #10450

changelog: [`manual_async_fn`] output function modifiers in correct order
2023-03-18 15:19:27 +00:00
bors
d3c8442d4d Auto merge of #10483 - samueltardieu:issue-10480, r=llogiq
New lint to detect `&std::path::MAIN_SEPARATOR.to_string()`

Fixes #10480

changelog: [`manual_main_separator_str`] new lint
2023-03-17 13:49:53 +00:00
bors
5c4040e9bb Auto merge of #10502 - blyxyas:fix-almost_swapped, r=giraffate
fix `almost_swapped`: Ignore external macros

Fixes #10421 ; Related to #10499 (Fixing points *1* and *3* from #10421)
changelog: [`almost_swapped`]: Add a check to ignore external macros
2023-03-17 00:03:45 +00:00
Samuel "Sam" Tardieu
ffabdab8cf New lint to detect &std::path::MAIN_SEPARATOR.to_string() 2023-03-16 21:42:04 +01:00
blyxyas
9546517a84
Add external macro test + Now it works 2023-03-16 20:22:39 +01:00
Samuel Tardieu
afe27ba1a2 Issue function modifiers in the right order in manual_async_fn lint 2023-03-16 18:59:14 +01:00
bors
5afa93bd8e Auto merge of #10481 - blyxyas:allow_attribute, r=xFrednet
Add `allow_attribute` lint

Fixes #10468

changelog: new lint: [`allow_attributes`]
[#10481](https://github.com/rust-lang/rust-clippy/pull/10481)
2023-03-16 10:18:19 +00:00
blyxyas
4b9cb857f9
Rename lint 2023-03-15 23:18:25 +01:00
blyxyas
e2ba75d69d
Add macro test 2023-03-15 16:27:46 +01:00
bors
c465bf7f67 Auto merge of #10499 - blyxyas:fix-almost_swapped, r=giraffate
Fix `almost_swapped` false positive (`let mut a = b; a = a`)

Fixes `2` in #10421
changelog: [`almost_swapped`]: Fix false positive when a variable is changed to itself. (`a = a`)
2023-03-14 13:30:21 +00:00
bors
491f63214a Auto merge of #104833 - Swatinem:async-identity-future, r=compiler-errors
Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes https://github.com/rust-lang/rust/issues/104826.
2023-03-14 10:12:58 +00:00
bors
ff843ac9ae Auto merge of #10350 - J-ZhengLi:issue_10272, r=xFrednet
enhance [`ifs_same_cond`] to warn same immutable method calls as well

fixes: #10272

---

changelog: Enhancement: [`ifs_same_cond`]: Now also detects immutable method calls.
[#10350](https://github.com/rust-lang/rust-clippy/pull/10350)
<!-- changelog_checked -->
2023-03-14 08:16:58 +00:00
blyxyas
6631480a7b
Fix false positive with a = a 2023-03-13 19:13:56 +01:00
Alex Macleod
555f56862e Fix semicolon insertion in match_single_binding 2023-03-13 14:17:35 +00:00
J-ZhengLi
f4ccb06d69 extract is_interior_mutable_type from [mut_key] to clippy_utils::ty;
fix configuration of [`ifs_same_cond`];

add some style improvement for [`ifs_same_cond`];
2023-03-13 20:17:30 +08:00
J-ZhengLi
f0ae2b71ca make [ifs_same_cond] use ignore_interior_mutablility configuration 2023-03-13 20:13:56 +08:00
J-ZhengLi
8a9492aa03 enhance [ifs_same_cond] to lint same immutable method calls as well 2023-03-13 20:13:56 +08:00
bors
ff23e48c30 Auto merge of #108471 - clubby789:unbox-the-syntax, r=Nilstrieb,est31
Remove `box_syntax`

r? `@Nilstrieb`

This removes the feature `box_syntax`, which allows the use of `box <expr>` to create a Box, and finalises removing use of the feature from the compiler. `box_patterns` (allowing the use of `box <pat>` in a pattern) is unaffected.
It also removes `ast::ExprKind::Box` - the only way to create a 'box' expression now is with the rustc-internal `#[rustc_box]` attribute.
As a temporary measure to help users move away, `box <expr>` now parses the inner expression, and emits a `MachineApplicable` lint to replace it with `Box::new`

Closes #49733
2023-03-13 10:41:50 +00:00
bors
e07c6b4899 Auto merge of #108872 - cjgillot:simp-const-prop, r=oli-obk
Strengthen state tracking in const-prop

Some/many of the changes are replicated between both the const-prop lint and the const-prop optimization.

Behaviour changes:
- const-prop opt does not give a span to propagated values. This was useless as that span's primary purpose is to diagnose evaluation failure in codegen.
- we remove the `OnlyPropagateInto` mode. It was only used for function arguments, which are better modeled by a write before entry.
- the tracking of assignments and discriminants make clearer that we do nothing in `NoPropagation` mode or on indirect places.
2023-03-12 23:27:52 +00:00
bors
e65ad6f5d0 Auto merge of #10453 - Jarcho:test_utils, r=dswij
Add utility macros to help with writing tests.

Adds two utility macros to help with testing:
* `external` expands to it's argument tokens, but makes them appear to come from an external macro. Helps make tests for `in_external_macro` much more readable.
* `inline_macros` is an attribute macro which allows the use of a pseudo `inline!` macro which expands to it's argument tokens, but makes them appear to be from a crate-local macro expansion. This removes the need to write `macro_rules` boilerplate when testing how lints interact with macros.

---

`external`'s usage is simple. `external!(struct Foo { x: u32});` will make the struct appear as though it came from an external macro. Individual tokens can be escaped if needed. `external!($x + 0 / 10)` will make everything except `x` appear as though it came from an external macro. Can also use `$literal` and `$(tokens...)` as well.

---

`inline_macros` is more complicated due to compiler constraints. Given:
```rust
#[inline_macros]
fn foo() {
    inline!(5 + 5 / 10);
}
```
`inline!(5 + 5 / 10)` will be replace with a call to a generated macro which expands to the contained tokens.

Tokens can be escaped by prefixing them with `$`:
```rust
#[inline_macros]
fn foo() {
    let x = 5;
    inline!($x + 5 / $10);
}
```
This will pass `x` as an `ident` argument and `10` as a `literal` argument.

Token sequences can also be passed with `$(...)`:
```rust
#[inline_macros]
fn foo() {
    let mut x = 5;
    inline!(if $(x >= 5) {
        $x = 5;
    });
}
```
This will pass `x >= 5` as `tt` arguments, and `x` as an `ident` argument.

---

Not 100% sure `inline_macros` is actually worth having. It does make the tests a little easier to read once you're used to it and it becomes more useful once there are multiple macro tests. The verbosity of declaring single use macros starts to hurt at that point.

changelog: None
2023-03-12 21:36:47 +00:00
Jason Newcomb
1c7048d785 Add utility macros to help with writing tests. 2023-03-12 17:24:36 -04:00
clubby789
213a22efb9 Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
blyxyas
d65c9a5700
Extend tests + improve description + general improvement 2023-03-11 21:30:34 +01:00
bors
f19db28361 Auto merge of #10434 - Jarcho:snip_context, r=dswij
Remove `snippet_with_macro_callsite`

`snippet_with_context` is used instead to support nested macro calls.

changelog: None
2023-03-11 12:45:20 +00:00
bors
e426ba4e06 Auto merge of #10420 - Jarcho:no_mangle_diag, r=dswij
Improve diagnostic of `no_mangle_with_rust_abi`

fixes #10409

Pending rust-lang/rustfmt#5701

This rewords the message to focus on the error being an implicit ABI, rather than the `Rust` ABI. Also downgrades the suggestion to `MaybeIncorrect` and changes the suggestion span to better highlight the change.

---

changelog: None
<!-- changelog_checked -->
2023-03-11 12:14:48 +00:00
blyxyas
0f1474ea27
Add allow_attribute lint 2023-03-11 00:30:30 +01:00
Jason Newcomb
797d8bff08 Don't lint manual_clamp in const contexts. 2023-03-10 11:07:28 -05:00
Philipp Krones
cf8a67d9ad Merge commit '3c06e0b1ce003912f8fe0536d3a7fe22558e38cf' into clippyup 2023-03-10 10:53:50 +01:00
bors
3c06e0b1ce Auto merge of #10275 - Alexendoo:format-args-ast, r=flip1995
Migrate `write.rs` to `rustc_ast::FormatArgs`

changelog: none

Part 1 of #10233

The additions to `clippy_utils` are the main novelty of this PR, there's no removals yet since other parts still rely on `FormatArgsExpn`

The changes to `write.rs` itself are relatively straightforward this time around, as there's no lints in it that rely on type checking format params

r? `@flip1995`
2023-03-10 09:38:18 +00:00
bors
9074da0bd7 Auto merge of #10359 - mladedav:dm/private/is-empty, r=llogiq
Include async functions in the len_without_is_empty

fixes #7232

Changes done to the functionality:

Allowing different error types for the functions was disallowed. So the following was linted before but is not after this change
```
impl Foo {
    pub len(&self) -> Result<usize, Error1> { todo!(); }
    pub is_empty(&self) -> Result<bool, Error2> { todo!(); }
}
```

---

changelog: Enhancement: [`len_without_is_empty`]: Now also detects `async` functions
[#10359](https://github.com/rust-lang/rust-clippy/pull/10359)
<!-- changelog_checked -->
2023-03-09 17:15:23 +00:00
bors
5f9873497f Auto merge of #10467 - blyxyas:underscore_typed, r=Jarcho
Add `let_with_type_underscore` lint

Fixes #10463
changelog: [`let_with_type_underscore`]: Add the lint.
2023-03-09 16:35:30 +00:00
blyxyas
ca3bf94c43
Add let_with_type_underscore lint 2023-03-09 17:18:03 +01:00
bors
ea4ebed2ed Auto merge of #10309 - c410-f3r:arith, r=giraffate
[arithmetic_side_effects] Fix #10252

Fix #10252

At least for integers, shifts are already handled by the compiler.

----

changelog: [`arithmetic_side_effects`]: No longer lints on right or left shifts with constant integers, as the compiler warns about them.
[#10309](https://github.com/rust-lang/rust-clippy/pull/10309)
<!-- changelog_checked-->
2023-03-09 13:30:11 +00:00
Camille GILLOT
e66e918bd3 Fortify clippy tests. 2023-03-08 14:40:38 +00:00
Arpad Borsos
90afb207eb Remove identity_future indirection
This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]` annotation.
2023-03-08 15:37:14 +01:00
Samuel Tardieu
d5429eab8a Add new redundant_async_block lint 2023-03-08 10:48:54 +01:00
unexge
e7065efc76 Revert tests/ui/filter_map_next_fixable.rs
Co-authored-by: Weihang Lo <me@weihanglo.tw>
2023-03-08 08:51:52 +00:00
unexge
4eb6ccc973 Update lint description and add help section
Co-authored-by: Weihang Lo <me@weihanglo.tw>
2023-03-08 08:51:26 +00:00
Burak Varlı
ea2547b8c6 Add missing_assert_message lint
Co-authored-by: Weihang Lo <me@weihanglo.tw>
2023-03-08 08:50:21 +00:00
David Mládek
536905278f Include async functions in the len_without_is_empty
Co-authored-by: Akshay <nerdy@peppe.rs>
2023-03-07 22:04:11 +01:00
bors
41fa24cef8 Auto merge of #10415 - schubart:collection_is_never_read, r=llogiq
Add `collection_is_never_read`

Fixes #9267

`@flip1995` and `@llogiq,` I talked with you about this one at Rust Nation in London last week. :-)

This is my first contribution to Clippy, so lots of feedback would be greatly appreciated.

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

`dogfood` found one true positive (see #9509) and no false positives.

`lintcheck` found no (true or false) positives, even when running on an extended set of crates.

---

changelog: new lint [`collection_is_never_read`]
[#10415](https://github.com/rust-lang/rust-clippy/pull/10415)
<!-- changelog_checked -->
2023-03-07 13:35:07 +00:00
Michael Schubart
4ee65535a7 Add test where container is passed to a function 2023-03-06 22:19:34 +00:00
Alex Macleod
fa0c3cce51 Move test for 10148 to tests/ui/crashes 2023-03-06 21:54:40 +00:00
Michael Schubart
85ad8a6fdc Avoid false positives from extension traits 2023-03-06 07:19:09 +00:00
bors
783bc621a1 Auto merge of #10438 - Jarcho:use_snip_ctxt, r=dswij
Use `snippet_with_context` more

No tests at the moment. Need to find a way to write macro tests without writing a pile of macros.

changelog: None
2023-03-05 15:24:36 +00:00
bors
70e85d146f Auto merge of #10403 - smoelius:fix-107877, r=Jarcho
Fix rust-lang/rust#107877, etc.

Fix #10009
Fix #10387
Fix https://github.com/rust-lang/rust/issues/107877

The fix is to verify that the associated item's trait is implemented before trying to project the item's type.

r? `@Jarcho`

---

changelog: ICE: [`needless_borrow`]: No longer panics on ambiguous projections
[#10403](https://github.com/rust-lang/rust-clippy/pull/10403)
<!-- changelog_checked -->
2023-03-05 01:15:46 +00:00
Samuel Moelius
f95d9deafd Handle ambiguous projections 2023-03-04 19:03:40 -05:00
bors
2500f960fc Auto merge of #10439 - giraffate:fix_fp_for_let_unit_value, r=Jarcho
Fix FP for `let_unit_value` when `await` used

Fix https://github.com/rust-lang/rust-clippy/issues/10433

changelog: Fix FP for `let_unit_value` when `await` used
2023-03-04 19:42:26 +00:00
Takayuki Nakata
027f19c8b9 Fix FP for let_unit_value when await used 2023-03-03 22:41:39 +09:00
Jason Newcomb
efbcb99b73 Use snippet_with_context more 2023-03-03 00:55:53 -05:00
Alex Macleod
64b54ef950 Fix array-size-threshold config deserialization error 2023-03-02 21:42:11 +01:00
Jason Newcomb
1a81a3e5cf Remove snippet_with_macro_callsite 2023-03-02 00:51:04 -05:00
Michael Schubart
fbb7fd59c3 Add test for an interesting edge case 2023-02-28 22:09:04 +00:00
Michael Schubart
cb3bb8a5b5 Add tests that show: insert() can be a read or not 2023-02-28 22:09:04 +00:00
bors
ba86a99d24 Auto merge of #10324 - andrewbanchich:fix-missing-private-docs, r=dswij
Scope `missing_docs_in_private_items` to only private items

`missing_docs_in_private_items` currently detects missing docs for public items as well as private. Since `missing_docs`already covers public items, this PR updates `missing_docs_in_private_items` to only cover private items.

Fixes #1895

changelog: [`missing_docs_in_private_items`]: Apply lint only to private items (used to be public and private)
2023-02-28 16:30:49 +00:00
bors
1a11ad7390 Auto merge of #10405 - Jarcho:issue_10367, r=flip1995
Fix ICE in `multiple_unsafe_ops_per_block`

fixes #10367

changelog: [`multiple_unsafe_ops_per_block`]: Fix ICE when calling a function-like object in an unsafe block
2023-02-28 15:08:34 +00:00
Alex Macleod
2cadea5dc5 Fix array-size-threshold config deserialization error 2023-02-28 14:37:41 +00:00
Jason Newcomb
003a2119e7 Improve diagnostic of no_mangle_with_rust_abi 2023-02-27 22:06:36 -05:00
Andreas Deininger
03a3f74365 Fixing typos 2023-02-27 21:45:26 +01:00
bors
2742ac0748 Auto merge of #10399 - samueltardieu:issue-10396, r=Manishearth
Do not suggest to derive `Default` on generics with implicit arguments

Fixes #10396

changelog: FP: [`derivable_impls`]: do not suggest to derive `Default` on generics with implicit arguments
2023-02-27 17:12:43 +00:00
Michael Schubart
2a9c254e23 Add collection_is_never_read 2023-02-27 07:14:55 +00:00
Samuel Tardieu
c82ff00539 Do not suggest to derive Default on generics with implicit arguments 2023-02-26 15:44:04 +01:00
Jason Newcomb
002e934189 Don't assume paths work with fn_sig in multiple_unsafe_ops_pre_block. 2023-02-26 02:55:52 -05:00
bors
3d193fa17a Auto merge of #10400 - calebcartwright:rustfmt-cleanup, r=Jarcho
chore: remove unneeded rustfmt skip

---

The associated rustfmt bug that originally necessitated these skips was resolved a while back, so these are no longer necessary

changelog: none
2023-02-26 03:03:01 +00:00
bors
e1ac1332b6 Auto merge of #10375 - samueltardieu:issue-10371, r=Manishearth
Do not suggest using Self in const generic parameters

Fixes #10371

changelog: FP: [`use_self`]: do not suggest using `Self` in const generic parameters
2023-02-26 00:52:55 +00:00
Jason Newcomb
0413fb35ba Merge commit '149392b0baa4730c68f3c3eadf5c6ed7b16b85a4' into clippyup 2023-02-25 19:28:50 -05:00
Andrew Banchich
49a06ed66f Scope missing_docs_in_private_items to only private items 2023-02-25 19:16:53 -05:00
bors
149392b0ba Auto merge of #10402 - Jarcho:rustup, r=Jarcho
Rustup

Looks like `@flip1995`  is busy.

r? `@ghost`

changelog: None
2023-02-25 23:34:06 +00:00
Samuel Tardieu
64775f30c2 Do not panic when analyzing the malformed origin of a format string 2023-02-25 23:48:17 +01:00
Jason Newcomb
bc184e9c7d Merge branch 'master' into rustup 2023-02-25 17:43:19 -05:00
Caleb Cartwright
730fa93634 chore: remove unneeded rustfmt skip 2023-02-25 12:34:05 -06:00
Krishna Sundarram
00c294ad05 Add new lint no_mangle_with_rust_abi 2023-02-23 17:35:06 +00:00
Michael Krasnitski
528bb639d4 Fix more false positives for extra_unused_type_parameters 2023-02-23 10:12:02 -05:00
Michael Howell
d254516be1 clippy: update clippy to use new TyCtxt::def_descr 2023-02-22 08:40:47 -07:00
bors
51668820f4 Auto merge of #10386 - Jarcho:issue_10384, r=Manishearth
Normalize projections types when checking `explicit_auto_deref`

fixes #10384

changelog: [`explicit_auto_deref`]: Better consider projection types when checking if auto deref is applicable
2023-02-21 21:27:41 +00:00
Jason Newcomb
0aad34e43f Normalize projections types when checking explicit_auto_deref 2023-02-21 15:59:06 -05:00
bors
803ce88477 Auto merge of #10380 - Alexendoo:needless-lifetime-macro-expansion, r=xFrednet
Ignore lifetimes from differing contexts in `needless_lifetimes`

Fixes #10379

changelog: [`needless_lifetimes`]: Don't lint signatures in macros if the lifetime is a metavariable
2023-02-21 20:47:30 +00:00
bors
5ef3cc8ca1 Auto merge of #10197 - blyxyas:impl_trait_param, r=Jarcho
Add `impl_trait_in_params` lint

As this is a lint about style, and using `impl Trait` is purely cosmetical (even with downsides), a lot of unrelated files needed to allow this lint.

---

Resolves #10030

changelog: New lint: [`impl_trait_in_params`]
[10197](https://github.com/rust-lang/rust-clippy/pull/10197)
<!-- changelog_checked -->
2023-02-21 03:02:48 +00:00
Samuel Tardieu
92c403c9b0 Box::default(): do not omit the type of the removed trait object
Within a larger expression, when the type of `Box::new(T::default())` is
`Box<dyn Trait>`, the concrete type `T` cannot be omitted in the
proposed replacement `Box::<T>::default()`.
2023-02-20 11:58:27 +01:00
Alex Macleod
09058388de Ignore lifetimes from differing contexts in needless_lifetimes 2023-02-20 09:54:53 +00:00
Samuel Tardieu
f531abcef5 Do not suggest using Self in const generic parameters 2023-02-19 11:59:02 +01:00
blyxyas
89fde4abf2
Add placeholders, remove name suggesting 2023-02-18 20:05:30 +01:00
Caio
7518969501 Evaluate the return expression of a block 2023-02-18 09:14:41 -03:00
bors
e1da00210a Auto merge of #10363 - c410-f3r:lock-1, r=xFrednet
[significant_drop_tightening] Ignore inexpensive statements

Not all statements that follow the last use of a lock guard are expensive and can therefore be ignored by the lint.

```rust
pub fn foo() -> i32 {
    let mutex = Mutex::new(1);
    let lock = mutex.lock().unwrap();
    let rslt = *lock;
    let another = rslt;
   another
}
```

---

changelog: [`significant_drop_tightening`]: No longer lints for inexpensive statements after the lock guard
[#10363](https://github.com/rust-lang/rust-clippy/pull/10363)
<!-- changelog_checked -->
2023-02-18 10:25:15 +00:00
Caio
747f81ecd0 [significant_drop_tightening] Ignore inexpensive statements 2023-02-16 18:34:33 -03:00
bors
6444621c10 Auto merge of #10336 - samueltardieu:issue-10241, r=llogiq
manual_let_else: do not suggest semantically different replacements

The problem is that this lint does not consider the possibility that the divergent branch can come first and that the patterns may overlap. This led to incorrect suggestions, previously registered as correct in the tests themselves:

```rust
let v = match build_enum() {
    _ => continue,
    Variant::Bar(v) | Variant::Baz(v) => v,
};
```

had a `let Variant::Bar(v) | Variant::Baz(v) = v else { continue; }` suggestion, which is obviously wrong as the original code `continue`s in any case. Issue #10241 gives another example.

The code now checks that the divergent branch comes second. It could be extended later (I've added a TODO) to check for non-overlapping patterns.

Fixes #10241.

changelog: [`manual_let_else`] do not suggest non equivalent replacements in `match`
2023-02-16 20:30:42 +00:00
bors
eac0bd9da3 Auto merge of #10361 - nindalf:nth_bytes_copy, r=llogiq
Stop bytes_nth from suggesting code that does not compile

Fixes #10151

As discussed in the issue, this PR changes the lint in 2 ways

1. Replace `bytes().nth(n).unwrap()` with `as_bytes()[n]`
2. Replace other `bytes().nth(n)` with `as_bytes().get(n).copied()`

---

changelog: Stop bytes_nth from suggesting code that does not compile in some cases
2023-02-16 17:25:25 +00:00
bors
be7477381b Auto merge of #10357 - nindalf:doc_markdown_relax, r=llogiq
Stop doc_markdown requiring backticks on links to external websites

Fixes #10302

This lint currently checks that any link should be enclosed with `backticks` if the title looks like a lang item. This PR changes the lint to only run on internal links. External links, indicated by `http` or `https`, are skipped.

This PR also reorganises `pulldown_cmark` imports to bypass the clippy lint enforcing 100 line functions.

---

changelog: Stop doc_markdown requiring backticks on links to external websites
2023-02-16 17:09:18 +00:00
Krishna Sundarram
7e53e27dfd Stop bytes_nth from suggesting code that does not compile 2023-02-16 17:05:21 +00:00
Jirka Vebr
6d0df84f6f
Add the transmute_int_to_non_zero lint 2023-02-16 16:58:05 +01:00
Krishna Sundarram
9c9dbc2408 Fix DOC_MARKDOWN requiring backticks on links to external websites 2023-02-16 14:47:30 +00:00
bors
52c8b536c9 Auto merge of #10342 - mitsuhiko:feature/question-mark-used, r=Alexendoo
Add question-mark-used lint

This lint complains when the question mark operator (try operator) is used.  This is a restriction lint that can be useful on local scopes where a custom error handling macro is supposed to be used to augment the error based on local scope data before returning.

Fixes #10340

---

changelog: New lint [`question_mark_used`]
[#10342](https://github.com/rust-lang/rust-clippy/pull/10342)
<!-- changelog_checked -->
2023-02-16 14:21:43 +00:00
bors
99d4ea4f39 Auto merge of #10356 - JirkaVebr:let_underscore_untyped, r=llogiq
Add `let_underscore_untyped`

Fixes #6842

This adds a new pedantic `let_underscore_untyped` lint which checks for `let _ = <expr>`, and suggests to either provide a type annotation, or to remove the `let` keyword. That way the author is forced to specify the type they intended to ignore, and thus get forced to re-visit the decision should the type of `<expr>` change. Alternatively, they can drop the `let` keyword to truly just ignore the value no matter what.

r? `@llogiq`

changelog: New lint: [let_underscore_untyped]
2023-02-16 12:58:43 +00:00
bors
4369a67a9b Auto merge of #10163 - c410-f3r:lock-1, r=llogiq
[significant_drop_tightening] Add MVP

cc #9399

Creates the lint with minimum functionalities, which is a good start IMO.

---

changelog: new lint: [`significant_drop_tightening`]
[#10163](https://github.com/rust-lang/rust-clippy/pull/10163)
<!-- changelog_checked -->
2023-02-16 12:30:26 +00:00
Jirka Vebr
2d4d39de53
Add the let_underscore_untyped lint 2023-02-16 13:05:33 +01:00
Krishna Sundarram
f12b492ee0 Change unusual_byte_groupings to require byte groupings of equal size 2023-02-16 11:31:42 +00:00
blyxyas
4166b7dcfe
Fix lint message 2023-02-15 21:34:49 +01:00
blyxyas
6aa06b757d
Remove #[allow]s. Apply conversations from @Jarcho 2023-02-15 21:34:48 +01:00
blyxyas
bdf4fd3e82
Tests pass 2023-02-15 21:34:48 +01:00
blyxyas
6c9983b936
Exec cargo dev update_lints 2023-02-15 21:34:47 +01:00
blyxyas
ade4c9b2b6
Rename lint to better fit lint naming conventions 2023-02-15 21:34:47 +01:00
blyxyas
8ec9543f13
Add impl_trait_param lint
As this is a lint about "style", and a purely cosmetical choice (using `<A: Trait>` over `impl Trait`), a lot of other files needed to be allowed this lint.
2023-02-15 21:29:58 +01:00
Michael Krasnitski
1ee4651ca1 Ignore synthetic type parameters for extra_unused_type_parameters 2023-02-15 10:01:33 -05:00
bors
595f783f22 Auto merge of #10321 - mkrasnitski:false-positives, r=flip1995
Fix false positives for `extra_unused_type_parameters`

Don't lint external macros. Also, if the function body is empty, any type parameters with bounds on them are not linted. Note that only the body needs be empty - this rule still applies if the function takes any arguments.

fixes #10318
fixes #10319
changelog: none
<!-- changelog_checked -->
2023-02-15 14:37:16 +00:00
bors
8754d5a6fb Auto merge of #10343 - samueltardieu:issue-10339, r=Alexendoo
uninlined_format_args: do not inline argument with generic parameters

Fix #10339

---

changelog: FP: [`uninlined_format_args`]: No longer lints for arguments with generic parameters
[#10343](https://github.com/rust-lang/rust-clippy/pull/10343)
<!-- changelog_checked -->
2023-02-15 13:35:49 +00:00
bors
d3d235dcbf Auto merge of #10345 - J-ZhengLi:issue_10049, r=xFrednet
fix [`needless_return`] incorrect suggestion when returning if sequence

fixes: #10049

---

changelog: [`needless_return`]: fix incorrect suggestion  on if sequence
2023-02-15 10:27:46 +00:00
Samuel Tardieu
75aa2b9ec8 uninlined_format_args: do not inline argument with generic parameters 2023-02-15 08:49:43 +01:00
bors
e018a2c8bd Auto merge of #10328 - compiler-errors:fix-re-erased-in-needless_pass_by_value, r=matthiaskrgr
Liberate late-bound regions rather than erasing them in `needless_pass_by_value`

changelog: [`needless_pass_by_value`]: fixes an ICE when there are late-bound regions in function arguments that are needlessly passed by value

Fixes rust-lang/rust#107147
r? `@matthiaskrgr`
2023-02-15 06:41:35 +00:00
J-ZhengLi
8b93eb8a9b add some adjustment regarding review suggestion 2023-02-15 11:26:30 +08:00
Samuel Tardieu
7f15a11aa1 manual_let_else: let/else is not divergent by default
The divergent `else` block of a `let`/`else` statement does not make
the `let`/`else` statement itself divergent.
2023-02-15 00:47:43 +01:00
Michael Goulet
17cb2e47e5 Liberate late-bound regions rather than erasing them in needless_pass_by_value 2023-02-14 23:27:46 +00:00
bors
0e40f94a86 Auto merge of #10346 - samueltardieu:issue-10331, r=Manishearth
Do not base map_entry lint suggestion on expanded code

Fixes #10331

changelog: [`map_entry`]: do not base suggestion on code expanded by the compiler
2023-02-14 23:21:08 +00:00
Samuel Tardieu
e4e5924b99 Do not base map_entry lint suggestion on expanded code 2023-02-14 15:37:48 +01:00
Samuel Tardieu
657ee48bec Ignore instructions following a break from block in never_loop lint
It is not sufficient to ignore break from a block inside the loop.
Instructions after the break must be ignored, as they are unreachable.
This is also true for all instructions in outer blocks and loops
until the right block is reached.
2023-02-14 09:55:44 +01:00
Samuel Tardieu
e9dffa3910 Fix a bug in never_loop when anonymous blocks are nested in named blocks
The following code

```
loop {
    'a: {
        { }
        break 'a;
    }
}
```

was detected as a never-looping loop.
2023-02-14 09:23:04 +01:00
J-ZhengLi
8e96adedd5 fix [needless_return] incorrect suggestion when returning if sequence 2023-02-14 11:31:42 +08:00
Armin Ronacher
89314a0805 Add question-mark-used lint
This lint complains when the question mark operator (try operator)
is used.  This is a restriction lint that can be useful on local
scopes where a custom error handling macro is supposed to be used
to augment the error based on local scope data before returning.
2023-02-13 20:59:26 +01:00
bors
ac60dcaa25 Auto merge of #10177 - chansuke:almost_swapped, r=Alexendoo
Almost swapped

Take over from https://github.com/rust-lang/rust-clippy/pull/8945

Fix https://github.com/rust-lang/rust-clippy/issues/8151

---

changelog: enhancement: [`almost_swapped`]: Now detects almost swaps using `let` statements
[#10177](https://github.com/rust-lang/rust-clippy/pull/10177)
<!-- changelog_checked -->
2023-02-13 13:20:18 +00:00
chansuke
ebca1b5d00 Refactor almost_swapped to lint with let statement correctly 2023-02-13 16:16:31 +09:00
bors
298f139798 Auto merge of #10317 - m-ou-se:suspicious-command-arg-space, r=Manishearth
Add `suspicious_command_arg_space` lint

Fixes #10316

---

changelog: New lint: [`suspicious_command_arg_space`]
[#10317](https://github.com/rust-lang/rust-clippy/pull/10317)
<!-- changelog_checked -->
2023-02-12 21:57:49 +00:00
Caio
c43937316a [arithmetic_side_effects] Fix #10252 2023-02-12 17:34:07 -03:00
bors
6f353fdf0a Auto merge of #10310 - c410-f3r:arith-2, r=Alexendoo
[arithmetic_side_effects] Fix #10209

Fix #10209

---

changelog: Enhancement: [`arithmetic_side_effects`]: No longer lints, if safe constant values are used.
[#10310](https://github.com/rust-lang/rust-clippy/pull/10310)
<!-- changelog_checked -->
2023-02-12 19:34:15 +00:00
Caio
e70a7a68bd [arithmetic_side_effects] Evaluate integers originated from constant declarations 2023-02-12 16:19:51 -03:00
Samuel Tardieu
09d3097734 manual_let_else: do not suggest semantically different replacements 2023-02-12 20:07:23 +01:00
Samuel Tardieu
d9dc1679f5 cast_possible_truncation: issue proper help message 2023-02-12 08:56:21 +01:00
Michael Krasnitski
8789b37d06 Fix false positives for extra_unused_type_parameters 2023-02-11 12:22:25 -05:00
Mara Bos
805a0ae2df Add more test cases for suspicious_command_arg_space. 2023-02-10 22:35:23 +01:00
Caio
078f149aa4 [significant_drop_tightening] Add MVP 2023-02-10 15:07:34 -03:00
Mara Bos
5fefe8b317 Add test. 2023-02-10 19:02:39 +01:00
Philipp Krones
e7fe1f9c14 Merge commit '0f7558148c22e53cd4608773b56cdfa50dcdeac3' into clippyup 2023-02-10 14:01:19 +01:00
Philipp Krones
7c61b4ed89
Merge remote-tracking branch 'upstream/master' into rustup 2023-02-10 11:33:45 +01:00
DevAccentor
179c037643 improve almost swap to look for let statement 2023-02-10 18:00:46 +09:00
bors
fd2d8beaf8 Auto merge of #10293 - Alexendoo:bool-assert-comparison-negation, r=dswij
Negate suggestions when needed in `bool_assert_comparison`

changelog: none assuming this gets into the same release as #10218

Fixes #10291

r? `@dswij`

Thanks to `@black-puppydog` for spotting it early
2023-02-08 23:03:32 +00:00
Kartavya Vashishtha
b7c38981ff
bless new output 2023-02-07 15:39:19 +05:30
Kartavya Vashishtha
46edafe8c1
blessed stderr output 2023-02-05 01:18:29 +05:30
Alex Macleod
5546c82051 Negate suggestions when needed in bool_assert_comparison 2023-02-04 19:28:11 +00:00
Michael Krasnitski
fba16e2e3a Add extra_unused_type_parameters lint 2023-02-02 19:37:34 -05:00
bors
006a4cc767 Auto merge of #10276 - m-ou-se:manual-assert, r=Alexendoo
Don't depend on FormatArgsExpn in ManualAssert.

Part of https://github.com/rust-lang/rust-clippy/issues/10233

changelog: none
2023-02-02 14:47:43 +00:00
Mara Bos
ecd98bad45 Bless tests. 2023-02-01 22:51:02 +01:00
bors
a2f85deba3 Auto merge of #10250 - tylerjw:issue_7419, r=xFrednet
wildcard_enum_match_arm lint takes the enum origin into account

fixes #7419

---

changelog: Enhancement: [`wildcard_enum_match_arm`]: Now lints missing private variants, for local enums
[#10250](https://github.com/rust-lang/rust-clippy/pull/10250)
<!-- changelog_checked -->
2023-02-01 20:01:56 +00:00
koka
07c8c50a41
Avoid renaming for TupleStruct with multiple arguments
update spec

fix: move specs in fire
2023-02-01 22:10:19 +09:00
koka
a408e76098
Suggest the correct variable name for manual_let_else 2023-02-01 19:17:39 +09:00
Alex Macleod
6a8b20230b Add machine applicable suggestion for needless_lifetimes
Also adds a test for #5787
2023-01-31 14:12:03 +00:00
bors
d227f18c2e Auto merge of #10225 - evantypanski:et/issue10132, r=flip1995
[`unused_io_amount`]: Lint with `is_ok` and `is_err`

Fixes #10132

changelog: Apply [`unused_io_amount`] lint to `is_ok` and `is_err` without checking read/write amount
2023-01-31 08:20:21 +00:00
Tyler Weaver
2432e97d6a
wildcard_enum_match_arm lint takes the enum origin into account
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-30 17:29:29 -07:00
Tyler Weaver
4fde96c30e
Test needless_lifetimes within external macro
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-30 16:16:53 -07:00
Tyler Weaver
c959813bfd
needless_lifetimes: macro test
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
2023-01-30 16:04:31 -07:00
Esteban Küber
821199c885 Modify primary span label for E0308
The previous output was unintuitive to users.
2023-01-30 20:12:19 +00:00
bors
d020fd7fe6 Auto merge of #10260 - Niki4tap:external_macro_fp, r=xFrednet
`multiple_unsafe_ops_per_block`: Don't lint in external macros

Fixes #10259

changelog: FP: [`multiple_unsafe_ops_per_block`]: No longer lints in external macros
[#10260](https://github.com/rust-lang/rust-clippy/pull/10260)
<!-- changelog_none -->
2023-01-30 20:10:19 +00:00
bors
173fac0989 Auto merge of #10255 - khayyamsaleem:issue_9520, r=Jarcho
prevents `len_without_is_empty` from yielding positive when `len` takes arguments besides `&self`

Fixes #9520

---

changelog: FP [`len_without_is_empty`]: No longer lints, if `len` as a non-default signature
[#10255](https://github.com/rust-lang/rust-clippy/pull/10255)
<!-- changelog_checked -->
2023-01-30 19:08:04 +00:00
Niki4tap
926c5e4cde multiple_unsafe_ops_per_block: don't lint in external macros 2023-01-30 20:42:40 +03:00
Tyler Weaver
5ed191de6b
bless 2023-01-30 10:10:52 -07:00