Commit graph

1189 commits

Author SHA1 Message Date
y21
08d8ca9edd new lint: eager_int_transmute 2023-12-27 14:16:35 +01: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
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
bors
75bdbfcea5 Auto merge of #11853 - J-ZhengLi:issue11814, r=llogiq
expending lint [`blocks_in_if_conditions`] to check match expr as well

closes: #11814

changelog: rename lint `blocks_in_if_conditions` to [`blocks_in_conditions`] and expand it to check blocks in match scrutinees
2023-12-02 14:03:46 +00:00
y21
504941591f new lint: repeat_vec_with_capacity 2023-12-01 16:52:34 +01:00
J-ZhengLi
40b558af76 rename [blocks_in_if_conditions] to [blocks_in_conditions];
add more test cases with `match`;
minor fixes in message output regarding review feedback
2023-11-30 15:41:54 +08:00
Andre Bogus
0ba9bf9f9a add lint against unit tests in doctests 2023-11-28 21:29:08 +01:00
J-ZhengLi
758d0e8661 change name to [infinite_loop];
& apply review suggestions;
2023-11-28 10:28:55 +08:00
Guillaume Gomez
ef38969e06 Update changelog to add new option_map_or_err_ok lint 2023-11-24 18:14:34 +01:00
Guillaume Gomez
abd9deb9f4 [missing_safety_doc], [unnecessary_safety_doc], [missing_panics_doc], [missing_errors_doc]: Added the [check-private-items] configuration to enable lints on private items.
[#11842](https://github.com/rust-lang/rust-clippy/pull/11842)
2023-11-21 11:42:42 +01:00
ofeeg
34d9e88a47
New lint clippy::join_absolute_paths
* `join_absolute_paths` Address PR review
* Move `clippy::join_absolute_paths` to `clippy::suspicious`
* `join_absolute_paths`: Address PR review

Co-Authored-By: ofeeg <mhanna0000@gmail.com>
2023-11-20 13:28:28 +01:00
Quinn Sinclair
3c1e0afa58 New Lint [impl_hash_with_borrow_str_and_bytes]
Implements a lint to prevent implementation of Hash, Borrow<str> and
Borrow<[u8]> as it breaks Borrow<T> "semantics". According to the book,
types that implement Borrow<A> and Borrow<B> must ensure equality of
borrow results under Eq,Ord and Hash.

> In particular Eq, Ord and Hash must be equivalent for borrowed and
owned values: x.borrow() == y.borrow() should give the same result as x == y.

In the same way, hash(x) == hash(x as Borrow<[u8]>) != hash(x as Borrow<str>).

changelog: newlint [`impl_hash_with_borrow_str_and_bytes`]
2023-11-19 11:33:01 +01:00
J-ZhengLi
2d9fc6dfc8 implement unoptimized code logic for [infinite_loops] 2023-11-17 18:10:50 +08:00
xFrednet
cab975c713
Changelog for Rust 1.74 🎃 2023-11-14 18:08:00 +01:00
Jacherr
cb90674aed add iter_over_hash_type lint 2023-11-11 00:20:47 +00:00
Dinu Blanovschi
0b90f72064 feat: unused_enumerate_index lint 2023-10-31 17:53:24 +01:00
y21
69c3b9c252 new lint: unnecessary_fallible_conversions 2023-10-30 20:54:24 +01:00
Benoît du Garreau
f8790963d9 Add a lint to check needless Waker clones 2023-10-24 09:58:23 +02:00
jonboh
8b02dac542 add lint for struct field names
side effect for `enum_variants`:
use .first() instead of .get(0) in enum_variants lint
move to_camel_case to str_util module
move module, enum and struct name repetitions check to a single file `item_name_repetitions`
rename enum_variants threshold config option
2023-10-18 19:20:08 +02:00
xFrednet
404217e631
Address PR Review <3 2023-10-04 10:28:52 +02:00
xFrednet
948355586f
sudo CI=green 2023-10-04 01:19:38 +02:00
xFrednet
8d920a8b03
Changelog for Rust 1.73 🖊️ 2023-10-04 01:09:46 +02:00
y21
8eb586d154 new lint: into_iter_without_iter 2023-09-30 19:38:16 +02:00
y21
330ebbb9f9 new lint: iter_without_into_iter 2023-09-28 22:22:36 +02:00
Alex Macleod
ec2f62677f Add manual_hash_one lint 2023-09-26 13:49:15 +00:00
Dev381
1c9f3bef8b Add redundant_as_str lint
This lint checks for `as_str` on a `String` immediately followed by `as_bytes` or `is_empty` as those methods are available on `String` too. This could possibly also be extended to `&[u8]` in the future.
2023-09-17 17:50:45 -04:00
bors
251a475b72 Auto merge of #11511 - Jarcho:split_borrow, r=llogiq
Split `needless_borrow` into two lints

Splits off the case where the borrow is used as a generic argument to a function. I think the two cases are different  enough to warrant a separate lint.

The tests for the new lint have been reordered to group related parts together. Two warning have been dropped, one looked like it was testing the generic argument form, but it ends up triggering the auto-deref variant. The second was just a redundant test that didn't do anything interesting.

An issue with cycle detection is also included. The old version was checking if a cycle was reachable from a block when it should have been checking if the block is part or a cycle.

As a side note, I'm liking the style of just jamming all the tests into separate scopes in main.

changelog: Split off `needless_borrows_for_generic_args` from `needless_borrow`
2023-09-17 13:48:40 +00:00
Jason Newcomb
79247d95f7 Split part of needless_borrow into needless_borrows_for_generic_args 2023-09-17 09:48:12 -04:00
y21
981e96008b new lint: path_ends_with_ext 2023-09-15 16:17:51 +02:00
jonboh
f136e1634a new unnecessary_map_on_constructor lint 2023-09-12 17:32:11 +02:00
Alex Macleod
b99921a5e8 Rename incorrect_impls to non_canonical_impls, move them to warn by default 2023-09-08 13:15:51 +00:00
y21
b54bac9f14 new lint: missing_assert_for_indexing 2023-08-31 17:44:19 +02:00
bors
c50d86fc6a Auto merge of #11418 - Benjscho:explicit_iter_loop_config, r=llogiq
Add config flag for reborrows in explicit_iter_loop

This PR adds a config flag for enforcing explicit into iter lint for reborrowed values. The config flag, `enforce_iter_loop_reborrow`, can be added to clippy.toml files to enable the linting behaviour. By default the reborrow lint is disabled.

fixes: #11074

changelog: [`explicit_iter_loop`]: add config flag `enforce_iter_loop_reborrow` to disable reborrow linting by default
2023-08-31 11:19:04 +00:00
Ben Schofield
55bd0fe296 Fix metadata collection 2023-08-30 16:02:37 -07:00
bors
3da21b089f Auto merge of #11396 - y21:issue11345, r=Jarcho
new lint: `iter_out_of_bounds`

Closes #11345

The original idea in the linked issue seemed to be just about arrays afaict, but I extended this to catch some other iterator sources such as `iter::once` or `iter::empty`.

I'm not entirely sure if this name makes a lot of sense now that it's not just about arrays anymore (specifically, not sure if you can call `.take(1)` on an `iter::Empty` to be "out of bounds"?).

changelog: [`iter_out_of_bounds`]: new lint
2023-08-30 19:51:32 +00:00
xFrednet
fe38aaad66
Update changelog stable note 2023-08-24 20:41:26 +02:00
y21
86b6644379 new lint: iter_out_of_bounds 2023-08-24 20:21:55 +02:00
y21
09506f49c1 rename lint, docs, improve diagnostics 2023-08-23 17:06:55 +02:00
y21
42bd6d7af3 new lint: implied_bounds_in_impl 2023-08-23 17:05:55 +02:00
Red Rapious
7fbf808a50 Added new lint: reserve_after_initialization 2023-08-21 18:50:53 +02:00
y21
e52bd6f850 new lint: should_panic_without_expect 2023-08-18 18:57:14 +02:00
xFrednet
8f06b19b45
Changelog for Rust 1.72 🏖️ 2023-08-18 18:27:11 +02:00
Morten Lohne
1d61fc1b0a Rename 'impossible_double_const_comparisons' -> 'impossible_comparisons' and 'ineffective_double_const_comparisons' -> 'redundant_comparisons', after discussion on Zulip 2023-08-05 21:28:08 +02:00
Morten Lohne
046d3df35e New lints: impossible_double_const_comparisons and ineffective_double_const_comparisons 2023-08-05 21:28:08 +02:00