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
[`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
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
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
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
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`
Reorder the suggested code for the `IntoIterator` to match the ordering of the trait declaration:
```rust
impl IntoIterator for ... {
type Item = ...;
type IntoIter = ...;
```
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
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`
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`.
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
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`
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
Add test case for `missing_errors_doc` at tests with option `check-private-item=true`
Add test case for `missing_errors_doc` at tests with option `check-private-item=true` to proof that rust-lang/rust-clippy#13391 is not an issue anymore
changelog: none
Closes: rust-lang/rust-clippy#13391
Fix indentation of website code snippets
Fixes#13568
Follow up to #13359, I didn't catch that it swapped the `strip_prefix` out for a `trim` but they aren't interchangeable here
changelog: none
docs: Fix too_long_first_doc_paragraph: line -> paragraph
The documentation for too_long_first_doc_paragraph incorrectly says "line" where it should say "paragraph".
Fix a minor typo: doscstring -> docstring.
Also do a few tiny edits to attempt to make the wording slightly shorter and clearer.
changelog: [`too_long_first_doc_paragraph`]: Edit documentation
Add units/unit prefixes of frequency to doc-valid-idents
These units/unit prefixes often come up in the embedded world.
Should this PR also modify the `test_units` test? It seems only concerned with data units currently; should it also test frequency units?
changelog: [`doc_markdown`]: Add MHz, GHz, and THz to `doc-valid-idents`.
Fix not working lint anchor (generation and filtering)
As spotted by `@flip1995,` the anchor button is currently not working. Problem was the JS that was preventing the web browser from adding the hash at the end of the URL.
For the second bug fixed, the JS was stripping two characters instead of just stripping the `#` at the beginning.
changelog: Fix clippy page lint anchor (generation and filtering)
r? `@flip1995`