Commit Graph

20148 Commits

Author SHA1 Message Date
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
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
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