Commit Graph

21009 Commits

Author SHA1 Message Date
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
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
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
bors
12ca3630fc Auto merge of #13611 - xFrednet:0-giraffate-alumni, r=xFrednet
Unvacation giraffate and remove gh-pages -> xFrednet assignment

changelog: none

r? `@ghost`
2024-10-27 17:31:51 +00:00
xFrednet
f562d478f2
Unvacation giraffate and remove gh-pages -> xFrednet assignment 2024-10-27 18:27:44 +01:00
GnomedDev
d0b15f157c Swap Msrv from Vec to SmallVec 2024-10-27 14:11:20 +00:00
bors
31f6679e78 Auto merge of #13610 - alex-semenyuk:add_test_case, r=xFrednet
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
2024-10-27 12:46:55 +00:00
bors
c02f3a2822 Auto merge of #13600 - samueltardieu:push-tzuvnutssmrs, r=xFrednet
borrow_deref_ref: do not trigger on `&raw` references

changelog: [`borrow_deref_ref`]: do not trigger on `&raw` references

Fix #13584
2024-10-27 12:37:40 +00:00
Alexey Semenyuk
900db48900 Add test case for missing_errors_doc at tests with option check-private-items = true 2024-10-27 14:53:20 +05:00
bors
a0fab5cab1 Auto merge of #13605 - GnomedDev:read-exact-in-read-exact, r=llogiq
Stop linting unused_io_amount in io traits

Closes #4836

changelog: [`unused_io_amount`] No longer lints inside `io::Read`/`io::Write`, and async variants.
2024-10-27 09:42:03 +00:00
bors
3caff9962b Auto merge of #13571 - Alexendoo:website-code-indent, r=Centri3
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
2024-10-26 18:48:12 +00:00
GnomedDev
560353c90a
Stop linting unused_io_amount in io traits 2024-10-26 00:39:18 +01:00
Ruairidh Williamson
59ecf4d073
Fix is_from_proc_macro attr 2024-10-25 15:25:17 +01:00
bors
9cf416dc6e Auto merge of #13586 - evanj:evan.jones/long-paragraph-edit, r=xFrednet
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
2024-10-24 19:29:29 +00:00
bors
6bcd0b9b42 Auto merge of #13558 - alex-semenyuk:const_is_empty_fix, r=dswij
Don't trigger `const_is_empty` for inline const assertions

Close #13106

Considered case was described [here](https://github.com/rust-lang/rust-clippy/pull/13114#issuecomment-2266629991)

changelog: [`const_is_empty`]: skip const_is_empty for inline const assertions
2024-10-24 13:55:52 +00:00
bors
c2534dcc49 Auto merge of #13460 - ROMemories:feat/freq-units-allowed-idents, r=Centri3
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`.
2024-10-24 08:50:36 +00:00
Samuel Tardieu
b0412d0dd7 borrow_deref_ref: do not trigger on &raw references 2024-10-24 09:03:15 +02:00
bors
cefa31a524 Auto merge of #13588 - GuillaumeGomez:fix-lint-anchor, r=flip1995
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`
2024-10-23 19:12:16 +00:00
Guillaume Gomez
7115404a97 Open lint when clicking on its anchor 2024-10-23 16:58:06 +02:00
Guillaume Gomez
b33977b852 Fix invalid lint ID filtering 2024-10-22 22:54:29 +02:00
Guillaume Gomez
97d13a8c0a Fix not working lint anchor 2024-10-22 22:50:17 +02:00
Evan Jones
0bcc6f8156
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: Edit documentation for [`too_long_first_doc_paragraph`]
2024-10-22 16:04:30 -04:00
bors
5873cb9d17 Auto merge of #13570 - Kijewski:pr-stray-comma, r=xFrednet
docs: remove stray comma

changelog: none

the typo was (seemingly) ignored by browsers, so the change isn't visible to users
2024-10-21 09:11:08 +00:00
bors
8538562429 Auto merge of #13567 - y21:span_debug_assertions, r=flip1995
Add debug assertions for empty replacements and overlapping spans

rustc has debug assertions [^1] [^2] that check that a substitution doesn't have an empty suggestion string and an empty span at the same time, as well as that spans in multipart suggestions don't overlap.
However, since we link to the rustc-dev distributed compiler, these debug assertions are always disabled and so we never actually run them.

This leads to the problem that the debug ICE is not necessarily caught in the PR and only triggered in the rust repo sync, and in one of the last syncs this was a blocker and delayed the sync by several weeks because the fix was not obvious.

So this PR essentially copies the checks over and runs them in clippy debug builds as well, so that we can catch these errors in PRs directly.

-----
As for the second commit, this also *did* cause an ICE in a sync before and was fixed in the sync PR (see https://github.com/rust-lang/rust/pull/120345#issuecomment-1911005554), but it seems like that commit didn't make it back into the clippy repo (cc `@flip1995),` so the fixed code is in the rust repo but not in the clippy repo.

changelog: none

[^1]: https://doc.rust-lang.org/1.82.0/nightly-rustc/src/rustc_errors/diagnostic.rs.html#1019
[^2]: https://doc.rust-lang.org/1.82.0/nightly-rustc/src/rustc_errors/diagnostic.rs.html#932
2024-10-21 08:26:32 +00:00
bors
d00ab2e955 Auto merge of #13569 - alex-semenyuk:fix_version, r=blyxyas
Fix version for `ref_option`

Close #13566
As mentioned at #13566 `ref_option` [was merged](https://github.com/rust-lang/rust-clippy/pull/13336) after 1.82.0 so it wasn't include in this version

changelog: none
2024-10-20 22:20:55 +00:00
Alex Macleod
2666ed6c5b Fix indentation of website code snippets 2024-10-20 19:02:40 +00:00
y21
65eb1ec0fb remove the semicolon for builtin macro call statements in statement_outside_block
The expansion of `asm!()` and `line!()` is not marked as from an expansion, in which case `SourceMap::stmt_span` returns the input span unchanged. So instead of using `stmt_span`, use `mac_call_stmt_semi_span` directly
2024-10-20 19:00:55 +02:00
René Kijewski
2a5de352a1 docs: remove stray comma 2024-10-20 14:47:01 +02:00