Commit graph

1346 commits

Author SHA1 Message Date
AurelienFT
c86b19f1ef Add lint to check manual pattern char comparison and merge its code with single_char_pattern lint 2024-06-11 21:56:14 +02:00
bors
336046c5e2 Auto merge of #12889 - xFrednet:changelog-1-79, r=flip1995,dswij
Changelog for Clippy 1.79 🎓

Two cat ears from waffle,
A tail and a dress,
That's our Jyn,
The magnificent cat

~ =^.^=

---

### The cat of this release is: *Jyn* submitted by `@jyn514:`

<img height=600 src="https://github.com/rust-lang/rust-clippy/assets/17087237/2f902dea-9ad5-4ad2-b281-1f152b7ad7c7" alt="The cat(s) of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none
2024-06-07 10:02:32 +00:00
bors
6cfd4ac955 Auto merge of #10632 - Alexendoo:needless-maybe-sized, r=Jarcho
Add `needless_maybe_sized` lint

changelog: new lint: [`needless_maybe_sized`]

Closes #10600
2024-06-05 20:11:03 +00:00
xFrednet
a0e407c7c2
Address PR feedback <3 2024-06-05 16:26:51 +02:00
xFrednet
466acfa650
Changelog for Clippy 1.79 🎓 2024-06-05 14:02:11 +02:00
bors
61d3e14718 Auto merge of #12815 - GuillaumeGomez:add-needless_character_iteration, r=xFrednet
Add `needless_character_iteration` lint

Fixes #4817.

r? `@xFrednet`

changelog: Add `needless_character_iteration` lint
2024-06-03 08:09:18 +00:00
Guillaume Gomez
566dfd9008 Add needless_character_iteration lint 2024-05-27 14:16:02 +02:00
bors
2efebd2f0c Auto merge of #12765 - yusufraji:while-float, r=llogiq
Add new lint `while_float`

This PR adds a nursery lint that checks for while loops comparing floating point values.

changelog:
```
changelog: [`while_float`]: Checks for while loops comparing floating point values.
```

Fixes #758
2024-05-21 11:36:31 +00:00
Daniel Sedlak
c342a61564 Add configuration option for ignoring panic!() in tests 2024-05-16 05:45:56 +00:00
y21
9747c80644 new lint: macro_metavars_in_unsafe 2024-05-12 17:03:30 +02:00
bors
7cfb9a0d6f Auto merge of #11540 - J-ZhengLi:issue11443, r=xFrednet
add new lint that disallow renaming parameters in trait functions

fixes: #11443
fixes: #486

changelog: add new lint [`renamed_function_params`]

Note that the lint name is not final, because I have a bad reputation in naming things, and I don't trust myself.
2024-05-12 14:21:22 +00:00
J-ZhengLi
46659acdbd add configuration to allow skipping on some certain traits & collect metadata 2024-05-12 22:13:17 +08:00
J-ZhengLi
28d5115067 add new lint that disallow renaming parameters in trait functions 2024-05-07 10:49:02 +08:00
Michael Howell
f3dd31e214 Add lint for markdown lazy paragraph continuations
This is a follow-up for https://github.com/rust-lang/rust/pull/121659,
since most cases of unintended block quotes are lazy continuations.
The lint is designed to be more generally useful than that, though,
because it will also catch unintended list items and unintended
block quotes that didn't coincidentally hit a pulldown-cmark bug.
2024-05-06 16:31:21 -07:00
Yusuf Raji
c9ea0ae502 Lint while loops with float comparison 2024-05-06 00:04:00 +02:00
Fridtjof Stoldt
5c23f138dd
Apply suggestions from code review <3
Co-authored-by: Timo <30553356+y21@users.noreply.github.com>
2024-05-02 12:15:08 +02:00
xFrednet
7ac1529ff6
Changelog for Clippy 1.78 🪄 2024-04-29 22:01:33 +02:00
Andre Bogus
87efce4fa2 configurably allow useless_vec in tests
This adds a `àllow-useless-vec-in-test` configuration which, when set
to `true` will allow the `useless_vec` lint in `#[test]` functions and
code within `#[cfg(test)]`. It also moves a `is_in_test` helper to
`clippy_utils`.
2024-04-28 22:07:56 +02:00
Alex Macleod
cf0b55eb62 Add needless_maybe_sized lint 2024-04-14 14:43:03 +00:00
modelflat
3705073a71 Recognize common prefixes when checking for items with module name suffix
Fixes #12544.

- don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`).
- configured by `allowed-prefixes` config entry
- prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`]
- update docs
2024-04-09 09:47:54 +02:00
bors
cebf879de8 Auto merge of #12312 - pitaj:legacy_numeric_constants, r=xFrednet
new lint `legacy_numeric_constants`

Rework of #10997

- uses diagnostic items
- does not lint imports of the float modules (`use std::f32`)
- does not lint usage of float constants that look like `f32::MIN`

I chose to make the float changes because the following pattern is actually pretty useful
```rust
use std::f32;
let omega = freq * 2 * f32::consts::PI;
```
and the float modules are not TBD-deprecated like the integer modules.

Closes #10995

---

changelog: New lint [`legacy_numeric_constants`]
[#12312](https://github.com/rust-lang/rust-clippy/pull/12312)
2024-03-30 17:50:36 +00:00
bors
95c62ffae9 Auto merge of #12239 - GuillaumeGomez:missing_transmute_annotation, r=y21
Add `missing_transmute_annotations` lint

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

r? `@blyxyas`

changelog: Add `missing_transmute_annotations` lint
2024-03-24 00:20:28 +00:00
Catherine
0c392d918a new lint legacy_numeric_constants 2024-03-21 17:10:02 -06:00
xFrednet
87d45e5e2c
Changelog for Clippy 1.77 🏫 2024-03-19 11:55:20 +01:00
Guillaume Gomez
79766577f2 Add missing_transmute_annotation lint 2024-03-15 20:31:51 +01:00
Jacherr
edcf10e2f7 update_lints 2024-03-11 22:55:31 +00:00
Jacherr
100ab4993e new restriction lint: division_remainder_used 2024-03-11 22:51:03 +00:00
bors
f685a4b3f1 Auto merge of #12378 - GuillaumeGomez:duplicated_attr, r=blyxyas
Add new `duplicated_attributes` lint

It's a lint idea that `@llogiq` gave me while reviewing another PR.

There are some limitations, in particular for the "output". Initially I wanted to make it possible for directly lint against the whole attribute if its parts were all duplicated, but then I realized that the output would be chaotic if the duplicates were coming from different attributes, so I preferred to go to the simplest way and simply emit a warning for each entry. Not the best, but makes the implementation much easier.

Another limitation is that `cfg_attr` would be a bit more tricky to implement because we need to check if two `cfg` sets are exactly the same. I added a FIXME and will likely come back to it later.

And finally, I updated the `cargo dev update_lints` command because the generated `tests/ui/rename.rs` file was emitting the `duplicated_attributes` lint, so I allowed this lint inside it to prevent it from working.

changelog: Add new `duplicated_attributes` lint
2024-03-11 18:36:21 +00:00
Guillaume Gomez
98ac5f1e8c Rename into manual_unwrap_or_default 2024-03-10 01:23:28 +01:00
Guillaume Gomez
1abf4418f8 Add new match_option_and_default lint 2024-03-10 01:15:22 +01:00
Jacherr
0e59259add add new lint zero_repeat_side_effects 2024-03-09 18:53:14 +00:00
Guillaume Gomez
f34804d807 Add new duplicated_attributes lint 2024-03-09 12:43:18 +01:00
bors
453242cbde Auto merge of #12310 - samueltardieu:issue-12307, r=xFrednet
New lint `const_is_empty`

This lint detects calls to `.is_empty()` on an entity initialized from a string literal and flag them as suspicious. To avoid triggering on macros called from generated code, it checks that the `.is_empty()` receiver, the call itself and the initialization come from the same context.

Fixes #12307

changelog: [`const_is_empty`]: new lint
2024-03-09 09:56:37 +00:00
Jakub Beránek
e3cda2a399
Update lints 2024-03-01 16:35:28 +01:00
bors
00ff8c92d3 Auto merge of #12354 - GuillaumeGomez:mixed_attributes_style, r=llogiq
Add new `mixed_attributes_style` lint

Add a new lint to detect cases where both inner and outer attributes are used on a same item.

r? `@llogiq`

----

changelog: Add new [`mixed_attributes_style`] lint
2024-02-29 11:44:51 +00:00
bors
04b74ee392 Auto merge of #12344 - CBSpeir:alphabetize-affected-lints, r=flip1995
Alphabetize configuration options and lints in Clippy documentation

changelog: alphabetize configuration options and affected lints listed in section 3.1. of the Clippy Documentation

r? blyxyas
2024-02-29 11:15:53 +00:00
Guillaume Gomez
9f4a58f616 Add new mixed_attributes_style lint 2024-02-27 15:22:39 +01:00
Christopher B. Speir
d85642e6e8 Alphabetize configuration options and lints in Clippy doc 2024-02-26 14:55:45 -06:00
bors
1c5094878b Auto merge of #12342 - lucarlig:empty-docs, r=llogiq
Empty docs

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

changelog: [`empty_doc`]: Detects documentation that is empty.
changelog: Doc comment lints now trigger for struct field and enum variant documentation
2024-02-26 18:03:13 +00:00
Samuel Tardieu
dbfbd0e77f feat: add const_is_empty lint 2024-02-26 08:51:28 +01:00
lucarlig
3093b291f6 WIP: empty doc span is still broken 2024-02-25 09:55:58 +04:00
Guillaume Gomez
ad319484f1 Add new unnecessary_get_then_check clippy lint 2024-02-24 15:02:10 +01:00
bors
a2c1d565e5 Auto merge of #12259 - GuillaumeGomez:multiple-bound-locations, r=llogiq
Add new `multiple_bound_locations` lint

Fixes #7181.

r? `@llogiq`

changelog: Add new `multiple_bound_locations` lint
2024-02-24 13:43:34 +00:00
Guillaume Gomez
d654acd554 Add new multiple_bound_locations lint 2024-02-23 13:22:21 +01:00
Guillaume Gomez
f35d87f211 Add unneeded_clippy_cfg_attr lint 2024-02-22 11:52:58 +01:00
Philipp Krones
4363278c73 Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into clippy-subtree-update 2024-05-21 10:39:30 -07:00
Philipp Krones
80c6f8ff7b Merge commit '20b085d500dfba5afe0869707bf357af3afe20be' into clippy-subtree-update 2024-05-02 17:26:44 +02:00
Philipp Krones
a5aaf33422 Merge commit 'ca3b393750ee8d870bf3215dcf6509cafa5c0445' into clippy-subtree-update 2024-04-18 17:48:52 +02:00
Philipp Krones
0ae4a048c6 Merge commit '9725c4a162502a02c1c67fdca6b797fe09b2b73c' into clippy-subtree-update 2024-04-04 19:52:55 +02:00
Philipp Krones
0e62b18435 Merge commit '9d6f41691ed9dbfaec2a2df2661c42451f2fe0d3' into clippy-subtree-update 2024-03-21 22:20:40 +01:00
Philipp Krones
7e83df4068 Merge commit '93f0a9a91f58c9b2153868f458402155fb6265bb' into clippy-subtree-update 2024-03-07 17:19:29 +01:00
Philipp Krones
7be6e2178e Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into clippy-subtree-update 2024-02-27 15:50:17 +01:00
bors
32c006ca94 Auto merge of #12292 - GuillaumeGomez:DEPRECATED_CLIPPY_CFG_ATTR, r=flip1995
Add new lint `DEPRECATED_CLIPPY_CFG_ATTR`

As discussed [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Is.20.60--cfg.20feature.3Dcargo-clippy.60.20deprecated.20or.20can.20it.20be.3F).

This lint suggests to replace `feature = "cargo-clippy"` with `clippy`.

r? `@flip1995`

changelog:  Add new lint `DEPRECATED_CLIPPY_CFG_ATTR`
2024-02-16 10:24:15 +00:00
Guillaume Gomez
f35eec867a Add new lint DEPRECATED_CLIPPY_CFG_ATTR 2024-02-15 00:40:43 +01:00
Philipp Krones
f3b3d23416 Merge commit '60cb29c5e4f9772685c9873752196725c946a849' into clippyup 2024-02-08 20:24:42 +01:00
Yuri Astrakhan
36f7248da0
Fix release year in CHANGELOG.md 2024-02-06 02:43:34 -05:00
y21
7f80b449f5 new lint: manual_c_str_literals 2024-02-05 18:51:49 +01:00
bors
8baeb26754 Auto merge of #12224 - xFrednet:chaneglog-1-76, r=Manishearth
Changelog for Clippy 1.76 🐈

Roses are red,
Violets are blue,
So many cute cats,
How to choose?

---

### The cat of this release is: *Cabrel* submitted by `@daniel-g-gagnon:`

<img height=500 src="https://github.com/rust-lang/rust-clippy/assets/17087237/41aea3dc-7935-4dfe-80ff-a6efd92f76ab" alt="The cats of this Clippy release" />

The cat for the next release can be voted on: [here](https://docs.google.com/forms/d/e/1FAIpQLSfERam31AEi3_5uVsugi1-JHGF9Po1oC7OIiLs8jglprZNy_g/viewform)

The cat for the next next release can be nominated in the comments and will be voted in the next changelog PR (Submission deadline is 2024-02-06 23:59CET)

---

changelog: none
2024-02-05 08:44:34 +00:00
bors
34e4c9fa4a Auto merge of #12087 - marcin-serwin:ref_as_ptr_cast, r=blyxyas
Add new lint: `ref_as_ptr`

Fixes #10130

Added new lint `ref_as_ptr` that checks for conversions from references to pointers and suggests using `std::ptr::from_{ref, mut}` instead.

The name is different than suggested in the issue (`as_ptr_cast`) since there were some other lints with similar names (`ptr_as_ptr`, `borrow_as_ptr`) and I wanted to follow the convention.

Note that this lint conflicts with the `borrow_as_ptr` lint in the sense that it recommends changing `&foo as *const _` to `std::ptr::from_ref(&foo)` instead of `std::ptr::addr_of!(foo)`. Personally, I think the former is more readable and, in contrast to `addr_of` macro, can be also applied to temporaries (cf. #9884).

---

changelog: New lint: [`ref_as_ptr`]
[#12087](https://github.com/rust-lang/rust-clippy/pull/12087)
2024-02-04 17:07:18 +00:00
Marcin Serwin
a3baebcb31
Add ref_as_ptr lint
Author:    Marcin Serwin <marcin.serwin0@protonmail.com>
2024-02-04 17:38:09 +01:00
xFrednet
aa1de4d556
Changelog for Clippy 1.76 🐈 2024-02-04 16:31:01 +01:00
bors
c82162eb71 Auto merge of #11979 - J-ZhengLi:issue11428, r=Alexendoo
add configuration for [`wildcard_imports`] to ignore certain imports

fixes: #11428

changelog: add configuration `ignored-wildcard-imports` for lint [`wildcard_imports`]
2024-02-02 21:28:49 +00:00
J-ZhengLi
46dd8263a0 rename conf option to allowed_wildcard_imports 2024-02-02 09:22:42 +08:00
Alex Macleod
6619e8c27d Add lint_groups_priority lint
Warns when a lint group in Cargo.toml's `[lints]` section shares the
same priority as a lint
2024-01-31 18:33:41 +00:00
bors
85e08cd3b9 Auto merge of #12169 - GuillaumeGomez:unnecessary_result_map_or_else, r=llogiq
Add new `unnecessary_result_map_or_else` lint

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

r? `@llogiq`

changelog: Add new `unnecessary_result_map_or_else` lint
2024-01-27 12:42:18 +00:00
bors
79f10cf364 Auto merge of #12122 - andrewbanchich:tostring-impl, r=llogiq
add to_string_trait_impl lint

closes #12076

changelog: [`to_string_trait_impl`]: add lint for direct `ToString` implementations
2024-01-27 12:31:18 +00:00
bors
855aa08de5 Auto merge of #12178 - mdm:modulo-arithmetic-comparison-to-zero, r=llogiq
Don't warn about modulo arithmetic when comparing to zero

closes #12006

By default, don't warn about modulo arithmetic when comparing to zero. This behavior is configurable via `clippy.toml`.

See discussion [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.E2.9C.94.20Is.20issue.20.2312006.20worth.20implementing.3F)

changelog: [`modulo_arithmetic`]: By default don't lint when comparing the result of a modulo operation to zero.
2024-01-27 12:22:48 +00:00
Andrew Banchich
6d76d14565 add to_string_trait_impl lint 2024-01-26 19:28:54 -05:00
Guillaume Gomez
14e15206ed Warn if an item coming from more recent version than MSRV is used 2024-01-26 14:13:02 +01:00
Philipp Krones
798865c593 Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into clippy-subtree-update 2024-01-25 19:17:36 +01:00
Marc Dominik Migge
e456c28e11 Don't warn about modulo arithmetic when comparing to zero
Add lint configuration for `modulo_arithmetic`

Collect meta-data
2024-01-25 12:42:53 +01:00
Guillaume Gomez
e86da9eca3 Update CHANGELOG 2024-01-23 16:12:56 +01:00
y21
95a084f2eb [multiple_crate_versions]: add a configuration option for allowed duplicate dependencies 2024-01-21 03:23:41 +01:00
atwam
6c201db005
Add suspicious_open_options lint.
Checks for the suspicious use of OpenOptions::create()
without an explicit OpenOptions::truncate().

create() alone will either create a new file or open an
existing file. If the file already exists, it will be
overwritten when written to, but the file will not be
truncated by default. If less data is written to the file
than it already contains, the remainder of the file will
remain unchanged, and the end of the file will contain old
data.
In most cases, one should either use `create_new` to ensure
the file is created from scratch, or ensure `truncate` is
called so that the truncation behaviour is explicit.
`truncate(true)` will ensure the file is entirely overwritten
with new data, whereas `truncate(false)` will explicitely
keep the default behavior.

```rust
use std::fs::OpenOptions;

OpenOptions::new().create(true).truncate(true);
```
2024-01-15 17:15:08 +00:00
Philipp Krones
aa220c7ee7 Merge commit '26ac6aab023393c94edf42f38f6ad31196009643' 2024-01-11 17:27:03 +01:00
y21
5960107415 new lint: option_as_ref_cloned 2024-01-03 19:40:47 +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
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
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
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
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
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
Philipp Krones
15b1edb209 Merge commit 'ac4c2094a6030530661bee3876e0228ddfeb6b8b' into clippy-subtree-sync 2023-12-28 19:33:07 +01:00
bors
c689d32a90 Auto merge of #11981 - y21:eager_int_transmute, r=llogiq
new lint: `eager_transmute`

A small but still hopefully useful lint that looks for patterns such as `(x < 5).then_some(transmute(x))`.
This is almost certainly wrong because it evaluates the transmute eagerly and can lead to surprises such as the check being completely removed and always evaluating to `Some` no matter what `x` is (it is UB after all when the integer is not a valid bitpattern for the transmuted-to type). [Example](https://godbolt.org/z/xoY34fPzh).
The user most likely meant to use `then` instead.

I can't remember where I saw this but this is inspired by a real bug that happened in practice.

This could probably be a correctness lint?

changelog: new lint: [`eager_int_transmute`]
2023-12-27 15:16:46 +00:00
y21
08d8ca9edd new lint: eager_int_transmute 2023-12-27 14:16:35 +01:00
Yuxiang Qiu
c4a80f2e3e
feat: add manual_is_variant_and lint 2023-12-26 17:49:51 -07:00
bors
cda17014fa Auto merge of #12022 - xFrednet:changelog-1-75, r=llogiq
Fix typo in changelog for 1.75

Roses are red,
violets are blue,
another typo fixed,
thanks to you `@llogiq`

---

r? `@llogiq`

changelog: none
2023-12-26 20:34:01 +00:00
xFrednet
ae4ab9e369
Fix typo in changelog for 1.75 2023-12-26 20:52:05 +01:00
bors
eb679c7f34 Auto merge of #12019 - xFrednet:changelog-1-75, r=flip1995
Changelog for Rust 1.75 🎄

Roses are red,
Violets are blue,
Another year of development,
And a strong team, too

---

### The cat of this release:

<img width=500 src="https://cdn2.thecatapi.com/images/49r.gif?api_key=live_iA7QQQ2LdohvDfCghXThmLqVYCZ9kXIwGMcwyJyaYyOTRC8NZSYqykPoc2UypsMi" alt="The cats of this Clippy release" />

<sub>The cat for the next release can be nominated in the comments</sub>

---

changelog: none
2023-12-26 19:23:16 +00:00
xFrednet
2087e24338
Changelog for Rust 1.75 🎄 2023-12-26 16:09:06 +01:00
Quinn Sinclair
25b9ca3f64 New lints iter_filter_is_some and iter_filter_is_ok
Adds a pair of lints that check for cases of an iterator over `Result`
and `Option` followed by `filter` without being followed by `map` as
that is covered already by a different, specialized lint.

changelog: New Lint: [`iter_filter_is_some`]
changelog: New Lint: [`iter_filter_is_ok`]
2023-12-21 00:16:47 +02:00
bors
f9b5def2ae Auto merge of #11869 - PartiallyTyped:result-filter-map, r=Alexendoo
New Lint: `result_filter_map` / Mirror of `option_filter_map`

Added the `Result` mirror of `option_filter_map`.

changelog: New Lint: [`result_filter_map`]

I had to move around some code because the function def was too long 🙃.

I have also added some pattern checks on `option_filter_map`
2023-12-16 23:29:07 +00:00
bors
9907b90b1e Auto merge of #11938 - GuillaumeGomez:unconditional_recursion, r=llogiq
Add new `unconditional_recursion` lint

Currently, rustc `unconditional_recursion` doesn't detect cases like:

```rust
enum Foo {
    A,
    B,
}

impl PartialEq for Foo {
    fn eq(&self, other: &Self) -> bool {
        self == other
    }
}
```

This is because the lint is currently implemented only for one level, and in the above code, `self == other` will then call `impl PartialEq for &T`, escaping from the detection. The fix for it seems to be a bit tricky (I started investigating potential solution to add one extra level of recursion [here](https://github.com/rust-lang/rust/compare/master...GuillaumeGomez:rust:trait-impl-recursion?expand=1) but completely broken at the moment).

I expect that this situation will remain for a while. In the meantime, I think it's acceptable to check it directly into clippy for the time being as a lot of easy cases like this one can be easily checked (next I plan to extend it to cover other traits like `ToString`).

changelog: Add new `unconditional_recursion` lint
2023-12-16 18:21:01 +00:00
Philipp Krones
3596d44988 Merge commit 'a859e5cc1ce100df22346a1005da30532d04de59' into clippyup 2023-12-16 14:12:50 +01:00
Quinn Sinclair
8892420aa7 New Lint: Result_filter_map
Added the `Result` mirror of `option_filter_map` to catch

```
   .into_iter().filter(Result::is_ok).map(Result::unwrap)
```

changelog: New Lint: [`result_filter_map`]
Co-authored-by: Alex Macleod <alex@macleod.io>
2023-12-16 00:43:52 +01:00
bors
2e96c74dce Auto merge of #11829 - J-ZhengLi:issue11438, r=matthiaskrgr
new lint to detect infinite loop

closes: #11438

changelog: add new lint to detect infinite loop

~*I'll change the lint name*~. Should I name it  `infinite_loop` or `infinite_loops` is fine? Ahhhh, English is hard...
2023-12-12 17:53:51 +00:00
Guillaume Gomez
91fd01c31c Add changelog for unconditional_recursion 2023-12-12 15:37:51 +01:00
Guillaume Gomez
ded94ecf65 Update CHANGELOG to add write_and_append lint 2023-12-12 14:56:35 +01:00
bors
2a1645d009 Auto merge of #11878 - samueltardieu:uninhabited_reference, r=flip1995
uninhabited_reference: new lint

Close #11851

The lint is implemented on function parameters and return types, as this is the place where the risk of exchanging references to uninhabited types is the highest. Other constructs, such as in a local variable,
would require the use of `unsafe` and will clearly be done on purpose.

changelog: [`uninhabited_reference`]: new lint
2023-12-11 09:28:54 +00:00
Samuel Tardieu
cdfa38a9d1 new lint: uninhabited_reference 2023-12-08 17:21:30 +01:00