Commit Graph

18627 Commits

Author SHA1 Message Date
y21
6c28f0765e recognize contains calls on ranges 2023-12-28 05:27:56 +01:00
y21
affde93041 lint on nested binary operations involving local and handle projections 2023-12-27 23:38:20 +01:00
bors
7343db9ce3 Auto merge of #12029 - torfsen:6459-more-cases-for-redundant-matches!, r=llogiq
6459: Check for redundant `matches!` with `Ready`, `Pending`, `V4`, `V6`

Fixes #6459.

```
changelog: [`redundant_pattern_matching`]: Add checks for `Poll::{Ready,Pending}` and `IpAddr::{V4,V6}` in `matches!`
```
2023-12-27 19:55:39 +00:00
Florian Brucker
ebc0588937 6459: Check for redundant matches! with Ready, Pending, V4, V6 2023-12-27 19:10:04 +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
bors
677f8d8a3c Auto merge of #12018 - waywardmonkeys:doc-markdown-allow-webgpu-webgl2, r=blyxyas
[doc_markdown]: Add "WebGL2", "WebGPU" to default `doc_valid_idents`

changelog: [`doc_markdown`]: Add "WebGL2", "WebGPU" to default `doc_valid_idents`
2023-12-27 11:26:36 +00:00
Bruce Mitchener
f48b850c65 [doc_markdown]: Add "WebGL2", "WebGPU" to default doc_valid_idents 2023-12-26 16:58:43 -05: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
bors
9dd2252b2c Auto merge of #12004 - PartiallyTyped:11843, r=xFrednet
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.

Fixes #11843

PS, I also made some minor documentations fixes in a case where a double tick (`) was included.

---

changelog: New Lint: [`iter_filter_is_some`]
[#12004](https://github.com/rust-lang/rust/pull/12004)
changelog: New Lint: [`iter_filter_is_ok`]
[#12004](https://github.com/rust-lang/rust/pull/12004)
2023-12-26 15:41:40 +00:00
xFrednet
2087e24338
Changelog for Rust 1.75 🎄 2023-12-26 16:09:06 +01:00
xFrednet
8990153997
Update version attribute for 1.75 lints 2023-12-26 16:00:53 +01:00
bors
99c783843d Auto merge of #11967 - samueltardieu:issue-11959, r=llogiq
Do not consider `async { (impl IntoFuture).await }` as redundant

changelog: [`redundant_async_block`]: do not trigger on `IntoFuture` instances

Fix #11959
2023-12-25 12:42:26 +00:00
bors
5ab2319898 Auto merge of #12011 - blyxyas:not-on-vacation, r=blyxyas
Remove me from `users_on_vacation`

Came back from surgery about 2 days ago, totally cool to review some more PRs.

changelog:none
r? ghost
2023-12-25 12:00:41 +00:00
blyxyas
c1c52e9049
Remove blyxyas from users_on_vacation 2023-12-25 12:52:08 +01:00
Quinn Sinclair
85e1646afc more tests 2023-12-24 17:32:00 +02:00
Quinn Sinclair
2177f2cb96 formatting 2023-12-24 14:42:18 +02:00
Quinn Sinclair
4b1ac31c18 Added MSRV and more tests, improved wording 2023-12-24 14:40:14 +02:00
bors
370615bc78 Auto merge of #11997 - TethysSvensson:uninhabited-references-pedantic, r=xFrednet
Move `uninhabited_references` to `nursery`

I think this lint has too many false positives and should be put in pedantic. See #11984 and #11985 for context.

The lint is already in beta and is causing trouble for us, so I would also like this PR to be backported to beta as well.

changelog: Moved [`uninhabited_references`] to `nursery` (Now allow-by-default)
[#11997](https://github.com/rust-lang/rust-clippy/pull/11997)
(Check if this has been backported)

Fixes #11984.
2023-12-23 16:25:53 +00:00
bors
830f1c58f4 Auto merge of #11994 - y21:issue11993-fn, r=xFrednet
[`question_mark`]: also trigger on `return` statements

This fixes the false negative mentioned in #11993: the lint only used to check for `return` expressions, and not a statement containing a `return` expression (doesn't close the issue tho since there's still a useful suggestion that we could make, which is to suggest `.ok_or()?`/`.ok_or_else()?` for `else { return Err(..) }`)

changelog: [`question_mark`]: also trigger on `return` statements
2023-12-23 16:17:35 +00:00
Tethys Svensson
1576ecce40 Move uninhabited_references to nursery 2023-12-23 17:00:14 +01:00
y21
e44caea259 respect comments in question_mark 2023-12-23 16:22:12 +01:00
y21
dfb4ff8bbf [question_mark]: also trigger on return statements 2023-12-23 16:22:08 +01:00
bors
618fd4b494 Auto merge of #11999 - Takashiidobe:fix-typo-in-infinite-loop-lint, r=xFrednet
fix typo in infinite loop lint

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: This fixes a small typo introduced in https://github.com/rust-lang/rust-clippy/pull/11829
2023-12-23 14:46:52 +00:00
bors
858d96d63a Auto merge of #11871 - GuillaumeGomez:UNNECESSARY_TO_OWNED-split, r=llogiq
Extend `UNNECESSARY_TO_OWNED` to handle `split`

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

When you have `to_string().split('a')` or equivalent, it'll suggest to remove the `to_owned`/`to_string` part.

r? `@flip1995`

changelog: Extend `UNNECESSARY_TO_OWNED` to handle `split`
2023-12-23 11:36:53 +00:00
bors
2ddcfb8531 Auto merge of #12000 - Takashiidobe:fix-some-typos, r=llogiq
Fixing some other typos

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: none
2023-12-23 10:01:15 +00:00
Takashi Idobe
3a4d99ec42 run cargo uibless 2023-12-22 19:02:22 -05:00
Takashi Idobe
9c2be205b3 fix typos in default constructed unit structs, implied bounds, ineffective open options 2023-12-22 18:54:48 -05:00
Takashi Idobe
67a33e8cc8 fix typo in infinite loop lint 2023-12-22 18:44:20 -05:00
bors
e0b25c5a64 Auto merge of #11998 - cocodery:fix/issue11762, r=llogiq
Check whether out of bound when access a known length array with a constant index

fixes [Issue#11762](https://github.com/rust-lang/rust-clippy/issues/11762)

Issue#11762 points that `Array references with known length are not flagged when indexed out of bounds`.

To fix this problem, it is needed to add check for `Expr::Index`. We expand this issue include reference and direct accessing a array.

When we access a array with a constant index `off`, and already know the length `size`, if `off >= size`, these code will throw an error, instead rustc's lint checking them or runtime panic happening.

changelog: [`out_of_bound_indexing`]: Add check for illegal accessing known length array with a constant index
2023-12-22 17:01:17 +00:00
cocodery
18eb406776 Add test for indexing_slicing_index and modify related test 2023-12-22 20:31:48 +08:00
cocodery
d020196dc0 Add check for illegal accessing known length array with a constant index 2023-12-22 20:17:43 +08:00
bors
dc975266a9 Auto merge of #11991 - J-ZhengLi:issue9911, r=llogiq
stop [`bool_comparison`]'s suggestion from consuming parentheses

fixes: #9907

---

changelog: stop [`bool_comparison`]'s suggestion from consuming parentheses
2023-12-21 12:30:11 +00:00
J-ZhengLi
a556d00c0a stop [bool_comparison]'s suggestion from consuming parentheses 2023-12-21 18:20:25 +08: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
Guillaume Gomez
238c5f9f27 Add ui tests for UNNECESSARY_TO_OWNED on split 2023-12-18 16:55:42 +01:00
Guillaume Gomez
71ea36b539 Extend UNNECESSARY_TO_OWNED to handle split 2023-12-18 16:46:41 +01:00
bors
7e650b7610 Auto merge of #11947 - hamirmahal:fix/broken-GitHub-corner, r=blyxyas,xFrednet
fix: broken GitHub corner

changelog: none

fixes #11946
2023-12-17 21:12:11 +00:00
bors
dd857f8207 Auto merge of #11966 - StackOverflowExcept1on:issue-8159, r=Jarcho
Do not lint `assertions_on_constants` for `const _: () = assert!(expr)`

Fixes #8159

```rust
pub fn f() {
    // warning
    assert!(true);
    assert!(usize::BITS >= 32);

    // ok
    const _: () = assert!(usize::BITS >= 32);
}
```

changelog: Fix `const _: () = assert!(expr)` false positive on `assertions_on_constants` lint
2023-12-17 14:03:13 +00: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
fff484d18e Auto merge of #11977 - y21:is_const_evaluatable_ice, r=Manishearth
don't visit nested bodies in `is_const_evaluatable`

Fixes #11939

This ICE happened in `if_let_some_else_none`, but the root problem is in one of the utils that it uses.
It is (was) possible for `is_const_evalutable` to visit nested bodies which would lead to it trying to get the type of one of the expressions with the wrong typeck table, which won't have the type stored.

Notably, for the expression `Bytes::from_static(&[0; 256 * 1024]);` in the linked issue, the array length is an anonymous const in which type checking happens on its own, so we can't use the typeck table of the enclosing function in there.

Visiting nested bodies is also not needed for checking whether an expression can be const, so I think it's safe to ignore just ignore them altogether.

changelog: Fix ICE when checking for constness in nested bodies
2023-12-16 22:54:50 +00:00
y21
b5169aea52 don't visit any nested bodies in is_const_evaluatable 2023-12-16 22:13:54 +01: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
bors
b918434717 Auto merge of #11974 - y21:if_let_true, r=llogiq
[`redundant_pattern_matching`]: lint `if let true`, `while let true`, `matches!(.., true)`

Closes #11917

This could also lint e.g. `if let (true, true, false) = (a, b, c)` and suggest `if a && b && c`, but that's a change in semantics (going from eager to lazy, so I just left it out for now. Could be a future improvement.

changelog: [`redundant_pattern_matching`]: lint `if let true`, `while let true`, `matches!(.., true)`
2023-12-16 18:08:22 +00:00
Guillaume Gomez
6b444f3092 Also check code generated by macros 2023-12-16 18:45:24 +01:00
y21
bc22407b79 add tests, lint on while let true and matches!(.., true) 2023-12-16 17:40:32 +01:00
y21
850d77ed55 [redundant_pattern_matching]: catch if let true 2023-12-16 16:37:58 +01:00
bors
a859e5cc1c Auto merge of #11971 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2023-12-16 13:02:49 +00:00