Commit Graph

6755 Commits

Author SHA1 Message Date
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
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
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
Jason Newcomb
797d8bff08 Don't lint manual_clamp in const contexts. 2023-03-10 11:07:28 -05: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
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
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
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