Commit graph

6385 commits

Author SHA1 Message Date
koka
c7152679ef
Apply review suggestions from @y21 2023-10-04 00:13:53 +09:00
koka
1a56f90ee5
Fix: avoid changing drop order 2023-10-03 21:28:01 +09:00
bors
81400e2db8 Auto merge of #11589 - koka831:fix/10198, r=giraffate
std_instead_of_core: avoid lint inside of proc-macro

- fixes https://github.com/rust-lang/rust-clippy/issues/10198

note: The lint for the reported `thiserror::Error` has been suppressed by [Don't lint unstable moves in std_instead_of_core](https://github.com/rust-lang/rust-clippy/pull/9545/files#diff-2cb8a24429cf9d9898de901450d640115503a10454d692dddc6a073a299fbb7eR29) because `thiserror::Error`  internally implements `std::error::Error for (derived struct)`.

changelog: [`std_intead_of_core`]: avoid linting inside proc-macro

I confirmed this change fixes the problem:
<details>
<summary>test result without the change</summary>

```console
error: used import from `std` instead of `core`
  --> tests/ui/std_instead_of_core.rs:65:14
   |
LL |     #[derive(ImplStructWithStdDisplay)]
   |              ^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the derive macro `ImplStructWithStdDisplay` (in Nightly builds, run with -Z macro-backtrace for more info)
```
</details>
2023-10-03 01:26:29 +00:00
bors
08c429f241 Auto merge of #11596 - blyxyas:fix-fp-needless_pass_by_ref_mut, r=Jarcho
Move `needless_pass_by_ref_mut`: `suspicious` -> `nursery`

[Related to [this Zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/needless_pass_by_ref_mut.20isn't.20ready.20for.20stable)]

`needless_pass_by_ref_mut` has been released with some important bugs (notably having a lot of reported false positives and an ICE). So it may not be really ready for being in stable until these problems are solved. This PR changes the lint's category from `suspicious` to `nursery`, just that.
changelog: none
2023-10-02 18:40:32 +00:00
blyxyas
07e63291ec
Modify tests to account for the new allow-by-default needless_pass_by_ref_mut 2023-10-02 20:14:43 +02:00
Alex Macleod
258b9a8562 Don't escape unicode escape braces in print_literal 2023-10-01 21:43:09 +00:00
Victor Song
e683e3eeac Don't lint manual_non_exhaustive when enum explicitly marked as non_exhaustive
There are cases where users create a unit variant for the purposes
of tracking the number of variants for an nonexhaustive enum.
We should check if an enum is explicitly marked as nonexhaustive
before reporting `manual_non_exhaustive` in these cases. Fixes #11583
2023-09-30 22:57:54 -05:00
bors
0e43a04fab Auto merge of #11587 - y21:into_iter_without_iter, r=Jarcho
new lint: `into_iter_without_iter`

Closes #9736 (part 2)

This implements the other lint that my earlier PR missed: given an `IntoIterator for &Type` impl, check that there exists an inherent `fn iter(&self)` method.

changelog: new lint: `into_iter_without_iter`

r? `@Jarcho` since you reviewed #11527 I figured it makes sense for you to review this as well?
2023-09-30 18:43:37 +00:00
y21
8eb586d154 new lint: into_iter_without_iter 2023-09-30 19:38:16 +02:00
koka
d5cc97e32c
Add macro for test which use std internally 2023-10-01 00:47:57 +09:00
bors
b00236d7f0 Auto merge of #11580 - y21:issue11579, r=Jarcho
[`manual_let_else`]: only omit block if span is from same ctxt

Fixes #11579.

The lint already had logic for omitting a block in `else` if a block is already present, however this didn't handle the case where the block is from a different expansion/syntax context. E.g.
```rs
macro_rules! panic_in_block {
  () => { { panic!() } }
}

let _ = match Some(1) {
  Some(v) => v,
  _ => panic_in_block!()
};
```
It would see this in its expanded form as `_ => { panic!() }` and think it doesn't have to include a block in its suggestion because it is already there, however that's not true if it's from a different expansion like in this case.

changelog: [`manual_let_else`]: only omit block in suggestion if the block is from the same expansion
2023-09-29 18:49:57 +00:00
y21
2d2017942a [manual_let_else]: only omit block if span is from same ctxt 2023-09-29 16:54:50 +02:00
y21
330ebbb9f9 new lint: iter_without_into_iter 2023-09-28 22:22:36 +02:00
koka
b413bf6c4e
Fix index of the remaining positional arguments 2023-09-28 17:34:02 +09:00
bors
4494b6947f Auto merge of #11569 - Alexendoo:needless-raw-string-descr, r=llogiq
Describe the type of string in raw_strings lints

changelog: none
2023-09-26 21:16:33 +00:00
Alex Macleod
ec2f62677f Add manual_hash_one lint 2023-09-26 13:49:15 +00:00
Alex Macleod
6cdff10778 Describe the type of string in raw_strings lints 2023-09-26 11:49:44 +00:00
koka
fab90003b8
Do not lint when imported item contains underscore 2023-09-26 12:58:48 +09:00
Philipp Krones
81fe8dc084
Merge remote-tracking branch 'upstream/master' into rustup 2023-09-25 10:26:11 +02:00
Camille GILLOT
19e160fe2f Bless clippy. 2023-09-23 13:47:30 +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
pc-linux
ab51f66ec0 added tests 2023-09-22 18:04:57 +02:00
Ralf Jung
1fac304bf5 adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +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
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
e9dc753b7b Auto merge of #115748 - RalfJung:post-mono, r=oli-obk
move required_consts check to general post-mono-check function

This factors some code that is common between the interpreter and the codegen backends into shared helper functions. Also as a side-effect the interpreter now uses the same `eval` functions as everyone else to get the evaluated MIR constants.

Also this is in preparation for another post-mono check that will be needed for (the current hackfix for) https://github.com/rust-lang/rust/issues/115709: ensuring that all locals are dynamically sized.

I didn't expect this to change diagnostics, but it's just cycle errors that change.

r? `@oli-obk`
2023-09-18 19:41:21 +00: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
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
Dylan DPC
66aa7f7cac Rollup merge of #115477 - kellerkindt:stabilized_int_impl, r=dtolnay
Stabilize the `Saturating` type

Closes #87920
Closes #92354

Stabilization report https://github.com/rust-lang/rust/issues/87920#issuecomment-1652346124
FCP https://github.com/rust-lang/rust/issues/87920#issuecomment-1676438885
2023-09-17 11:23:24 +00: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