Commit Graph

21037 Commits

Author SHA1 Message Date
alexey semenyuk
7bcd578a02
Link fix 2024-11-06 18:23:01 +05:00
bors
f02a0208e5 Auto merge of #13659 - samueltardieu:push-twtxmtvopoxo, r=blyxyas
no_mangle_with_rust_abi: properly position the suggested ABI

Fix #13656

changelog: [`no_mangle_with_rust_abi`]: properly position the suggested ABI
2024-11-06 11:27:13 +00:00
Samuel Tardieu
c1ab18d1c0 no_mangle_with_rust_abi: properly position the suggested ABI 2024-11-05 23:10:41 +01:00
bors
6631a2c1b7 Auto merge of #13654 - GnomedDev:early-exit-visitors, r=Alexendoo
Swap Visitors to early exit, instead of storing poison flag

I noticed that a bunch of visitors had a `poison` or `success` field, when they could just be returning `ControlFlow`.

changelog: none
2024-11-05 17:39:32 +00:00
GnomedDev
44c2a82972
Swap Visitors to early exit, instead of storing poison flag 2024-11-04 23:49:25 +00:00
bors
ccf7c88386 Auto merge of #13648 - samueltardieu:push-rpxvoukpolvm, r=Centri3
needless_continue: check labels consistency before warning

changelog: [`needless_continue`]: check labels before warning about `continue` as the last statement in a loop body

Fix #13641
2024-11-03 23:17:36 +00:00
bors
a1a9aaef87 Auto merge of #13631 - samueltardieu:push-uoowutzkvsrk, r=Centri3
no_mangle attribute requires unsafe in Rust 2024

Tests without unsafe must not run in edition 2024. Also, error messages have been modified to include the full attribute, so that a use of `#[unsafe(no_mangle)]` does not produce an error message containing `#[no_mangle]`.

changelog: [`no_mangle_attribute`]: handle `#[unsafe(no_mangle)]` as well
2024-11-03 19:43:19 +00:00
bors
040129b774 Auto merge of #13629 - samueltardieu:push-nwukowumrvsn, r=flip1995
Return iterator must not capture lifetimes in Rust 2024

In Rust 2024, by default lifetimes will be captured which does not reflect the reality since we return an iterator of `DefId` which do not capture the input parameters.

changelog: none
2024-11-03 15:50:48 +00:00
Samuel Tardieu
2f1b7b64fb needless_continue: check labels consistency before warning 2024-11-03 16:49:15 +01:00
bors
ddd1a86c66 Auto merge of #13573 - y21:issue13427, r=Centri3
Don't lint unnamed consts and nested items within functions in `missing_docs_in_private_items`

With this change we no longer require doc comments for `const _: ()` items as well as nested items in functions or other bodies. In both of those cases, rustdoc generates no documentation even with `--document-private-items`.

Fixes #13427 (first commit)
Fixes #13298 (second commit)
cc https://github.com/rust-lang/rust-clippy/issues/5736#issuecomment-668524296

changelog: [`missing_docs_in_private_items`]: avoid linting in more cases where rustdoc generates no documentation
2024-11-03 09:10:22 +00:00
bors
52b8324503 Auto merge of #13585 - GuillaumeGomez:no-js, r=Alexendoo
Improve display of clippy lints page when JS is disabled

There is no point in displaying the settings menu and the filters if JS is disabled. So in this case, this PR simply hides it:

![image](https://github.com/user-attachments/assets/e96039a9-e698-49b7-bf2b-70e78442b305)

For the theme handling though, I need to send a fix to mdBook first. But once done, it'll look as expected (dark if system is in dark mode).

changelog: Improve clippy lints page display when JS is disabled.

r? `@Alexendoo`
2024-11-02 13:49:04 +00:00
bors
5c6fe68c00 Auto merge of #13376 - decryphe:source-ordering, r=llogiq
new lint: `source_item_ordering`

changelog: [`source_item_ordering`]: Introduced a new restriction lint that checks the ordering of items in Modules, Enums, Structs, Impls and Traits.

From the written documentation:

> Why restrict this?
> Keeping a consistent ordering throughout the codebase helps with working as a team, and possibly improves maintainability of the codebase. The idea is that by defining a consistent and enforceable rule for how source files are structured, less time will be wasted during reviews on a topic that is (under most circumstances) not relevant to the logic implemented in the code. Sometimes this will be referred to as "bike-shedding".
>
> Keep in mind, that ordering source code alphabetically can lead to reduced performance in cases where the most commonly used enum variant isn't the first entry anymore, and similar optimizations that can reduce branch misses, cache locality and such. Either don't use this lint if that's relevant, or disable the lint in modules or items specifically where it matters. Other solutions can be to use profile guided optimization (PGO), or other advanced optimization methods.

I tried to build it as configurable as possible, as such a highly opinionated lint should be adjustable to personal opinions.

I'm open to any input and will be available both here and on the zulip for communication. In the meantime I'll be testing this lint against my own code-bases, which I've (manually) kept ordered with the default config, to see how well it works in practice.

And lastly, a big thanks to the community for making clippy the best linter there is!
2024-11-02 11:03:30 +00:00
bors
e8b78e2f66 Auto merge of #13630 - samueltardieu:push-qrnxuykslnsl, r=y21
Use match ergonomics compatible with editions 2021 and 2024

This PR contains the minimal changes needed to make Clippy match ergonomics work with both Rust 2021 and Rust 2024.

changelog: none
2024-11-01 20:23:33 +00:00
bors
9d03956fad Auto merge of #13635 - Alexendoo:cargo-dev-serve-watch-test, r=blyxyas
Watch `tests/compile-test.rs` in `cargo dev serve`

Changes to `compile-test.rs` will also need a rerun of `collect-metadata`

changelog: none
2024-11-01 19:45:24 +00:00
bors
e4dc892ae3 Auto merge of #13608 - J-ZhengLi:issue12338-new, r=Alexendoo
[`infinite_loops`]: fix incorrect suggestions on async functions/closures

closes: #12338

I intend to fix this in #12421 but got distracted by some other problems in the same lint, delaying the process of closing the actual issue. So here's a separated PR that only focus on the issue and nothing else.

---

changelog: [`infinite_loops`]: fix suggestion error on async functions/closures
2024-11-01 19:36:02 +00:00
Guillaume Gomez
ac764df8ab Handle noscript style with "js" class on <html>. 2024-11-01 20:20:12 +01:00
Guillaume Gomez
ca5c6f6c26 Improve theme handling when JS is disabled 2024-11-01 20:20:12 +01:00
Guillaume Gomez
c056928af2 Improve display of clippy lints page when JS is disabled 2024-11-01 20:20:12 +01:00
bors
c782988378 Auto merge of #13615 - GnomedDev:document-constevalctx-point, r=Alexendoo
Explain why clippy's HIR const eval exists

When I initially found this, I was wondering why clippy wasn't just using miri, but after some discussion with some rustc folks let's document why.

changelog: none
2024-11-01 13:39:21 +00:00
GnomedDev
012e30622c
Explain why clippy's HIR const eval exists 2024-11-01 11:06:54 +00:00
bors
8568ca8c23 Auto merge of #13634 - nyurik:fix-iter-without-into, r=xFrednet,samueltardieu
Cleanup code suggestion for `into_iter_without_iter`

Reorder the suggested code for the `IntoIterator` to match the ordering of the trait declaration:

```rust
impl IntoIterator for ... {
    type Item = ...;
    type IntoIter = ...;
```

changelog: none
2024-10-31 14:27:16 +00:00
bors
2298a6742f Auto merge of #13628 - samueltardieu:push-puluprmsyuzq, r=xFrednet
Do not use `gen` as a variable name

`gen` will be a reserved word in Rust 2024.

changelog: none
2024-10-31 12:04:31 +00:00
bors
e1fa1b2c42 Auto merge of #13636 - GuillaumeGomez:extend-large_include_file, r=dswij
Extend `large_include_file` lint to also work on attributes

I realized randomly while working on another lint that `large_include_file` was not emitted on attributes. This PR fixes that.

changelog: Extend `large_include_file` lint to also work on attributes
2024-10-31 09:24:59 +00:00
bors
1998abcdce Auto merge of #13633 - chrysn-pull-requests:doc-valid-ident-coap, r=Centri3
Add 'CoAP' to doc-valid-idents

CoAP is a name of a network protocol common in embedded systems; one would talk in documentation about "a CoAP server" or "a CoAP client" without referring to a specific type.

This PR fixes false positives that arise from that use.

changelog: [`doc_markdown`]: Add CoAP to `doc-valid-idents`.

As this review is identical in structure to https://github.com/rust-lang/rust-clippy/pull/13460, I'm asking for a the same reviewer (if that works):

r? `@Centri3`
2024-10-30 21:58:56 +00:00
Guillaume Gomez
0c29fccf03 Extend large_include_file lint to also work on attributes 2024-10-30 20:41:34 +01:00
Alex Macleod
a7aa8bfde0 Watch tests/compile-test.rs in cargo dev serve 2024-10-30 19:21:25 +00:00
Yuri Astrakhan
323f144fe1 Cleanup code suggestion for into_iter_without_iter
Reorder the suggested code for the `IntoIterator` to match the ordering of the trait declaration:

```rust
impl IntoIterator for ... {
    type Item = ...;
    type IntoIter = ...;
```
2024-10-30 13:10:55 -04:00
bors
1bdc08a6bc Auto merge of #13599 - RuairidhWilliamson:proc_macro_attr, r=blyxyas
Fix allow_attributes when expanded from some macros

fixes #13349

The issue here was that the start pattern being matched on the original source code was not specific enough. When using derive macros or in the issue case a `#[repr(C)]` the `#` would match the start pattern meaning that the expanded macro appeared to be unchanged and clippy would lint it.

The change I made was to make the matching more specific by matching `#[ident` at the start. We still need the second string to match just the ident on its own because of things like `#[cfg_attr(panic = "unwind", allow(unused))]`.

I also noticed some typos with start and end, these code paths weren't being reached so this doesn't fix anything.

changelog: FP: [`allow_attributes`]: don't trigger when expanded from some macros
2024-10-30 15:22:47 +00:00
chrysn
bd4aa170ef Add 'CoAP' to doc-valid-idents 2024-10-30 12:57:24 +01:00
Samuel Tardieu
805245161a no_mangle attribute requires unsafe in Rust 2024 2024-10-30 11:31:14 +01:00
Samuel Tardieu
540e116a38 Return iterator must not capture lifetimes in Rust 2024
In Rust 2024, by default lifetimes will be captured which does not
reflect the reality since we return an iterator of `DefId` which do
not capture the input parameters.
2024-10-30 11:22:17 +01:00
Samuel Tardieu
0c1ef98454 Use match ergonomics compatible with editions 2021 and 2024 2024-10-30 11:22:17 +01:00
decryphe
f7ab2c9908 new lint: source_item_ordering 2024-10-30 10:03:16 +01:00
Samuel Tardieu
a3047098b6 Do not use gen as a variable name
`gen` will be a reserved word in Rust 2024.
2024-10-30 09:28:37 +01:00
bors
15ad8245b2 Auto merge of #13034 - rspencer01:trivial_map_over_range, r=y21
Add new `trivial_map_over_range` lint

This lint checks for code that looks like
```rust
  let something : Vec<_> = (0..100).map(|_| {
    1 + 2 + 3
  }).collect();
```
which is more clear as
```rust
  let something : Vec<_> = std::iter::repeat_with(|| {
    1 + 2 + 3
  }).take(100).collect();
```

That is, a map over a range which does nothing with the parameter passed to it is simply a function (or closure) being called `n` times and could be more semantically expressed using `take`.

- [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`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

changelog: new lint: [`trivial_map_over_range`] `restriction`
2024-10-29 22:27:34 +00:00
Robert Spencer
acc3842d43 Add new map_with_unused_argument_over_ranges lint
This lint checks for code that looks like
```rust
  let something : Vec<_> = (0..100).map(|_| {
    1 + 2 + 3
  }).collect();
```
which is more clear as
```rust
  let something : Vec<_> = std::iter::repeat_with(|| {
    1 + 2 + 3
  }).take(100).collect();
```
or
```rust
  let something : Vec<_> =
      std::iter::repeat_n(1 + 2 + 3, 100)
      .collect();
```

That is, a map over a range which does nothing with the parameter
passed to it is simply a function (or closure) being called `n`
times and could be more semantically expressed using `take`.
2024-10-29 21:32:00 +00:00
bors
35a7095d8c Auto merge of #13499 - samueltardieu:map-all-any-identity, r=xFrednet
New lint `map_all_any_identity`

This lint has been inspired by code encountered in Clippy itself (see the first commit).

changelog: [`map_all_any_identity`]: new lint
2024-10-29 11:31:11 +00:00
Samuel Tardieu
91a1d16a81 Add new lint: map_all_any_identity 2024-10-29 11:59:15 +01:00
Samuel Tardieu
f2f73f9c9c Replace .map(…).any(identity) by .any(…) 2024-10-29 11:55:13 +01:00
bors
625d391107 Auto merge of #13437 - samueltardieu:issue-13434, r=y21
New lint `needless_as_bytes`

changelog: [`needless_as_bytes`]: new lint

Fix #13434
2024-10-29 08:03:05 +00:00
bors
528dcc3025 Auto merge of #13620 - GnomedDev:large-const-array-compute-const, r=Manishearth
Fire large_const_arrays for computed array lengths

changelog: [`large_const_arrays`]: Lint now fires when the length is determined by an expression
2024-10-28 20:15:54 +00:00
GnomedDev
c5df79d9db
Fire large_const_arrays for computed array lengths 2024-10-28 18:35:21 +00:00
bors
d09d85d8ef Auto merge of #13614 - hamirmahal:fix/usage-of-a-deprecated-nodejs-version, r=flip1995
fix: usage of `a deprecated Node.js version`

Fixes #13613

changelog: none
2024-10-28 17:18:11 +00:00
Hamir Mahal
d63322f0f4
fix: usage of a deprecated Node.js version 2024-10-28 09:04:16 -07:00
bors
2e4a11ea77 Auto merge of #13338 - CoCo-Japan-pan:nonminimal_bool_casted, r=Centri3
fix incorrect suggestion for `!(a >= b) as i32 == c`

fixes #12761

The expression `!(a >= b) as i32 == c` got simplified to `a < b as i32 == c`, but this is a syntax error.
The result we want is `(a < b) as i32 == c`.
This is fixed by adding a parenthesis to the suggestion given in `check_simplify_not` when the boolean expression is casted.

changelog: [`nonminimal_bool`]: fix incorrect suggestion for `!(a >= b) as i32 == c`
2024-10-28 13:58:16 +00:00
bors
a529c44eca Auto merge of #13472 - GnomedDev:smaller-msrv, r=Jarcho
Optimise Msrv for common one item case

Currently, `Msrv` is cloned around a lot in order to handle the `#[clippy::msrv]` attribute. This attribute, however, means `RustcVersion` will be heap allocated if there is only one source of an msrv (eg: `rust-version` in `Cargo.toml`).

This PR optimizes for said case, while keeping the external interface the same by swapping the internal representation to `SmallVec<[RustcVersion; 2]>`.

changelog: none
2024-10-28 12:53:06 +00:00
CoCo-Japan-pan
d30a026a6b check if we need a parenthesis 2024-10-28 18:13:16 +09:00
Samuel Tardieu
f152bcb72e Update the number of lints (over 700 → over 750) 2024-10-28 09:21:07 +01:00
Samuel Tardieu
62c4daf358 New lint needless_as_bytes 2024-10-28 09:19:17 +01:00
bors
73bad368f2 Auto merge of #13548 - wowinter13:unnecessary_filter_map_filter_map_some, r=llogiq
fix: remove unnecessary filter_map usages

fixes https://github.com/rust-lang/rust-clippy/issues/12556

(Fixed version of https://github.com/rust-lang/rust-clippy/pull/12766)

changelog: [unnecessary_filter_map]: filter map improvements
2024-10-27 22:27:49 +00:00