Commit Graph

18013 Commits

Author SHA1 Message Date
Alex Macleod
39f7f695da Add msrv test template for cargo dev new_lint --msrv 2023-09-23 18:12:20 +00:00
bors
d732cce0d3 Auto merge of #11553 - mickvangelderen:fix-large-futures-example, r=xFrednet
Fix large_futures example

The value used in the large_futures example was not large enough to trigger the lint given the default threshold. The example also contained more code than necessary. This PR changes the value size from 1kB to 16kB and reduces the example in size.

changelog: [`large_futures`]: Fix and simplify example
2023-09-22 21:19:28 +00:00
bors
50139e6ad2 Auto merge of #11551 - Meczka:fix-fp-needless-pass-by-ref-mut, r=xFrednet
fixed fp caused by moving &mut reference inside of a closure

changelog: [`needless_pass_by_ref mut`]: fixes false positive caused by not covering mutable references passed to a closure inside of a fuction
fixes #11545
2023-09-22 21:07:46 +00:00
Mick van Gelderen
7e46fb9a65
Fix large_futures example
The value used in the large_futures example was not large enough to
trigger the lint given the default threshold.

The example also contained more code than necessary.

This PR changes the value size from 1kB to 16kB and reduces the example
in size.
2023-09-22 19:41:00 +02:00
pc-linux
ab51f66ec0 added tests 2023-09-22 18:04:57 +02:00
pc-linux
85801f55ef fixed fp caused by moving &mut reference inside of a closure 2023-09-22 16:54:21 +02:00
bors
33f084ef78 Auto merge of #11544 - Alexendoo:hir-ty-to-ty, r=Jarcho
Remove most usage of `hir_ty_to_ty`

Removes the usages where there's a suitable query or the type was already available elsewhere. The remaining cases would all require more involved changes

changelog: none

r? `@Jarcho`
2023-09-21 15:25:36 +00:00
bors
4d143d7e16 Auto merge of #11518 - mojave2:issue-11420, r=Alexendoo
fix FP with needless_raw_string_hashes

changelog: Fix [`needless_raw_string_hashes`]: Continue the lint checking of raw string when `needless_raw_strings` is allowed.

fix #11420
2023-09-21 12:27:24 +00:00
bors
c55669513a Auto merge of #11522 - y21:redundant_guards_pat_lhs, r=giraffate
[`redundant_guards`]: lint if the pattern is on the left side

A tiny improvement to the `redundant_guards` lint. There's no associated issue for this, just noticed it while going through the code.
Right now it warns on `Some(x) if x == 2` and suggests `Some(2)`, but it didn't do that for `Some(x) if 2 == x` (i.e. when the local is on the right side and the pattern on the left side).

changelog: [`redundant_guards`]: also lint if the pattern is on the left side
2023-09-20 23:57:25 +00:00
Alex Macleod
01c25a8eb6 Remove most usage of hir_ty_to_ty 2023-09-20 14:05:00 +00:00
bors
ddbe110081 Auto merge of #11170 - tgross35:undocumented-unsafe-blocks-defaults, r=Centri3
Change defaults of `accept-comment-above-statement` and `accept-comment-above-attributes`

This patch sets the two configuration options for `undocumented_unsafe_blocks` to `true` by default: these are `accept-comment-above-statement` and `accept-comment-above-attributes`. Having these values `false` by default prevents what many users would consider clean code, e.g. placing the `// SAFETY:` comment above a single-line functino call, rather than directly next to the argument.

This was originally discussed in https://github.com/rust-lang/rust-clippy/issues/11162

changelog: [`undocumented_unsafe_blocks`]: set
`accept-comment-above-statement` and `accept-comment-above-attributes` to `true` by default.
2023-09-20 08:06:54 +00:00
bors
ece3878c8c Auto merge of #11492 - GuillaumeGomez:async-fn-returned-closure, r=Centri3
Fix mutaby used async function argument in closure for `needless_pass_by_ref_mut`

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

The problem was that it needed to go through closures as well in async functions to correctly find the mutable usage of async function arguments.

changelog: Correctly handle mutable usage of async function arguments in closures.

r? `@Centri3`
2023-09-20 07:48:54 +00:00
Trevor Gross
1b3e5dd0fc Change default configuration of undocumented_unsafe_blocks
This patch sets the two configuration options for
`undocumented_unsafe_blocks` to `true` by default: these are
`accept-comment-above-statement` and `accept-comment-above-attributes`.
Having these values `false` by default prevents what many users would
consider clean code, e.g. placing the `// SAFETY:` comment above a
single-line functino call, rather than directly next to the argument.

changelog: [`undocumented_unsafe_blocks`]: set
`accept-comment-above-statement` and `accept-comment-above-attributes`
to `true` by default.
2023-09-20 03:41:33 -04:00
bors
f464149b8f Auto merge of #11516 - mojave2:issue-11458, r=giraffate
fix cast_lossless with macro call

changelog: fix [`cast_lossless`] in the case when the cast operand is a macro call

fix #11458
2023-09-20 00:00:06 +00:00
bors
889e1b99bd Auto merge of #11530 - Alexendoo:zero-ptr-file-location, r=blyxyas
Move zero_ptr to the casts module

Also a bit of a touch up to the code while I was there

changelog: none
2023-09-18 22:19:59 +00:00
bors
5cba09c576 Auto merge of #11526 - Dev380:redundant-as-str, r=Manishearth
Add redundant_as_str lint

This lint checks for `as_str` on a `String` immediately followed by `as_bytes` or `is_empty` as those methods are available on `String` too. This could possibly also be extended to `&[u8]` in the future.

changelog: New lint [`redundant_as_str`] #11526
2023-09-18 21:31:48 +00:00
Dev381
d9d25e98fc Fix redundant_as_str .fixed file not being consistent 2023-09-18 16:46:00 -04:00
Dev381
17d174d113 Reformat redundant_as_str ui test 2023-09-18 16:39:09 -04:00
Dev381
5224853434 Remove periods from end of sentences in redundant_as_str comments 2023-09-18 16:37:27 -04:00
Dev381
367ba9cd00 Add not redundant examples for redundant_as_str 2023-09-18 16:36:10 -04:00
Dev381
00ca47b97d Add more examples and comments to redundant_as_str test 2023-09-18 16:32:22 -04:00
Dev381
f2ab16eac1 Add not triggering examples to redundant_as_str test 2023-09-18 16:08:02 -04:00
bors
4022591cfd Auto merge of #11517 - mojave2:issue-11426, r=Alexendoo
fix ICE by `u64::try_from(<u128>)`

changelog: Fix the ICE in [`cast_possible_truncation`], when the `Shr` bits is larger than `u64::MAX`

fix #11426
2023-09-18 14:21:48 +00:00
Guillaume Gomez
b8b420cc79 Improve code readability by moving the retrieval of closures inside async functions right besides other closures handling.
Add doc comment explaining what `MutablyUsedVariablesCtxt::prev_move_to_closure` is about.
2023-09-18 15:47:24 +02:00
bors
ea16f812be Auto merge of #11531 - Alexendoo:remark-deps, r=flip1995
Update remark CI deps

[Remark v15](https://github.com/remarkjs/remark/releases/tag/15.0.0) was just released that needs a newer node version, this updates us to 18 (the current LTS)

Also updates mdbook while we're at it

changelog: none
2023-09-18 13:12:18 +00:00
Alex Macleod
32519528df Update remark CI deps 2023-09-18 12:48:32 +00:00
Alex Macleod
b06b915dc0 Move zero_ptr to the casts module 2023-09-18 12:15:51 +00:00
bors
c92de58692 Auto merge of #11523 - Alexendoo:used-underscore-bindings-lint-levels, r=xFrednet
used_underscore_bindings: respect lint levels on the binding definition

Fixes #11520
Fixes #947

Also ignores usages of `PhantomData`

changelog: none
2023-09-18 09:04:44 +00:00
Dev381
01056c5aae Fix missing semicolon in redundant_as_str docstring example 2023-09-17 18:10:21 -04:00
Dev381
1c9f3bef8b Add redundant_as_str lint
This lint checks for `as_str` on a `String` immediately followed by `as_bytes` or `is_empty` as those methods are available on `String` too. This could possibly also be extended to `&[u8]` in the future.
2023-09-17 17:50:45 -04:00
Alex Macleod
32d3387c80 used_underscore_bindings: respect lint levels on the binding definition 2023-09-17 20:40:51 +00:00
bors
251a475b72 Auto merge of #11511 - Jarcho:split_borrow, r=llogiq
Split `needless_borrow` into two lints

Splits off the case where the borrow is used as a generic argument to a function. I think the two cases are different  enough to warrant a separate lint.

The tests for the new lint have been reordered to group related parts together. Two warning have been dropped, one looked like it was testing the generic argument form, but it ends up triggering the auto-deref variant. The second was just a redundant test that didn't do anything interesting.

An issue with cycle detection is also included. The old version was checking if a cycle was reachable from a block when it should have been checking if the block is part or a cycle.

As a side note, I'm liking the style of just jamming all the tests into separate scopes in main.

changelog: Split off `needless_borrows_for_generic_args` from `needless_borrow`
2023-09-17 13:48:40 +00:00
Jason Newcomb
79247d95f7 Split part of needless_borrow into needless_borrows_for_generic_args 2023-09-17 09:48:12 -04:00
y21
558ae4c6a8 [redundant_guards]: lint if the pattern is on the LHS 2023-09-17 15:34:32 +02:00
mojave2
3665a4102b
fix ICE by u64::try_from(<u128>) 2023-09-17 19:44:25 +08:00
bors
7b5e0199da Auto merge of #11515 - y21:filter_map_bool_then_peel_refs, r=Jarcho
[`filter_map_bool_then`]: include multiple derefs from adjustments

In #11506 this lint was improved to suggest one deref if the bool is behind references (fixed the FP #11503), however it might need multiple dereferences if the bool is behind multiple layers of references or custom derefs. E.g. `&&&bool` needs `***b`.

changelog: [`filter_map_bool_then`]: suggest as many dereferences as there are needed to get to the bool
2023-09-17 06:37:45 +00:00
mojave2
5b790ff9e0
fix FP with needless_raw_string_hashes 2023-09-17 12:54:00 +08:00
bors
ef736489e7 Auto merge of #11468 - mojave2:issue-11465, r=blyxyas
add extra `byref` checking for the guard's local

changelog: [`redundant_guards`]: Now checks if the variable is bound using `ref` before linting.

The lint should not be emitted, when the local variable is bind by-ref in the pattern.

fixes #11465
2023-09-16 22:02:10 +00:00
Chen Chen
3cad623716
更新 cast_lossless.rs
Co-authored-by: Timo <30553356+y21@users.noreply.github.com>
2023-09-17 02:42:12 +08:00
mojave2
af2a8478ba
fix cast_lossless with macro call 2023-09-16 23:17:47 +08:00
Chen Chen
67f0ba4af8
Update clippy_lints/src/matches/redundant_guards.rs
fix typo

Co-authored-by: Alejandra González <blyxyas@gmail.com>
2023-09-16 22:12:40 +08:00
y21
2ec6f3b1ed also count derefs through custom Deref impls 2023-09-16 15:13:44 +02:00
y21
860e800fa0 [filter_map_bool_then]: peel as many refs as needed 2023-09-16 14:14:51 +02:00
bors
f54275f20f Auto merge of #11509 - mojave2:issue-11502, r=llogiq
fix FP of let_unit_value on async fn args

changelog: [`let_unit_value`]: fix the FalsePostive on async fn arguments

fix #11502
2023-09-16 10:22:33 +00:00
bors
3f9db9025d Auto merge of #11507 - J-ZhengLi:issue11485, r=dswij
trigger [`transmute_null_to_fn`] on chain of casts

fixes: #11485

changelog: trigger [`transmute_null_to_fn`] on chain of casts
2023-09-16 06:19:09 +00:00
bors
59636a2aa3 Auto merge of #11301 - y21:issue11300, r=dswij
[`useless_conversion`]: don't lint if type parameter has unsatisfiable bounds for `.into_iter()` receiver

Fixes #11300.

Before this PR, clippy assumed that if it sees a `f(x.into_iter())` call and the type at that argument position is generic over any `IntoIterator`, then the `.into_iter()` call must be useless because `x` already implements `IntoIterator`, *however* this assumption is not right if the generic parameter has more than just the `IntoIterator` bound (because other traits can be implemented for the IntoIterator target type but not the IntoIterator implementor, as can be seen in the linked issue: `<[i32; 3] as IntoIterator>::IntoIter` satisfies `ExactSizeIterator`, but `[i32; 3]` does not).

So, this PR makes it check that the type parameter only has a single `IntoIterator` bound. It *might* be possible to check if the type of `x` in `f(x.into_iter())` satisfies all the bounds on the generic type parameter as defined on the function (which would allow removing the `.into_iter()` call even with multiple bounds), however I'm not sure how to do that, and the current fix should always work.

**Edit:** This PR has been changed to check if any of the bounds don't hold for the type of the `.into_iter()` receiver, so we can still lint in some cases.

changelog: [`useless_conversion`]: don't lint `.into_iter()` if type parameter has multiple bounds
2023-09-16 06:04:59 +00:00
Jason Newcomb
fed036a57c Fix cycle detection in needless_borrow 2023-09-15 19:13:34 -04:00
mojave2
7426c83d8f
add a test case 2023-09-16 00:05:57 +08:00
bors
daadab515a Auto merge of #11483 - y21:path_ends_with, r=Alexendoo
new lint: `path_ends_with_ext`

Closes #11479

Not sure if it needs more test cases. I couldn't come up with any other ones, but it is a pretty simple lint logic wise with not too many checks

changelog: new lint: [`path_ends_with_ext`]
2023-09-15 15:38:55 +00:00
y21
981e96008b new lint: path_ends_with_ext 2023-09-15 16:17:51 +02:00