Commit Graph

20170 Commits

Author SHA1 Message Date
bors
058e6eaa3a Auto merge of #13043 - Jarcho:assign_clone, r=Manishearth
Refactor `assigning_clones`

Short list of changes:
* Inline and simplify `extract_call`
* Inline `is_ok_to_suggest`
* Inline `skip_drop_block`
* Check the HIR tree before the macro check
* Don't call `outer_expn_data`
* Use `find` instead of a loop in `clone_source_borrows_from_dest`

changelog: none
2024-07-08 22:48:19 +00:00
bors
f6020fbd44 Auto merge of #13042 - Jarcho:almost_range, r=Manishearth
`almost_complete_range`: Delay suggestion creation.

Does less work when the lint doesn't trigger.

changelog: none
2024-07-08 22:39:01 +00:00
bors
510cfe3dc4 Auto merge of #13067 - Jarcho:misc_small3, r=Manishearth
Misc refactorings part 3

And some more changes. Same general idea of checking the HIR tree first when linting.

changelog: none
2024-07-08 17:52:47 +00:00
bors
dfb92532fa Auto merge of #12870 - lrh2000:sig-drop-while, r=blyxyas
`significant_drop_in_scrutinee`: Trigger lint also for scrutinees in `while let` and `if let`

This lint should also work for `if let` and `while let`, so this PR makes it actually work.

For `while let`, I can't think of any reason why this lint shouldn't be enabled. The only problem is that the lint suggests moving the significant drop above the `while let`, which is clearly invalid in the case of `while let`. I don't know if this is fixable, but this PR simply disables the wrong suggestions.

For `if let`, it seems that another lint called `if_let_mutex` has some overlapping functionality. But `significant_drop_in_scrutinee` is a bit stricter, as it will trigger even if the `else` branch does not try to lock the same mutex.

changelog: [`significant_drop_in_scrutinee`]: Trigger lint also for scrutinees in `while let` and `if let`.

r? `@blyxyas` (the third PR as promised in https://github.com/rust-lang/rust-clippy/pull/12740#issuecomment-2094876350, thanks for your review!)
2024-07-08 15:09:45 +00:00
bors
edc6b00e73 Auto merge of #13064 - Alexendoo:lintcheck-shrink-json, r=xFrednet
Reduce the size of lintcheck JSON output

Saves about 80% of the size by picking out what we need rather than serialising the whole diagnostic

r? `@xFrednet`

changelog: none
2024-07-08 14:57:42 +00:00
bors
2ad8cdc81b Auto merge of #13045 - J-ZhengLi:missing_const_for_fn_FP, r=blyxyas
[`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty

closes: #13009

---

changelog: [`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty
2024-07-08 14:39:12 +00:00
J-ZhengLi
08992d0372 [missing_const_for_fn]: fix FP when arg ty is impl trait alias ty 2024-07-08 18:09:49 +08:00
bors
1de41b18d2 Auto merge of #13068 - Jarcho:init_numbered, r=Alexendoo
Rework `init_numbered_fields`

Two behaviour changes:
* Not linting in macros
* Not linting when side effects might be reordered

changelog: `init_numbered_fields`: Don't suggest reordering side effects.
2024-07-08 00:28:03 +00:00
Jason Newcomb
5b7ffa1a63 Rework init_numbered_fields:
* Only check the name of a single field
* Don't lint in macros
* Check for side effects
* Don't use a binary heap
2024-07-07 20:15:19 -04:00
Alex Macleod
eac1aab1ff Reduce the size of lintcheck JSON output 2024-07-07 21:05:51 +00:00
Jason Newcomb
5ae33c7699 legacy_numeric_constants: Check HIR tree first. 2024-07-07 16:52:59 -04:00
Jason Newcomb
03036c11b3 large_include_file: Check HIR tree first. 2024-07-07 16:52:33 -04:00
Jason Newcomb
c3dd028d3e large_futures: Delay macro check 2024-07-07 16:52:13 -04:00
Jason Newcomb
430c02cbd0 large_enum_variant: Delay macro check 2024-07-07 16:51:58 -04:00
Jason Newcomb
3092c8a5fd large_const_arrays: Check HIR tree first. 2024-07-07 16:51:33 -04:00
Jason Newcomb
6b10b4360c iter_without_into_iter: Delay macro check 2024-07-07 16:51:20 -04:00
Jason Newcomb
fa1a690b23 iter_not_returning_iterator:
* Check HIR tree first.
* Check name by symbol.
2024-07-07 16:43:07 -04:00
Jason Newcomb
ca5c2813eb items_after_statements: Do less work in the default case. 2024-07-07 16:41:36 -04:00
Jason Newcomb
aef0710054 instant_subtraction: Reduce redundant work. 2024-07-07 16:37:51 -04:00
Jason Newcomb
dc8403f0f5 inline_fn_without_body: inline into a single function 2024-07-07 16:37:31 -04:00
Jason Newcomb
8e2ddc800b inherent_to_string: Check HIR tree before checking for macros. 2024-07-07 16:35:05 -04:00
bors
a4132817fb Auto merge of #13052 - xFrednet:00000-lintcheck-warn-all, r=Alexendoo
Lintcheck: Add `--warn-all` and make it the CI default

This PR adds a new `--warn-all` flag to lintcheck. This is intended for our CI, as it currently doesn't detect changes of `nursery` and `restriction` lints.

I only made it the default for the CI, as `restriction` lints tend to generate A LOT of lint triggers. Looking at you [`clippy::implicit_return`](https://rust-lang.github.io/rust-clippy/master/index.html#/clippy::implicit_return)

That's it. Should hopefully be easy to review.

Also, a bit thanks again to `@Alexendoo` for adding this to our CI ❤️

---

r? `@Alexendoo`

changelog: none
2024-07-07 18:30:39 +00:00
xFrednet
93e74a4187
Lintcheck: Update lintcheck documentation 2024-07-07 18:42:09 +02:00
bors
09c07ed63f Auto merge of #13048 - Jarcho:disallowed_methods, r=blyxyas
Refactor `disallowed_methods` and narrow span

Using the span of the call site just produces noisy diagnostics for long calls. Especially multi-line calls.

changelog: none
2024-07-07 14:28:44 +00:00
bors
f2c74e220b Auto merge of #12966 - Rudxain:patch-1, r=dswij
Clarify that `modulo_one` only applies to ints

changelog: [`modulo_one`]: (docs) Clarify that it only applies to integers

This might be nitpicky, but it's more technically correct.

It also helps if a user skims through the docs, because they may believe it also applies to `{float}`s. This doc edit minimizes that possibility
2024-07-07 10:21:47 +00:00
bors
0c9016aa1e Auto merge of #13055 - Jarcho:auto_derive, r=Alexendoo
Only check for `automatically_derived` on impl blocks

This brings us in line with how rustc checks for the attribute. Also note that `unused_attributes` will trigger if it's placed anywhere else.

See:
9a21ac8e7e/compiler/rustc_passes/src/dead.rs (L400-L403)
9a21ac8e7e/compiler/rustc_passes/src/liveness.rs (L143-L148)

changelog: none
2024-07-06 12:01:28 +00:00
Jason Newcomb
d8fb164a7c Rename any_parent_is_automatically_derived to in_automatically_derived. Only check for the attribute on an impl block. 2024-07-06 00:24:48 -04:00
bors
3ed690f07a Auto merge of #12974 - alex-semenyuk:rename_thread_local_initializer_can_be_made_const, r=Alexendoo
Rename thread_local_initializer_can_be_made_const to missing_const_for_thread_local

Close #12934
As discussed at #12934 name `thread_local_initializer_can_be_made_const` sounds against convention for other lints which describe the issue/wrong code but not suggestion and it is quite long. The new name take example from existing lint `missing_const_for_fn`

changelog: `thread_local_initializer_can_be_made_const` : Rename to [`missing_const_for_thread_local`]
2024-07-05 17:50:06 +00:00
xFrednet
25bb612538
Lintcheck: Add --warn-all and make it the CI default 2024-07-05 16:42:20 +02:00
Alexey Semenyuk
6621e6cbfa Rename thread_local_initializer_can_be_made_const to missing_const_for_thread_local 2024-07-05 19:40:37 +05:00
bors
94a000b613 Auto merge of #11293 - mrnossiom:11234, r=Jarcho
feat: add cfg_not_test lint

<!--
- \[x] 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`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
-->

Fixes #11234

changelog: new lint: [`cfg_not_test`]

I don't know whether to lint only the `attr` or also the item associated to it. I guess this would mean putting the check in another place than `check_attribute` but I can't find a way to get the associated item to the attribute.

Also, I'm not sure how to document this lint, I feel like my explications are bad.
2024-07-05 11:42:47 +00:00
bors
3ef366705b Auto merge of #13049 - Jarcho:is_in_test, r=Alexendoo
Remove `is_in_test_module_or_function`

Uses are replaced with `is_in_test` for consistency with other lints and to simplify the implementation of the lints. This means the module name is no longer checked, but that was a horrible hack from a time when late passes couldn't see `#[cfg(..)]` attributes.

changelog: none
2024-07-05 11:33:46 +00:00
Milo Moisson
dd37441a64
test: add cfg_not_test tests 2024-07-05 10:28:26 +02:00
Milo Moisson
2c09ac3d39
feat: add cfg_not_test lint 2024-07-05 10:28:26 +02:00
bors
e7f2952f7e Auto merge of #13047 - Jarcho:script, r=y21
Refactor `disallowed_script_idents`

Minor change to use `find_map` instead of a loop. Not important, but it's easier to read.

changelog: none
2024-07-05 06:47:49 +00:00
Jason Newcomb
6d61bdabea Use is_in_test in more places. 2024-07-05 02:42:58 -04:00
Jason Newcomb
60af2585f7 Refactor disallowed_methods:
* Simplify `def_id` extraction.
* Use the span of the method name instead of the call.
2024-07-05 02:37:09 -04:00
Jason Newcomb
4c44b4e3c8 Remove is_test_module_or_function and use is_in_test instead. 2024-07-05 02:17:24 -04:00
Jason Newcomb
ac939ad3a1 Refactor disallowed_script_idents: Simplify script checking loop. 2024-07-05 02:04:43 -04:00
bors
885f97e2ce Auto merge of #11656 - y21:unnecessary_string_from_utf8, r=Jarcho
[`unnecessary_to_owned`]: catch `to_owned` on byte slice to create temporary `&str`

Closes #11648

Detects the pattern `&String::from_utf8(bytes.to_vec()).unwrap()` and suggests `core::str::from_utf8(bytes).unwrap()`, which avoids the unnecessary intermediate allocation.

I decided to put this in the existing `unnecessary_to_owned` lint (rather than creating a new lint) for a few reasons:
- we get to use some of its logic (for example, recognizing any of the functions in the `to_owned` family, e.g. `to_vec`)
- the actual inefficient operation that can be avoided here is the call to `.to_vec()`, so this is in a way similar to the other cases caught by `unnecessary_to_owned`, just through a bunch of type conversions
- we can make this more "generic" later and catch other cases, so imo it's best not to tie this lint specifically to the `String` type

changelog: [`unnecessary_to_owned`]: catch `&String::from_utf8(bytes.to_vec()).unwrap()` and suggest `core::str::from_utf8(bytes).unwrap()`
2024-07-05 02:04:06 +00:00
Jason Newcomb
d9ab0a70f6 Refactor assigning_clones:
* Merge some code paths
* Use `find` instead of a loop
* Move macro check to after hir pattern matching
2024-07-04 21:51:27 -04:00
bors
0aac16e5b2 Auto merge of #13037 - J-ZhengLi:issue13008, r=llogiq
[`missing_const_for_fn`]: fix suggestions for fn with abi that requires `const_extern_fn` feature

closes: #13008

---

changelog: [`missing_const_for_fn`]: fix suggestions for fn with abi that requires `const_extern_fn` feature.
2024-07-05 00:20:56 +00:00
Jason Newcomb
5b30f6a1a3 almost_complete_range: Delay suggestion creation. 2024-07-04 19:36:30 -04:00
bors
2b01d69212 Auto merge of #10155 - TheNeikos:feature/add_byte_char_slice_lint, r=Manishearth
Add new lint for byte char slices

This patch adds a new lint that checks for potentially harder to read byte char slices: `&[b'a', b'b']` and suggests to replace them with the easier to read `b"ab"` form.

Fixes #10147

---

changelog: new lint: [`byte_char_slices`]
[#10155](https://github.com/rust-lang/rust-clippy/pull/10155)
<!-- changelog_checked -->
2024-07-04 16:15:01 +00:00
Marcel Müller
88c4a22480
New Lint: byte_char_slices
This patch adds a new lint that checks for potentially harder to read
byte char slices: `&[b'a', b'b']` and suggests to replace them with the
easier to read `b"ab"` form.

Signed-Off-By: Marcel Müller <m.mueller@ifm.com>
Co-authored-by: Matthias Beyer <matthias.beyer@ifm.com>

Use iterator to skip validation

Signed-off-by: Marcel Müller <m.mueller@ifm.com>
Suggested-by: Alex Macleod <alex@macleod.io>

Convert quote escapes to proper form

Signed-off-by: Marcel Müller <m.mueller@ifm.com>

Add more convertable test cases

Signed-off-by: Marcel Müller <m.mueller@ifm.com>
2024-07-04 14:31:15 +02:00
J-ZhengLi
3a71223812 [missing_const_for_fn]: fix suggestions for fn with abi that requires const_extern_fn feature 2024-07-04 15:56:11 +08:00
bors
d2400a49a4 Auto merge of #12873 - lochetti:issue_11103, r=llogiq
Add new lint `hashset_insert_after_contains`

This PR closes https://github.com/rust-lang/rust-clippy/issues/11103.

This is my first PR creating a new lint (and the second attempt of creating this PR, the first one I was not able to continue because of personal reasons). Thanks for the patience :)

The idea of the lint is to find insert in hashmanps inside if staments that are checking if the hashmap contains the same value that is being inserted. This is not necessary since you could simply call the insert and check for the bool returned if you still need the if statement.

changelog: new lint: [hashset_insert_after_contains]
2024-07-04 05:39:28 +00:00
Ruihan Li
378962f861 Lint significant drop on while let and if let 2024-07-04 13:18:38 +08:00
bors
a4bdab38f0 Auto merge of #13027 - xFrednet:12998-expect-returns, r=Jarcho
`needless_return`: Support `#[expect]` on the return statement

A fix for https://github.com/rust-lang/rust-clippy/issues/9361 suppresses `clippy::needless_return` if there are any attributes on the `return` statement. This leads to some unexpected behavior, as described in https://github.com/rust-lang/rust-clippy/issues/12998, where adding `#[expect(clippy::needless_return)]` suppresses the lint, but doesn't fulfill the expectation.

I now decided to manually fulfill any expectations, if they are before the attribute check.

---

Closes: https://github.com/rust-lang/rust-clippy/issues/12998

changelog: none
2024-07-03 19:18:46 +00:00
xFrednet
903874d2f4
needless_return: Support #[expect] on the return statement 2024-07-03 20:58:21 +02:00