Commit graph

20137 commits

Author SHA1 Message Date
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
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
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
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
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
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
Renato Lochetti
4e71fc4302
Small fix after rebase 2024-07-03 19:54:02 +01:00
Renato Lochetti
eff6f68caf
Fix typos 2024-07-03 19:42:35 +01:00
Renato Lochetti
6661e83e7b
Rename lint, generalize function, add known issues, use multispan 2024-07-03 19:42:34 +01:00
Renato Lochetti
0f915f6f30
Add new lint hashset_insert_after_contains 2024-07-03 19:41:26 +01:00
bors
0f4035fde3 Auto merge of #12976 - tesuji:fix-explicit_auto_deref, r=xFrednet
Fix some false-positive cases of `explicit_auto_deref`

changelog: [`explicit_auto_deref`] Fix some false-positive cases

Fix part of #9841
Fix  #12969

r? xFrednet
2024-07-03 18:24:23 +00:00
Lzu Tao
c4c41d1352 Fix 12969 and fix 9841 2024-07-03 21:25:43 +07:00
Lzu Tao
388de386f5 Make it easier to print debugging with Debug 2024-07-03 21:09:58 +07:00
Lzu Tao
7b76b94780 add test 12969 and 9841 2024-07-03 21:09:38 +07:00
bors
918ae1bec4 Auto merge of #11647 - flip1995:needless-pass-by-ref-mut-pub-api, r=xFrednet
Honor `avoid-breaking-exported-api` in `needless_pass_by_ref_mut`

Until now, the lint only emitted a warning, when breaking public API. Now it doesn't lint at all when the config value is not set to `false`, bringing it in line with the other lints using this config value.

Also ensures that this config value is documented in the lint.

changelog: none
(I don't think a changelog is necessary, since this lint is in `nursery`)

---

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

cc `@GuillaumeGomez`

Marking as draft: Does this lint even break public API? If I change a function signature from `fn foo(x: &mut T)` to `fn foo(x: &T)`, I can still call it with `foo(&mut x)`. The only "breaking" thing is that the `clippy::unnecessary_mut_passed` lint will complain that `&mut` at the callsite is not necessary, possibly trickling down to the crate user having to remote a `mut` from a variable. [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=058165a7663902e84af1d23e35c10d66).

Are there examples where this actually breaks public API, that I'm missing?
2024-07-03 07:55:05 +00:00
Philipp Krones
ae47b97655
needless-pass-by-ref-mut: Update conf documentation 2024-07-03 09:53:05 +02:00
bors
3af20058eb Auto merge of #13010 - notriddle:notriddle/unbalanced-ticks-backslash, r=blyxyas
doc_markdown: detect escaped `` ` `` when checking unmatched

```
changelog: [`doc_markdown`]: correctly detect backslash-escaped `` ` ``
```
2024-07-02 21:30:36 +00:00
Michael Howell
70c8579e21 doc_markdown: detect escaped ` `` when checking unmatched
Add explanatory comment to complex bounds check

Format
2024-07-02 23:27:14 +02:00
Philipp Krones
125c778d6d
Move exported check to check_fn to exit early 2024-07-02 19:30:30 +02:00
Philipp Krones
2da0edbdf1
Honor avoid-breaking-exported-api in needless_pass_by_ref_mut
Until now, the lint only emitted a warning, when breaking public API. Now it
doesn't lint at all when the config value is not set to `false`, bringing it in
line with the other lints using this config value.

Also ensures that this config value is documented in the lint.
2024-07-02 19:30:01 +02:00
bors
6e6683b15e Auto merge of #13030 - astra-90:master, r=Alexendoo
Fix #12964 - false positive with `into_iter_without_iter`

changelog: FP: `into_iter_without_iter`: No longer lints when the `iter` or `iter_mut` implementation is not within the first `impl` block

fixes #12964

---

I'm pretty new to this open-source thing, so hopefully I did everything right. Got a little annoyed this false positive was happening in my code and the issue was inactive for two weeks so I thought I'd fix it myself.

As an aside, maybe `iter.map(...).next()` could be linted against? I don't see that ever being preferred over `iter.next().map(...)`, and it could've prevented the bug here.
2024-07-02 15:17:47 +00:00
bors
c4f81d00a2 Auto merge of #13029 - tesuji:minimal, r=flip1995
build: Skip installing rust-docs with minimal rustup profile

r? `@flip1995`

changelog: none
2024-07-02 14:34:31 +00:00
Astra Tsai
0dd8b27b6b Fix formatting 2024-07-01 19:10:10 -07:00
Astra Tsai
ba05b764bc Add regression test for #12964 2024-07-01 19:00:10 -07:00
Astra Tsai
567bea29b1 Fix into_iter_without_iter false positive when the implementation is not within the first impl block 2024-07-01 18:57:24 -07:00
bors
c4125286ce Auto merge of #12840 - tesuji:const-asserts, r=llogiq
Don't lint `assertions_on_constants` on any const assertions

close #12816
close #12847
cc #12817

----

changelog: Fix false positives in consts for `assertions_on_constants` and `unnecessary_operation`.
2024-07-01 22:06:06 +00:00
bors
0505dad349 Auto merge of #13017 - kornelski:idents, r=blyxyas
Image-related valid idents

False positives for idents in markdown

changelog: Add "WebP", "OpenExr", "YcbCr", "sRGB" to `doc-valid-idents` default.
2024-07-01 21:56:54 +00:00
Lzu Tao
76a068be6d Skip installing rust-docs with minimal rustup profile 2024-07-01 22:45:56 +07:00
bors
d255efc257 Auto merge of #13026 - alex-semenyuk:fix_doc_verbose_bit_mask_example, r=Manishearth
Fix doc for INEFFECTIVE_BIT_MASK and VERBOSE_BIT_MASK

Minor fixes for doc for INEFFECTIVE_BIT_MASK and VERBOSE_BIT_MASK

changelog: [none]
2024-07-01 14:28:19 +00:00
asemia
0dddf6e0e8 Fix doc for verbose_bit_mask 2024-07-01 14:09:15 +05:00
bors
f24a87093e Auto merge of #13025 - ojeda:manual_inspect_nightly, r=y21
`manual_inspect`: fix `clippy::version` from 1.78.0 to 1.81.0

Although `manual_inspect`'s PR started some months ago, the lint is only available in the current nightly (1.81.0), rather than 1.78.0.

```
changelog: [`manual_inspect`]: fix `clippy::version` from 1.78.0 to 1.81.0
```
2024-07-01 06:38:21 +00:00
bors
0abcd34419 Auto merge of #12983 - frp:manual_rotate, r=llogiq
Implement a lint to replace manual bit rotations with rotate_left/rot…

Fixes #6861

r? `@llogiq`

---

changelog: add [`manual_rotate`] lint
2024-07-01 06:26:48 +00:00
Miguel Ojeda
eb1b24a97a manual_inspect: fix clippy::version from 1.78.0 to 1.81.0
Although `manual_inspect`'s PR started some months ago, the lint is only
available in the current nightly (1.81.0), rather than 1.78.0.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2024-07-01 07:09:53 +02:00
bors
06758d8d7f Auto merge of #12970 - J-ZhengLi:new_lint_msrv, r=y21
fix wrong msrv import in `new_lint` template

changelog: none
2024-07-01 00:06:13 +00:00
Roman Franchuk
b08b8b8a75 Implement a lint to replace bit manual rotations with rotate_left/rotate_right 2024-06-29 22:31:10 +02:00
Kornel
eb33c1ac74
Image-related valid idents 2024-06-29 12:18:09 +01:00
bors
1aa236d59b Auto merge of #13006 - flip1995:manual-inspect-error-message, r=Jarcho
Add error message to manual_inspect lint

r? `@Jarcho`

changelog: none
2024-06-28 18:47:12 +00:00
bors
2f80536e83 Auto merge of #13002 - notriddle:notriddle/blank-line, r=Manishearth
doc_lazy_continuation: blank comment line for gap

This change addresses cases where doc comments are separated by blank lines, comments, or non-doc-comment attributes, like this:

```rust
/// - first line
// not part of doc comment
/// second line
```

Before this commit, Clippy gave a pedantically-correct warning about how you needed to indent the second line. This is unlikely to be what the user intends, and has been described as a "false positive." Since Clippy is warning you about a highly unintuitive behavior [that Rustdoc actually has](https://notriddle.com/rustdoc-html-demo-11/lazy-continuation-bad/test_dingus_2024/constant.D.html), we definitely want it to output *something*, but the suggestion to indent was poor.

Fixes #12917

```
changelog: [`doc_lazy_continuation`]: suggest blank line for likely-unintended lazy continuations
```
2024-06-28 16:37:43 +00:00