Commit graph

6809 commits

Author SHA1 Message Date
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
Pietro Albini
aff9b72375 move clippy tests back to their intended directory 2023-03-08 14:17:16 +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
b4b2b1235a Revert "Dogfood missing_assert_message on Clippy"
This reverts commit ec653570ad50d11ecc3b5649dd28e29ed96199d3.
2023-03-08 08:51:50 +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ı
8f3ac65227 Dogfood missing_assert_message on Clippy
Co-authored-by: Weihang Lo <me@weihanglo.tw>
2023-03-08 08:51:24 +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
d98873497b Auto merge of #10418 - Jarcho:finish_dogfood, r=flip1995
Run dogfood to completion

Run dogfood on all packages before failing the test. Failing early is painful on lints which trigger on multiple crates.

changelog: None
2023-02-28 15:21:32 +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
Jason Newcomb
69a1100776 Run dogfood on all packages before failing 2023-02-28 09:49:54 -05: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
Jason Newcomb
69c4ff6df8 Emit unnecessary_def_path in source order. 2023-02-25 18:09:24 -05:00
Jason Newcomb
e825adf637 Fix normalization of custom_ice_message test. 2023-02-25 18:08:51 -05: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
bors
b528cc90bc Auto merge of #10391 - ldm0:ldm0_fix_unwrap_in_tests, r=xFrednet
Fix test function checker in `unwrap_used`, `expect_used`

After #9686 , `unwrap` and `expect` in integration tests and raw test functions won't be allowed.

fixes #10011
fixes #10238
fixes #10264

---

changelog: Fix: [`expect_used`], [`unwrap_used`], [`dbg_macro`], [`print_stdout`], [`print_stderr`]: No longer lint in test functions, if the related configuration is set
[#10391](https://github.com/rust-lang/rust-clippy/pull/10391)
<!-- changelog_checked -->
2023-02-24 09:24:41 +00: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
Liu Dingming
79a90248c3 bless 2023-02-22 21:49:26 +08:00
Liu Dingming
1a474d9179 Recover tests 2023-02-22 21:36:30 +08: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
bors
b1cf1e7b6a Auto merge of #10303 - pvdrz:pub_crate_missing_docs, r=giraffate
Add configuration to lint missing docs of `pub(crate)` items

Fixes this: https://github.com/rust-lang/rust-clippy/issues/5736#issuecomment-1412442404

TODO:
- [x] Needs docs
- [x] Needs better names
- [x] Should `pub` items be checked to when this new option is enabled? I'm saying no because `missing_docs` already exists

`@flip1995` I'd like to get some input from you :)

---

changelog: Enhancement: [`missing_docs_in_private_items`]: Added new configuration `missing-docs-in-crate-items` to lint on items visible within the current crate. For example, `pub(crate)` items.
[#10303](https://github.com/rust-lang/rust-clippy/pull/10303)
<!-- changelog_checked -->
2023-02-20 23:59:07 +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
Christian Poveda
c29e767ef1
Address review comments 2023-02-17 09:09:44 -05: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
Christian Poveda
64b8aaf91a
remove empty file 2023-02-16 11:45:57 -05: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