Commit Graph

18703 Commits

Author SHA1 Message Date
bors
ee8bfb7f7a Auto merge of #12051 - y21:option_as_ref_cloned, r=dswij
new lint: `option_as_ref_cloned`

Closes #12009

Adds a new lint that looks for `.as_ref().cloned()` on `Option`s. That's the same as just `.clone()`-ing the option directly.

changelog: new lint: [`option_as_ref_cloned`]
2024-01-05 06:39:46 +00:00
bors
8507e4c80e Auto merge of #12090 - GuillaumeGomez:default-unconditional-recursion, r=llogiq
Extend `unconditional_recursion` lint to check for `Default` trait implementation

In case the `Default` trait is implemented manually and is calling a static method (let's call it `a`) and then `a` is using `Self::default()`, it makes an infinite call recursion difficult to see without debugging. This extension checks that there is no such recursion possible.

r? `@llogiq`

changelog: Extend `unconditional_recursion` lint to check for `Default` trait implementation
2024-01-04 19:45:20 +00:00
Guillaume Gomez
bf5c0d8334 Add tests for extension of unconditional_recursion lint on Default trait 2024-01-04 17:40:28 +01:00
Guillaume Gomez
2666f39d3e Detect unconditional recursion between Default trait impl and static methods 2024-01-04 17:40:28 +01:00
bors
52ae2626f9 Auto merge of #12088 - granddaifuku:fix/metadata-collector-lint-listing, r=Manishearth
fix: metadata-collector lists wrong affected lints

fixes #12042

This PR addresses the issue where the `metadata collector` incorrectly generates the `Affected Lints` section when a comma is included in the configuration documentation.

I made adjustments; however, if the `/// Lint: SOMETHING` section ends with `.` it always produces the correct output.
For example,
```rust
/// Lint: PUB_UNDERSCORE_FIELDS
```
should be
```rust
/// Lint: PUB_UNDERSCORE_FIELDS.
```

changelog: none
2024-01-04 15:53:14 +00:00
Yudai Fukushima
9dcf92649c
fix: metadata-collector listing lints when config documents include comma 2024-01-04 13:49:33 +00:00
bors
0bf0b88035 Auto merge of #12025 - jetlime:master, r=flip1995
Include GitLab in the CI section of the clippy doc book

Fixes #12012
changelog: Docs: [`Continuous Integration`] now includes how to use clippy in GitLab CI.
2024-01-04 10:48:53 +00:00
Paul Houssel
89e4b7162c
Include GitLab in the CI section of the clippy doc book 2024-01-04 11:43:38 +01:00
bors
691d4e275a Auto merge of #12023 - waywardmonkeys:ci-update-checkout-action, r=flip1995
ci: Update to `actions/checkout@v4` from `v3`.

This also updates the book's section on CI for the same thing.

changelog: none
2024-01-04 10:28:38 +00:00
bors
ee04871f74 Auto merge of #12086 - blyxyas:update-copyright, r=flip1995
Update copyright year for Clippy (2024 edition)

Our license was outdated by a year (+ change in the main README.md)

changelog:none
2024-01-04 10:19:33 +00:00
bors
ebf5c1a928 Auto merge of #12031 - y21:eager_transmute_more_binops, r=llogiq
Lint nested binary operations and handle field projections in `eager_transmute`

This PR makes the lint a bit stronger. Previously it would only lint `(x < 4).then_some(transmute(x))` (that is, a single binary op in the condition). With this change, it understands:
- multiple, nested binary ops: `(x < 4 && x > 1).then_some(...)`
- local references with projections: `(x.field < 4 && x.field > 1).then_some(transmute(x.field))`

changelog: [`eager_transmute`]: lint nested binary operations and look through field/array accesses

r? llogiq (since you reviewed my initial PR #11981, I figured you have the most context here, sorry if you are too busy with other PRs, feel free to reassign to someone else then)
2024-01-03 21:43:01 +00:00
bors
17dcd0d2e4 Auto merge of #12030 - torfsen:11973-fix-quoting-of-double-quote-in-char-literal, r=llogiq
11973: Don't escape `"` in `'"'`

Fixes #11973.

```
changelog: [`single_char_pattern`]: don't escape `"` in `'"'`
```
2024-01-03 21:30:01 +00:00
bors
bc962c246a Auto merge of #12071 - ShE3py:deadlinks, r=blyxyas
Remove deadlinks from `unchecked_duration_subtraction`

See <https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction>

changelog: [`unchecked_duration_subtraction`]: remove deadlinks
2024-01-03 20:04:56 +00:00
y21
5960107415 new lint: option_as_ref_cloned 2024-01-03 19:40:47 +01:00
blyxyas
18e4632b2b
Update copyright year for Clippy (2024 edition) 2024-01-03 19:36:44 +01:00
bors
0153ca95ae Auto merge of #12062 - GuillaumeGomez:fix-false-positive-unconditional_recursion, r=xFrednet
Fix false positive `unconditional_recursion`

Fixes #12052.

Only checking if both variables are `local` was not enough, we also need to confirm they have the same type as `Self`.

changelog: Fix false positive for `unconditional_recursion` lint
2024-01-03 09:14:58 +00:00
bors
2eb13d3a7c Auto merge of #12056 - PartiallyTyped:12050, r=xFrednet
Fixes: #12050 - `identity_op` correctly suggests a deference for coerced references

When `identity_op` identifies a `no_op`, provides a suggestion, it also checks the type of the type of the variable. If the variable is a reference that's been coerced into a value, e.g.

```
let x = &0i32;
let _ = x + 0;
```

the suggestion will now use a derefence. This is done by identifying whether the variable is a reference to an integral value, and then whether it gets dereferenced.

changelog: false positive: [`identity_op`]: corrected suggestion for reference coerced to value.

fixes: #12050
2024-01-03 09:02:02 +00:00
bors
9eb2b225f8 Auto merge of #12079 - yuxqiu:fix_typos, r=Manishearth
Fix some typos

changelog: none
2024-01-03 00:38:43 +00:00
Yuxiang Qiu
88541d6637
fix some typos 2024-01-02 19:21:51 -05:00
bors
e73bb00542 Auto merge of #12026 - PartiallyTyped:12015, r=llogiq
New Lint: [`thread_local_initializer_can_be_made_const`]

Adds a new lint to suggest using `const` on `thread_local!` initializers that can be evaluated at compile time.

Impl details:

The lint relies on the expansion of `thread_local!`. For non const-labelled initializers, `thread_local!` produces a function called `__init` that lazily initializes the value. We check the function and decide whether the body can be const. If so, we lint that the initializer value can be made const.

changelog: new lint [`thread_local_initializer_can_be_made_const`]

fixes: #12015
2024-01-02 00:27:24 +00:00
Lieselotte
ff2919ac5d
Remove deadlinks from unchecked_duration_subtraction 2024-01-01 18:50:58 +01:00
Quinn Sinclair
70024e16c0 New Lint: [thread_local_initializer_can_be_made_const]
Adds a new lint to suggest using `const` on `thread_local!`
initializers that can be evaluated at compile time.

Impl details:

The lint relies on the expansion of `thread_local!`. For non
const-labelled initializers, `thread_local!` produces a function
called `__init` that lazily initializes the value. We check the function
and decide whether the body can be const. The body of the function is
exactly the initializer. If so, we lint the body.

changelog: new lint [`thread_local_initializer_can_be_made_const`]
2024-01-01 18:06:10 +02:00
bors
e1dbafd875 Auto merge of #12065 - samueltardieu:issue-12063, r=llogiq
Add `.front()` to `get_first` lint description

Fix #12063

changelog: none
2023-12-31 16:35:58 +00:00
bors
a89eb85d09 Auto merge of #11987 - torfsen:8733-Suggest-str.lines-when-splitting-at-newlines, r=Jarcho
Issue 8733: Suggest `str.lines` when splitting at hard-coded newlines

Fixes #8733.
```
changelog: [`splitting_strings_at_newlines`]: New lint that suggests `str.lines` over splitting at hard-coded newlines
```

This is my first PR to Clippy and one of my first Rust PRs in general -- please feel free to nitpick, I'm thankful for any opportunity to learn! I'd be especially interested in feedback to the following points:

* Is checking for `'\n'`, `"\n"`, and `"\r\n"` as arguments to `split` enough, or should we do more (e.g. checking for constants that have those values if that is possible)?
* Could the code be written in a more idiomatic way?
* Is the default `".."` for `snippet` a good choice? I copied it from other uses of `snippet` in the code base, but I'm not entirely sure.
* Is the category `suspicious` a good choice?
* Is the suggestion applicability `MaybeIncorrect` a good choice? I used it because the return type of `lines` is not exactly the same as that of `split`.
2023-12-31 16:25:28 +00:00
Samuel Tardieu
457ab585fc Add .front() to get_first lint description 2023-12-31 15:38:38 +01:00
Florian Brucker
fe35e08e9f 8733: Suggest str.lines when splitting at hard-coded newlines
Adds a new `splitting_strings_at_newlines` lint that suggests to use
`str.lines` instead of splitting a trimmed string at hard-coded
newlines.
2023-12-31 13:30:36 +01:00
Guillaume Gomez
7107aa22b2 Add regression tests for unconditional_recursion 2023-12-31 11:20:49 +01:00
Guillaume Gomez
d3bde854c4 Fix false positive in PartialEq implementation 2023-12-31 11:20:49 +01:00
bors
eca3932395 Auto merge of #12053 - mikkoglinn678:fix_new_lint_typo, r=llogiq
Fix typo in new_lint.rs

changelog: none
2023-12-31 09:22:26 +00:00
bors
44c99a8089 Auto merge of #11980 - GuillaumeGomez:UNCONDITIONAL_RECURSION-tostring, r=llogiq
Extend UNCONDITIONAL_RECURSION to check for ToString implementations

Follow-up of https://github.com/rust-lang/rust-clippy/pull/11938.

r? `@llogiq`

changelog: Extend `UNCONDITIONAL_RECURSION` to check for `ToString` implementations
2023-12-31 09:12:42 +00:00
bors
7f185bdef6 Auto merge of #12047 - ARandomDev99:12007-empty-enum-variants-with-brackets, r=Jarcho
New Lint: empty_enum_variants_with_brackets

This PR:
- adds a new early pass lint that checks for enum variants with no fields that were defined using brackets. **Category: Restriction**
- adds relevant UI tests for the new lint.

Closes #12007

```
changelog: New lint: [`empty_enum_variants_with_brackets`]
```
2023-12-30 19:01:53 +00:00
Aneesh Kadiyala
5f1718810f Change empty_enum_variants_with_brackets applicability to MaybeIncorrect 2023-12-30 22:22:44 +05:30
bors
0cc53f48f5 Auto merge of #11957 - J-ZhengLi:issue11535, r=Jarcho
don't lint [`default_numeric_fallback`] on return and local assigned macro calls with type stated

fixes: #11535

changelog: don't lint [`default_numeric_fallback`] on return and local assigned macro calls with type stated
2023-12-30 16:47:14 +00:00
bors
c6aeb28a7b Auto merge of #11865 - yuxqiu:map_unwrap_or_default, r=Jarcho
feat: add `manual_is_variant_and` lint

changelog: add a new lint [`manual_is_variant_and`].
- Replace `option.map(f).unwrap_or_default()` and `result.map(f).unwrap_or_default()` with `option.is_some_and(f)` and `result.is_ok_and(f)` where `f` is a function or closure that returns `bool`.
- MSRV is set to 1.70.0 for this lint; when `is_some_and` and `is_ok_and` was stabilised

---

For example, for the following code:

```rust
let opt = Some(0);
opt.map(|x| x > 1).unwrap_or_default();
```

It suggests to instead write:

```rust
let opt = Some(0);
opt.is_some_and(|x| x > 1)
```
2023-12-30 16:37:36 +00:00
bors
b19b5f293e Auto merge of #12008 - J-ZhengLi:issue9872, r=Jarcho
make [`mutex_atomic`] more type aware

fixes: #9872

---

changelog: [`mutex_atomic`] now suggests more specific atomic types and skips mutex i128 and u128
2023-12-30 16:29:13 +00:00
bors
c99224726c Auto merge of #12054 - y21:issue12037, r=Jarcho
add external macro checks to `iter_without_into_iter` and `into_iter_without_iter`

Fixes #12037

I think it's useful to still lint on local macros, since the user should still be able to add another impl with the `IntoIterator` or `iter` method. I think it's also fairly common to write a macro for generating many impls (e.g. for many similar types), so it'd be nice if we can continue linting in those cases.
For that reason I went with `in_external_macro`.

I also added a test for `#[allow]`ing the lint while I was at it.

changelog: [`iter_without_into_iter`]: don't lint if the `iter` method is defined in an external macro
changelog: [`into_iter_without_iter`]: don't lint if the `IntoIterator` impl is defined in an external macro
2023-12-30 16:20:47 +00:00
Guillaume Gomez
d161f3b559 Add ui test for UNCONDITIONAL_RECURSION lint on ToString impl 2023-12-30 17:11:56 +01:00
Guillaume Gomez
ab2d1c28d5 Extend UNCONDITIONAL_RECURSION to check for ToString implementations 2023-12-30 17:11:56 +01:00
Quinn Sinclair
c2b3f5c767 identity_op correctly suggests a deference for coerced references
When `identity_op` identifies a `no_op`, provides a suggestion, it also
checks the type of the type of the variable. If the variable is
a reference that's been coerced into a value, e.g.

```
let x = &0i32;
let _ = x + 0;
```

the suggestion will now use a derefence. This is done by identifying
whether the variable is a reference to an integral value, and then
whether it gets dereferenced.

changelog: false positive: [`identity_op`]: corrected suggestion for
reference coerced to value.

fixes: #12050
2023-12-30 13:31:32 +02:00
y21
0848e120b2 add expansion checks to iter_without_into_iter and into_iter_without_iter 2023-12-30 04:56:46 +01:00
mikkoglinn678
95f8f1eed2 fix typo in creating early lint pass 2023-12-29 20:46:37 -06:00
Aneesh Kadiyala
1ee9993a96 add new lint, empty_enum_variants_with_brackets
- Add a new early pass lint.
- Add relevant UI tests.
2023-12-29 19:23:31 +05:30
bors
174a0d7be6 Auto merge of #10283 - ParkMyCar:lint/pub_underscore_fields, r=blyxyas
feature: add new lint `pub_underscore_fields`

fixes: #10282

This PR introduces a new lint `pub_underscore_fields` that lints when a user has marked a field of a struct as public, but also prefixed it with an underscore (`_`). This is something users should avoid because the two ideas are contradictory. Prefixing a field with an `_` is inferred as the field being unused, but making a field public infers that it will be used.

- \[x] Followed [lint naming conventions][lint_naming]
  - I believe I followed the naming conventions, more than happy to update the naming if I did not :)
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog: new lint: [`pub_underscore_fields`]
[#10283](https://github.com/rust-lang/rust-clippy/pull/10283)
<!-- changelog_checked -->
2023-12-29 10:52:00 +00:00
Parker Timmerman
fa7dd1c4e0
add new lint, pub_underscore_fields
- add a new late pass lint, with config options
- add ui tests for both variations of config option
- update CHANGELOG.md

github feedback

bump version to 1.77 and run cargo collect-metadata

Change `,` to `;` in `conf.rs`
2023-12-29 11:44:34 +01:00
bors
8b22471274 Auto merge of #12041 - compiler-errors:args-are-correct-now, r=Jarcho
Remove mitigations for incorrect node args

This change https://github.com/rust-lang/rust/pull/118420/files#r1419874371 adds a missing `write_args` to properly record node args for lang-item calls.

Thus, in the `unnecessary_to_owned` lint, this ensures that the `call_generic_args` extracted by `get_callee_generic_args_and_args` are always correct, and we can remove the mitigation for #9504 and #10021 since the root cause has been fixed.

I'm not sure if there is other now-unnecessary code that can be removed, but this is the one I found when investigating https://github.com/rust-lang/rust-clippy/issues/11965#issuecomment-1871732518.

changelog: none
2023-12-29 05:52:17 +00:00
Michael Goulet
3fceca23bb Remove mitigations for incorrect node args 2023-12-29 05:16:53 +00:00
bors
ac4c2094a6 Auto merge of #12038 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-12-28 18:25:36 +00:00
Philipp Krones
2a4c7d2b0f
Bump Clippy version -> 0.1.77 2023-12-28 19:21:01 +01:00
Philipp Krones
887278c40a
Bump nightly version -> 2023-12-28 2023-12-28 19:20:40 +01:00
Philipp Krones
9ff84af787
Merge remote-tracking branch 'upstream/master' into rustup 2023-12-28 19:20:18 +01:00