Commit graph

11978 commits

Author SHA1 Message Date
Philipp Krones
40fca8f7a8
Bump Clippy version -> 0.1.83 2024-09-05 17:00:55 +02:00
Philipp Krones
87ce1d8069
Merge remote-tracking branch 'upstream/master' into rustup 2024-09-05 17:00:37 +02:00
bors
c95c767663 Auto merge of #13323 - xFrednet:chnagelog-1-81, r=flip1995
Changelog for Clippy 1.81 🔰

Roses are red,
Violets are blue,
Expectations are stable,
And reasons are set

---

### The cat of this release is *Keepy* submitted by `@blyxyas:`

<img height=500 src="https://github.com/rust-lang/rust-clippy/assets/73757586/902dd802-5ac8-471e-bb93-e195526ba580" alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none
2024-09-05 09:17:12 +00:00
Alex Macleod
f7f550561e Only lint manual_non_exhaustive for exported types 2024-09-04 21:22:28 +00:00
Lukas Lueg
7d2e6ebcbe Expand missing_transmute_annotations docs
Fixes #13339
2024-09-04 19:37:59 +02:00
bors
58cbf09e86 Auto merge of #13332 - nyurik:nits, r=xFrednet
Minor code simplification

changelog: none
2024-09-03 20:47:48 +00:00
bors
f2ef26d239 Auto merge of #13263 - y21:warn_manual_c_str_literals, r=Centri3
move `manual_c_str_literals` to complexity

IMO the suggestion to use `c""` literals over a hardcoded `\0` byte string literal has some fairly strong upsides (no need to manually null-terminate it and the compiler checks for intermediary null bytes) that this should just be enabled by default.

It's also written slightly conservatively to only emit a warning when we can be reasonably confident that the lint is *actually* applicable (that is, lint on e.g. `b"foo\0".as_ptr()` but not `b"foo\0"`. The latter looks like a c-string but its type is `&[u8; _]`, and if it's used in a context where a byte slice is needed then you have no nice way to convert to it from a `c"foo"` literal of type `&CStr`).

changelog: move [`manual_c_str_literals`] to complexity (now warn-by-default)
2024-09-03 18:29:20 +00:00
Soveu
273b561609 add pointers_in_nomem_asm_block lint 2024-09-03 18:58:05 +02:00
Yuri Astrakhan
cd28176025 Minor code simplification 2024-09-01 20:58:14 -04:00
Ralf Jung
ba2577f23c stabilize const_float_bits_conv 2024-09-01 12:38:59 +02:00
bors
a81f1c8277 Auto merge of #13325 - alex-semenyuk:wrong_self_convention_doc_fix, r=y21
Provide more clear example for `WRONG_SELF_CONVENTION`

Provide more clear example for `WRONG_SELF_CONVENTION`

changelog: none
2024-09-01 08:28:00 +00:00
alexey semenyuk
989ebae2ba Provide more clear example for WRONG_SELF_CONVENTION 2024-08-31 23:06:03 +05:00
bors
ac914d3457 Auto merge of #12476 - GuillaumeGomez:add-manual_arithmetic_check, r=y21
Extend `implicit_saturating_sub` lint

Fixes #10070.

It can serve as base if we want to add equivalent checks for other arithmetic operations.

Also one important note: when writing this lint, I realized that I could check for wrong conditions performed beforehand on subtraction and added another part in the lint. Considering they both rely on the same checks, I kept both in the same place. Not sure if it makes sense though...

changelog: Extend `implicit_saturating_sub` lint
2024-08-31 16:03:42 +00:00
Guillaume Gomez
2832faf895 Move MSRV check later in implicit_saturating_sub 2024-08-31 16:24:17 +02:00
Guillaume Gomez
e845366c82 Add MSRV check for saturating_sub lints in const contexts 2024-08-31 16:24:17 +02:00
WeiTheShinobi
04d70d04fc
[single_match, single_match_else] fix suggestion when match irrefutable 2024-08-31 05:25:59 +08:00
xFrednet
9e7473f08d
Update version attribute for 1.81 lints 2024-08-29 21:36:43 +02:00
Guillaume Gomez
d20fc38f0a Create new inverted_saturating_sub lint 2024-08-29 20:20:13 +02:00
Guillaume Gomez
74a2344dc1 Extend implicit_saturation_sub lint 2024-08-29 20:20:13 +02:00
Michael Goulet
5bbb0d41f1 Stop using ty::GenericPredicates for non-predicates_of queries 2024-08-29 00:17:40 -04:00
bors
04bded5d6e Auto merge of #13235 - kyoto7250:fix_issue_13191, r=llogiq
Use `is_diagnostic_item` for checking a def_id in `unnecessary_min_or_max`.

close #13191
This PR fixes the false positives in `unnecessary_min_or_max `.
We should use `is_diagnostic_item` for checking def_ids in this lint.

----

changelog: fix false positive in `unnecessary_min_or_max `.
2024-08-28 14:50:20 +00:00
y21
e8ac4ea418 new lint: zombie_processes 2024-08-27 21:51:02 +02:00
bors
603d5a19c9 Auto merge of #13294 - WeiTheShinobi:new_lint_used_underscore_items, r=llogiq
Add new lint: `used_underscore_items`

Closes #13260

---

changelog: new [`used_underscore_items`] lint against using items with a single leading underscore
2024-08-27 10:59:31 +00:00
bors
f194e684b1 Auto merge of #13311 - alex-semenyuk:fix_manual_range_patterns, r=Manishearth
Fix manual_range_patterns case with one element at OR

Close #11825
As mentioned #11825 `OR` can be used for stylistic purposes with one element, we can filter this case from triggering lint

changelog: [`manual_range_patterns`]: not trigger when `OR` has only one element
2024-08-26 21:10:54 +00:00
Alexey Semenyuk
494112e51f Fix manual_range_patterns case with one element at OR 2024-08-27 01:32:07 +05:00
bors
b3fc578ca6 Auto merge of #13300 - kyoto7250:issue_13292, r=llogiq
check std::panic::panic_any in panic lint

close #13292
This PR detects `std::panic::panic_any` in panic lint.

changelog: check std::panic::panic_any in panic lint
2024-08-26 19:32:11 +00:00
bors
ebcd6bc785 Auto merge of #13091 - Alexendoo:empty-line-after-rewrite, r=dswij
Rewrite `empty_line_after_doc_comments` and `empty_line_after_outer_attr`, move them from `nursery` to `suspicious`

changelog: [`empty_line_after_doc_comments`], [`empty_line_after_outer_attr`]: rewrite and move them from `nursery` to `suspicious`

They now lint when there's a comment between the last attr/doc comment and the empty line, to cover the case:

```rust
/// Docs for `old_code
// fn old_code() {}

fn new_code() {}
```

When these lints or `suspicious_doc_comments` trigger we no longer trigger any other doc lint as a broad fix for #12917, reverts some of #13002 as the empty line lints cover it

I ended up not doing https://github.com/rust-lang/rust-clippy/issues/12917#issuecomment-2161828859 as I don't think it's needed
2024-08-25 17:47:09 +00:00
bors
083e20a6dc Auto merge of #13113 - nyurik:ignore-pass-by-val-for-pfx, r=blyxyas
Ignore underscore-prefixed args for needless_pass_by_value lint

When a user explicitly tags a param as unused (yet?), there is no need to raise another lint on it.

fixes #7295

Note that I had to rename all `_*` params in the tests, but kept the variable name length to avoid extra changes in the expected output.

changelog: [`needless_pass_by_value`]: do not warn if the argument name starts with an `_`
2024-08-25 17:28:51 +00:00
WeiTheShinobi
d40e04a1cb
used_underscore_items will not lint exteranl item 2024-08-26 00:52:52 +08:00
bors
508a7b4b38 Auto merge of #129531 - Jarcho:clippyup, r=Manishearth
Clippy subtree update

r? `@Manishearth`
2024-08-25 11:56:57 +00:00
bors
40bca0d944 Auto merge of #13285 - alex-semenyuk:ignore_todo_for_diverging_sub_expression, r=xFrednet
Diverging subexpression lint should not fire on todo!()

As per #10243  it is not that helpful to point out that a subexpression diverges, so do not fire on todo

changelog: [`diverging_sub_expression`]: do not trigger on todo
2024-08-25 09:51:40 +00:00
Jason Newcomb
173d5a6af0 Merge commit '0f8eabd6231366bfc1bb1464601297c2d48f8f68' into clippyup 2024-08-24 18:33:44 -04:00
Jason Newcomb
e348fe2233 Merge branch 'master' into rustup 2024-08-24 16:31:01 -04:00
Alex Macleod
3474df6a8e Rewrite empty_line_after_doc_comments and empty_line_after_outer_attr 2024-08-24 18:07:31 +00:00
Pavel Grigorenko
3c4367a80f Fix elided_named_lifetimes in code 2024-08-24 19:21:32 +03:00
kyoto7250
b179c3e7f7 check std::panic::panic_any in panic lint 2024-08-25 00:56:02 +09:00
bors
30e0b69908 Auto merge of #12993 - GuillaumeGomez:too_long_first_doc_paragraph, r=Centri3
Add new `too_long_first_doc_paragraph` first paragraph lint

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

changelog: Add new `too_long_first_doc_paragraph` first paragraph lint
2024-08-24 15:23:34 +00:00
bors
497177fa50 Auto merge of #13296 - Jarcho:get_src_display3, r=Alexendoo
Replace more uses of `snippet_opt`.

Almost all calls are removed after this.

changelog: none
2024-08-24 12:42:32 +00:00
Alexey Semenyuk
f4fc3858bc Fix suggestion unwrap_or_else 2024-08-24 15:43:00 +05:00
Jason Newcomb
9450b4af48 Replace more uses of snippet_opt. 2024-08-21 14:41:18 -04:00
Jason Newcomb
8a4c34a5b7 Start removing snippet_opt 2024-08-21 12:25:10 -04:00
Bruce Mitchener
3f97261fba Fix a couple of typos. 2024-08-21 21:42:57 +07:00
WeiTheShinobi
b615c82180
Add new lint: used_underscore_items 2024-08-21 19:57:41 +08:00
bors
e5a1ef0795 Auto merge of #13290 - Jarcho:interior_mut_quick, r=Alexendoo
`declare_interior_mutable_const`: Ignore pointer types.

fixes #12951
fixes #13233

changelog: `declare_interior_mutable_const`: Ignore pointer types.
2024-08-20 18:04:47 +00:00
Jason Newcomb
687d4e3d16 declare_interior_mutable_const: Ignore pointer types. 2024-08-20 12:01:24 -04:00
bors
70650de720 Auto merge of #13241 - alex-semenyuk:fix_double_must_use, r=xFrednet
Fix confusing message in double_must_use lint

Close #13003
As mentioned at #13003 it isn't quite clear what it means "an empty `#[must_use]` attribute" so clarify it

changelog: [none]
2024-08-20 15:58:30 +00:00
Milo Moisson
fc8a025f17
fix(cfg_not_test): lint description typo 2024-08-20 12:10:32 +02:00
bors
d0e637da19 Auto merge of #13281 - alex-semenyuk:string_slice_fix, r=y21
Trigger [`string_slice`] if expression is reference to `&str`

Close #12708
changelog: [`string_slice`]: trigger lint if expression is reference to `&str`
2024-08-19 20:12:36 +00:00
bors
e7d9fcf8b2 Auto merge of #13288 - kyoto7250:fix-13184, r=y21
fix false positive in explicit_iter_loop with msrv

close #13184

This PR fix false positive in explicit_iter_loop when msrv < 1.80

changelog: fix false positive in explicit_iter_loop when msrv < 1.80
2024-08-19 20:03:46 +00:00
Alexey Semenyuk
7b7cf440cb string_slice should detect on Cow 2024-08-19 23:25:45 +05:00
bors
ba6bc81277 Auto merge of #13278 - Alexendoo:misc-cleanup, r=y21
Misc cleanup

changelog: none
2024-08-19 17:42:25 +00:00
kyoto7250
1958e1acd4 fix false position in explicit_iter_loop with msrv 2024-08-20 01:51:32 +09:00
Alexey Semenyuk
9732128e83 Diverging subexpression lint should not fire on todo!() 2024-08-18 22:05:57 +05:00
sobolevn
4e6fc6fa05
Improve collapsible_match error message syntax 2024-08-18 19:40:56 +03:00
Guillaume Gomez
a2033428c4 Do not emit TOO_LONG_FIRST_DOC_PARAGRAPH lint if item is generated from proc-macro and simplify code to emit lint 2024-08-18 14:14:00 +02:00
bors
bfe7f070bd Auto merge of #13248 - Alexendoo:format-arg-ast-fallback, r=xFrednet
Remove `find_format_arg_expr` AST fallback

If the function fails where it shouldn't we can fix that directly, but the fallback path is untested as I'm not aware of a case where it would fail

changelog: none
2024-08-18 09:11:03 +00:00
bors
233b5f2083 Auto merge of #13273 - alex-semenyuk:assigning_clones_disable_for_test, r=blyxyas
Disable assigning_clones for tests

Close: #12752
As mentioned at #12752 when a test struct is initialized with some default string, this inverts the order of assignee/assignment and makes a bit harder to read/write code

changelog: [`assigning_clones.rs`]: disable assigning_clones for tests
2024-08-18 02:15:36 +00:00
Alex Macleod
6993752607 Replace some iteration with get_[type_]diagnostic_name 2024-08-17 18:52:55 +00:00
Alex Macleod
9aa656df9f Remove redundant doc comments 2024-08-17 18:44:26 +00:00
Alex Macleod
ed46141081 Remove duplicate type_diagnostic_name function 2024-08-17 18:10:46 +00:00
Alex Macleod
4f661302c6 Replace span_suggestion_with_style with _verbose 2024-08-17 18:09:28 +00:00
Alex Macleod
c0373616d0 Fix code snippet in from_str_radix_10 docs 2024-08-16 15:28:42 +00:00
Alexey Semenyuk
953c7ed41e Disable assigning_clones for tests 2024-08-16 16:21:03 +05:00
bors
73819440ea Auto merge of #13193 - alex-semenyuk:fix_doc_unused_io_amount, r=xFrednet
Fix doc example for UNUSED_IO_AMOUNT

Cosmetic changes. Unify example for UNUSED_IO_AMOUNT

changelog: none
2024-08-14 08:17:18 +00:00
bors
70457f637d Auto merge of #13253 - alex-semenyuk:fix_message_unnecessary_unwrap, r=llogiq
Clarify suggestion message for unwrap lint

Close #10217
As mentioned at #10217 message for `unwrap` uses `..` like `Some(..)` which can confuse with slice and other places mostly use `<item>` like `for (i, <item>) in target_groups_json.iter().enumerate().skip(1) {` So replace  `..` to `<item>`

changelog: [`unnecessary_unwrap`] clarify suggestion message
2024-08-13 23:50:05 +00:00
Antoni Spaanderman
5fee840875
fix indentation in docs 2024-08-13 13:13:02 +02:00
y21
a5e3a3f9b6 move manual_c_str_literals to complexity 2024-08-12 22:54:20 +02:00
Alex Macleod
a22ce2d005 Remove HashSets from Conf 2024-08-12 20:24:47 +00:00
Alex Macleod
182cd5f278 Replace the metadata collector with tests 2024-08-12 20:24:46 +00:00
bors
e07078482b Auto merge of #13261 - antonilol:fix-doc-code-blocks, r=xFrednet
fix code blocks in doc comments inconsistently using 3 or 4 spaces of indentation

The metadata collector script was treating the space lines all start with as indentation. This caused code block's triple backticks to get a space in front of it, like this:
```
 ```rust
^ this space
```
Code after that that is indented with 4 spaces will only have 3 of those rendered.
Example (taken from [here](https://rust-lang.github.io/rust-clippy/master/index.html#/missing_panics_doc)):
```rust
...
pub fn divide_by(x: i32, y: i32) -> i32 {
   if y == 0 {                      // 3 spaces
       panic!("Cannot divide by 0") // 7 spaces
...
```

Also added 'compile_fail' alongside the other rustdoc directives (second code block [here](https://rust-lang.github.io/rust-clippy/master/index.html#/macro_metavars_in_unsafe) had no highlighting), fixed a doc comment using 'rs' instead of 'rust' and removed some spaces causing an extra missing space of indentation (see second code block [here](https://rust-lang.github.io/rust-clippy/master/index.html#/map_err_ignore)).

changelog: none
2024-08-12 19:14:50 +00:00
bors
1984752623 Auto merge of #13255 - Jarcho:get_src_display2, r=Manishearth
Remove more `snippet_opt` calls

First commit is the same as #13244

changelog: none
2024-08-12 18:50:19 +00:00
Antoni Spaanderman
d7f1252ddf
fix code blocks in doc comments inconsistently using 3 or 4 spaces of indentation 2024-08-12 18:42:13 +02:00
bors
52192aa321 Auto merge of #13243 - Alexendoo:rustcversion, r=flip1995
Replace `rustc_semver` with `rustc_session::RustcVersion`

Allows dropping a dependency but there is a behaviour change here, the following versions are no longer accepted:

* `1` (would need to be `1.0` or `1.0.0`)
* `1.0.0-alpha`
* `1.0.0-alpha.2`
* `1.0.0-beta`

But this seems unlikely to effect anybody, I did some GitHub searching and found no occurrences outside our UI tests

r? `@flip1995`

changelog: none
2024-08-12 08:24:00 +00:00
Jason Newcomb
ddf2ba5886 Remove more instances of snippet_opt. 2024-08-11 18:07:53 -04:00
Alexey Semenyuk
f93fb9a417 Clarify message for unwrap lint 2024-08-11 20:33:28 +05:00
bors
c8b0923a73 Auto merge of #13163 - GuillaumeGomez:fix-13097, r=Alexendoo
Fix case where doc_markdown is triggered on words ending with "ified"

Fixes #13097.

r? `@Alexendoo`

changelog: Fix case where doc_markdown is triggered on words ending with "ified"
2024-08-10 17:51:56 +00:00
bors
37f98fffe7 Auto merge of #13220 - y21:issue13219, r=dswij
[`macro_metavars_in_unsafe`]: recognize metavariables in tail expressions

Fixes #13219

`macro_metavars_in_unsafe` keeps track of the current "expansion depth" (incremented/decremented when entering/leaving a macro span) to tell if an expression from the root context is contained within a macro (see the doc comment I added for a hopefully better explanation)

Before this PR, we didn't increment said `expn_depth` for `unsafe` blocks within macros, because we already do that in `visit_stmt` anyway, so it would work fine for statements, but that's not enough for tail expressions of an unsafe block.

So we now also increment it for macro unsafe blocks.
Also updated the comment for `expn_depth` while I'm at it because "This is not necessary for correctness" isn't correct now that I think about it

------

changelog: none
2024-08-10 12:43:43 +00:00
Alex Macleod
4231e93bf7 Remove find_format_arg_expr AST fallback 2024-08-10 10:50:47 +00:00
Jason Newcomb
f9509d3574 Refactor absolute_paths:
* Check the path length first
* Use `is_from_proc_macro`
* Use symbols instead of strings when checking crate names
2024-08-09 22:08:29 -04:00
Jason Newcomb
9afab36ca9 Rename get_source_text to get_source_range. Add new get_source_text which returns a displayable string-like type. 2024-08-09 09:27:00 -04:00
Alex Macleod
b32a0176fa Replace rustc_semver with rustc_session::RustcVersion 2024-08-09 13:00:24 +00:00
bors
1c81105b43 Auto merge of #13211 - rzvxa:respect_allow_inconsistent_struct_constructor_on_adt, r=Alexendoo
Respect allow `inconsistent_struct_constructor` on the struct definition

Closes #13203

Now we check if the target type is marked with `#[allow(clippy:inconsistent_struct_constructor)]` before lining.
As a side-effect of this change, The rule in the subject no longer runs on non-local `AdtDef`s. However, as suggested by `@Jarcho` it shouldn't be a big deal since most of the time we didn't have access to this information anyway.

> You can't get lint attributes from other crates. I would probably just restrict the lint to only work with types from the current crate while you're at it. Upstream crates don't have a definition order from the point of view of the current crate (with the exception of #[repr(C)] structs).

changelog: Respect allow `inconsistent_struct_constructor` on the struct definition.
2024-08-09 12:23:53 +00:00
rzvxa
d85cf0bacd use fulfill_or_allowed over is_lint_allowed. 2024-08-09 12:18:56 +03:30
Nicholas Nethercote
e785219238 Shrink TyKind::FnPtr.
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and
`FnHeader`, which can be packed more efficiently. This reduces the size
of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms.
This reduces peak memory usage by a few percent on some benchmarks. It
also reduces cache misses and page faults similarly, though this doesn't
translate to clear cycles or wall-time improvements on CI.
2024-08-09 14:33:25 +10:00
Alexey Semenyuk
9948b423a0 Fix confusing message in double_must_use lint 2024-08-09 01:35:28 +05:00
Philipp Krones
1ac76a2062 Merge commit 'cb806113e0f83a8f9b47d35b453b676543bcc40e' into clippy-subtree-update 2024-08-08 19:13:50 +02:00
Philipp Krones
7a73a101e9
Merge remote-tracking branch 'upstream/master' into rustup 2024-08-08 18:54:43 +02:00
kyoto7250
c2ed04be16 check the def_id with using diagnostic_item in unnecessary_min_or_max lint
https://github.com/rust-lang/rust-clippy/issues/13191
2024-08-09 00:48:38 +09:00
bors
b1e87922c1 Auto merge of #13200 - Jarcho:constant_no_typeck, r=Alexendoo
Don't use `LateContext` in the constant evaluator

This also changes the interface to require explicitly creating the context. `constant` could be added back in, but the others are probably not worth it.

A couple of bugs have been fixed. The wrong `TypeckResults` was used once when evaluating a constant, and the wrong `ParamEnv` was used by some callers (there wasn't a way to use the correct one).

changelog: none
2024-08-08 14:42:42 +00:00
Jason Newcomb
e4ad36d6a8 Require ConstEvalCtxt to be constructed. 2024-08-08 10:37:10 -04:00
Jason Newcomb
d2cb227eb4 Don't store LateContext in ConstEvalLateContext 2024-08-08 10:34:53 -04:00
bors
ffc391c766 Auto merge of #13231 - Jarcho:no_tree_walk_in_const, r=Alexendoo
Don't walk the HIR tree when checking for a const context

changelog: none
2024-08-08 13:47:18 +00:00
Jason Newcomb
8bcecfff95 Handle or patterns in single_match and single_match_else 2024-08-07 11:40:15 -04:00
Jason Newcomb
514824ff9d Refactor single_match 2024-08-07 11:32:06 -04:00
Jason Newcomb
16633a2d7b Replace in_constant with is_in_const_context. Use only the state in LateContext to avoid walking the HIR tree. 2024-08-07 09:57:27 -04:00
bors
5ead90f13a Auto merge of #12150 - ithinuel:add_misleading_use_of_ok, r=y21
Add lint for `unused_result_ok`

This PR adds a lint to capture the use of `expr.ok();` when the result is not _really_ used.

This could be interpreted as the result being checked (like it is with `unwrap()` or `expect`) but
it actually only ignores the result.

`let _ = expr;` expresses that intent better.

This was also mentionned in #8994 (although not being the main topic of that issue).

changelog: [`misleading_use_of_ok`]: Add new lint to capture `.ok();` when the result is not _really_ used.
2024-08-06 19:01:41 +00:00
bors
9d9a0dcb64 Auto merge of #13225 - Jarcho:warnings, r=flip1995
Use `-D warnings` instead of `deny-warnings` feature.

r? `@flip1995`
changelog: none
2024-08-06 14:58:50 +00:00
Jason Newcomb
4e57b2c46f Use -D warnings instead of deny-warnings feature. 2024-08-06 10:46:39 -04:00
bors
cfb38819cc Auto merge of #13145 - xFrednet:07797-restriction-and-then-why, r=Jarcho
Make restriction lint's use `span_lint_and_then` (q -> w)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

sister PR of: https://github.com/rust-lang/rust-clippy/pull/13136

changelog: none
2024-08-06 04:47:27 +00:00
bors
c082bc2cb8 Auto merge of #13136 - xFrednet:07797-restriction-and-then, r=blyxyas
Make restriction lint's use `span_lint_and_then` (a -> e)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I'm also interested if it will have an impact on performance. With some of these lints, like [`clippy::implicit_return`](https://rust-lang.github.io/rust-clippy/master/index.html#/implicit_return) I expect an impact, as it was previously creating a suggestion **for every implicit return** which is just wild.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

`@blyxyas` Could you benchmark this PR? I want to get all the numbers :3

---

This also crashed our new lintcheck CI with the following message:

> Error: $GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of 1024k, got 46731k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary

Which is just wild. Like, I've [tested the first 20 lints](https://github.com/xFrednet/rust-clippy/actions/runs/10027528172) and got like four changes and then this. 50 MB of changed lint messages o.O. Looks like I'll create a separate PR to fix that step ^^

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

changelog: none

r? `@blyxyas`
2024-08-05 13:33:16 +00:00
Jason Newcomb
c2186e14de Make cargo dev deprecate require a reason 2024-08-05 09:17:46 -04:00
Jason Newcomb
2c34d58159 Store deprecated lints as an array of tuples.
Remove legacy deprecations.
Remove "View Source" link for deprecated lints.
2024-08-05 09:15:55 -04:00
Jason Newcomb
1672d5d4ed Mark some lint deprecations as renames 2024-08-05 09:10:49 -04:00
y21
234a1d35d9 recognize metavariables in tail expressions 2024-08-05 12:02:08 +02:00
bors
7ac242c3d0 Auto merge of #13213 - Alexendoo:multispan-sugg, r=y21
Remove `multispan_sugg[_with_applicability]`

They're thin wrappers over the corresponding diag method so we should just use that instead

changelog: none
2024-08-04 15:05:27 +00:00
apoisternex
66283bff5f apply [needless_return] suggestion 2024-08-04 10:54:08 -03:00
Alex Macleod
1ea7bddbdf Remove multispan_sugg[_with_applicability] 2024-08-04 13:14:23 +00:00
apoisternex
af35dcd330 Fix [needless_return] false negative when returned expression borrows a value
Fixes #12907

changelog: Fix [`needless_return`] false negative when returned expression borrows a value
2024-08-03 21:24:51 -03:00
rzvxa
5364cbea80 Respect allow inconsistent_struct_constructor on the type definition 2024-08-03 22:52:22 +03:30
bors
8dd459d4c7 Auto merge of #13209 - Alexendoo:nonminimal-bool-limit-ops, r=y21
Limit number of `nonminimal_bool` ops

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

changelog: none
2024-08-03 15:50:00 +00:00
alexey semenyuk
35dcc9bbfa Add clarification for from_iter_instead_of_collect 2024-08-03 19:28:21 +05:00
Alex Macleod
b2d0631300 Limit number of nonminimal_bool ops 2024-08-03 12:07:42 +00:00
xFrednet
0532104247
Migrating restriction lints to span_lint_and_then (e -> i) 2024-08-03 10:18:15 +02:00
xFrednet
a9d72c7107
Migrating restriction lints to span_lint_and_then (a -> d) 2024-08-03 10:18:05 +02:00
bors
1ea827fa03 Auto merge of #13115 - tesuji:rm-dup-peels, r=dswij
Remove duplicated `peel_middle_ty_refs`

TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?

changelog: none
2024-08-03 07:32:30 +00:00
bors
1aa686b9c0 Auto merge of #13126 - apoisternex:issue12751, r=dswij
Fix [`redundant_slicing`] when the slice is behind a mutable reference

Fixes #12751

changelog: Fix [`redundant_slicing`] when the slice is behind a mutable reference and a immutable reference is expected.
2024-08-03 07:23:58 +00:00
Esteban Küber
5ef38a3bc7 Do not underline suggestions for code that is already there
When a suggestion part is for already present code, do not highlight it. If after that there are no highlights left, do not show the suggestion at all.

Fix clippy lint suggestion incorrectly treated as `span_help`.
2024-08-01 18:53:42 +00:00
bors
2fc74a3931 Auto merge of #13108 - tesuji:fix_redundant_closure, r=xFrednet
Fix `redundant_closure` false positive with closures has return type contains  `'static`

Fix #13073 .

Please enable "ignore white-space change" settings in github UI for easy reviewing.

HACK: The third commit contains a hack to check if a type `T: 'static` when `fn() -> U where U: 'static`.
I don't have a clean way to check for it.

changelog: [`redundant_closure`] Fix false positive with closures has return type contains  `'static`
2024-08-01 07:55:37 +00:00
bors
5542309895 Auto merge of #13195 - GuillaumeGomez:fix-false-positive-13183, r=Manishearth
Fix false positive for `missing_backticks` in footnote references

Fixes #13183.

changelog: Fix false positive for `missing_backticks` in footnote references
2024-07-31 16:06:27 +00:00
Guillaume Gomez
edca73003b Fix false positive for missing_backticks in footnote references 2024-07-31 17:27:53 +02:00
bors
ea06fa326d Auto merge of #13177 - GuillaumeGomez:fix-broken-list-lints-config, r=xFrednet
Fix broken list for lints config

Follow-up of #13166.

Finally figured out that it was a transformation and not the source that was the problem. It now looks like this:

![Screenshot from 2024-07-29 16-29-10](https://github.com/user-attachments/assets/4b89b3fe-8f85-47b8-8d9a-505badeaeac4)

r? `@xFrednet`

changelog: none
2024-07-31 11:11:39 +00:00
bors
c6f45df3c1 Auto merge of #13181 - Alexendoo:implicit-hasher-suggestion, r=llogiq
Use a single multipart suggestion for `implicit_hasher`

The second commit individually shows the diagnostic change

----

changelog: none
2024-07-30 20:02:53 +00:00
alexey semenyuk
8bf5a83322
Fix example 2024-07-30 22:34:56 +05:00
Alex Macleod
943a8e0646 Remove some miscellaneous #[allow]s 2024-07-29 19:57:39 +00:00
Alex Macleod
33b16d31c2 implicit_hasher: use a single multipart suggestion 2024-07-29 17:56:27 +00:00
bors
834b691a9f Auto merge of #13174 - y21:if_let_mutex_multi_mutex, r=llogiq
Emit `if_let_mutex` in presence of other mutexes

Currently (master, not nightly nor stable) `if_let_mutex` does not emit a warning here:
```rs
let m1 = Mutex::new(10);
let m2 = Mutex::new(());

if let 100..=200 = *m1.lock().unwrap() {
  m2.lock();
} else {
  m1.lock();
}
```
It currently looks for the first call to `.lock()` on *any* mutex receiver inside of the if/else body, and only later (outside of the visitor) checks that the receiver matches the mutex in the scrutinee. That means that in cases like the above, it finds the `m2.lock()` expression, stops the visitor, fails the check that it's the same mutex (`m2` != `m1`) and then does not look for any other `.lock()` calls.

So, just make the receiver check also part of the visitor so that we only stop the visitor when we also find the right receiver.

The first commit has the actual changes described here. The sceond one just unnests all the `if let`s

----

changelog: none
2024-07-29 17:41:34 +00:00
Wilfried Chauveau
182c26891e
Add lint for unused_result_ok 2024-07-29 17:56:45 +01:00
Guillaume Gomez
712e8f4f48 Fix broken list for lints config 2024-07-29 16:30:59 +02:00
bors
3b64ca95a9 Auto merge of #13173 - Jarcho:conf_order, r=xFrednet
Misc changes to `clippy_config`

Contains part of #13084

Changes include:
* Sort config list and each configs lint list.
* Add default text for the two configs that were missing it.
* Switch the lint list in the configs to an attribute.
* Make `dev fmt` sort the config list.

r? `@xFrednet`

changelog: none
2024-07-29 13:19:01 +00:00
shenyifu
38a3462037 Fix fix under loop may dropping loop label when applying fix. 2024-07-29 17:43:03 +08:00
Mark Rousskov
5faea65d4d step cfg(bootstrap) 2024-07-28 14:46:29 -04:00
y21
61dcf6cfe0 inline a bunch of if lets into a single let chain 2024-07-28 18:28:24 +02:00
y21
1a1c978f8e [if_let_mutex]: make the mutex check part of the expr visitor 2024-07-28 18:27:53 +02:00
bors
668b659b47 Auto merge of #13166 - GuillaumeGomez:fix-clippy-doc, r=xFrednet
Fix display of configs in clippy doc page

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

It was simply some empty lines missing between configs. With this fix it looks like expected:

![image](https://github.com/user-attachments/assets/89c609b4-e24a-4f4a-91c1-3b49fc83584c)

r? `@xFrednet`

changelog: Fix display of configs in clippy doc page
2024-07-28 08:45:28 +00:00
Jason Newcomb
1d06ad5599 Mark the lints for each config via an attribute instead of a doc comment.. 2024-07-28 00:55:46 -04:00
Slanterns
0812732cfc stabilize is_sorted 2024-07-28 03:11:54 +08:00
bors
236c8c782b Auto merge of #13159 - Alexendoo:missing-trait-methods-stable-order, r=dswij
`missing_trait_methods`: lint methods in definition order

Lintcheck for #13157 showed a bunch of changes for `missing_trait_methods`

This is because `values_sorted` was sorting the entries by the key's [`DefPathHash`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/def_id/struct.DefPathHash.html), this is stable for a given compiler but can change across versions

changelog: none
2024-07-27 15:32:18 +00:00
bors
d20be39c7f Auto merge of #13149 - jusexton:issue-13123, r=dswij
Fix while_let_on_iterator dropping loop label when applying fix.

Loop label was not persisted when displaying help and was therefore producing broken rust code when applying fixes.

Solution was to store the `ast::Label` when creating a `higher::WhileLet` from an expression and add the label name to the lint suggestion and diagnostics.

---

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

changelog: [`while_let_on_iterator`]: Fix issue dropping loop label when displaying help and applying fixes.
2024-07-27 15:23:21 +00:00
bors
92768eeac4 Auto merge of #13053 - nyurik:rename-set_contains_or_insert, r=llogiq
Add `BTreeSet` detection to the `set_contains_or_insert` lint

* Detect `BTreeSet::contains` + `BTreeSet::insert` usage in the same way as with the `HashSet`.
CC: `@lochetti` `@bitfield`

----

changelog: [`set_contains_or_insert`]: Handle `BTreeSet` in addition to `HashSet`
2024-07-27 11:48:24 +00:00
xFrednet
4bf4c475ee
Make restriction lint's use span_lint_and_then (t -> w) 2024-07-27 13:45:02 +02:00
xFrednet
7de9c20145
Make restriction lint's use span_lint_and_then (q -> s) 2024-07-27 13:45:00 +02:00
bors
1ec502569e Auto merge of #13168 - Alexendoo:std-instead-of-core-msrv, r=Manishearth
Make `std_instead_of_core` somewhat MSRV aware

For #13158, this catches some things e.g. `core::net` and the recently stable `core::error` but not things moved individually like `UnwindSafe`, as far as I can see the version for those isn't easily available

Beta nominating since ideally we'd get this change in the same version as `core::error` becomes stable

cc `@kpreid`

changelog: none
2024-07-27 02:55:15 +00:00
Yuri Astrakhan
9964b4e053 Add BTreeSet to set_contains_or_insert
* Detect `BTreeSet::contains` + `BTreeSet::insert` usage in the same way as with the `HashSet`.
2024-07-26 22:52:07 -04:00
bors
2acbd31686 Auto merge of #121676 - Bryanskiy:polarity, r=petrochenkov
Support ?Trait bounds in supertraits and dyn Trait under a feature gate

This patch allows `maybe` polarity bounds under a feature gate. The only language change here is that corresponding hard errors are replaced by feature gates. Example:
```rust
#![feature(allow_maybe_polarity)]
...
trait Trait1 : ?Trait { ... } // ok
fn foo(_: Box<(dyn Trait2 + ?Trait)>) {} // ok
fn bar<T: ?Sized + ?Trait>(_: &T) {} // ok
```
Maybe bounds still don't do anything (except for `Sized` trait), however this patch will allow us to [experiment with default auto traits](https://github.com/rust-lang/rust/pull/120706#issuecomment-1934006762).

This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727)
2024-07-26 20:14:16 +00:00
bors
6713631b0f Auto merge of #13165 - riyueguang:master, r=Jarcho
chore: fix some comments

fix some comments

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

changelog: none
2024-07-26 17:37:20 +00:00
bors
479491ebce Auto merge of #13130 - nyurik:ref-lints, r=Centri3
Avoid ref when using format!

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing).

Inlining format args prevents accidental `&` misuse.

See also https://github.com/rust-lang/rust/issues/112156

changelog: none
2024-07-26 17:21:30 +00:00
Alex Macleod
84e36e6ce5 Make std_instead_of_core somewhat MSRV aware 2024-07-26 16:08:03 +00:00
Guillaume Gomez
b5fa6e28d4 Fix display of configs in clippy doc page 2024-07-26 14:23:46 +02:00
Alex Macleod
10fb062c48 missing_trait_methods: lint methods in definition order 2024-07-26 11:25:06 +00:00
riyueguang
8ca8ed9b07 chore: fix some comments
Signed-off-by: riyueguang <rustruby@outlook.com>
2024-07-26 17:51:22 +08:00