Commit graph

11277 commits

Author SHA1 Message Date
bors
e80ca2f381 Auto merge of #12615 - Kobzol:fix-recursive-clone-from, r=blyxyas
Do not suggest `assigning_clones` in `Clone` impl

This PR modifies `assigning_clones` to detect situations where the `clone` call is inside a `Clone` impl, and avoids suggesting the lint in such situations.

r? `@blyxyas`

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

changelog: Do not invoke `assigning_clones` inside `Clone` impl
2024-04-03 19:07:51 +00:00
Jakub Beránek
571118f4b0 Do not suggest assigning_clones in Clone impl 2024-04-03 20:55:34 +02:00
Aneesh Kadiyala
ac18c24fe8 Use IfLetOrMatch to avoid repetition of code 2024-04-02 22:49:00 +05:30
bors
f9f854f428 Auto merge of #12617 - y21:issue-12616, r=Alexendoo
avoid an ICE in `ptr_as_ptr` when getting the def_id of a local

Fixes #12616

`Res::def_id` can panic, so avoid calling it in favor of `opt_def_id`, so we can gracefully handle resolutions that don't have a `DefId` (e.g. local variables) and get a false negative in the worst case, rather than an ICE

changelog: Fix ICE in [`ptr_as_ptr`] when the cast expression is a function call to a local variable
2024-04-02 13:40:00 +00:00
not-elm
0478d26c8b FIX(12334): manual_swap auto fix
Initialization expressions are now generated when index is bound to a variable.

FIX: Check to see if variables are used after swap

FIX:  rename StmtKind::Local to StmtKind::Let
2024-04-02 22:30:34 +09:00
y21
e575f05a8b avoid an ICE in ptr_as_ptr when getting the def_id of a local 2024-04-02 15:09:32 +02:00
bors
95c45be1ed Auto merge of #12603 - m-rph:12594, r=Manishearth
Elide unit variables linted by `let_unit` and use `()` directly instead

Situation: `let_unit` lints when an expression binds a unit (`()`) to a variable. In some cases this binding may be passed down to another function. Currently, the lint removes the binding without considering usage.

fixes: #12594

changelog: Suggestion Fix [`let_unit`]. Clippy will remove unit bindings and replace all their instances in the body with `()`.
2024-04-01 21:14:32 +00:00
Yuxiang Qiu
b89fa5364f
fix: fix ci errors 2024-04-01 16:59:46 -04:00
Yuxiang Qiu
9d1f824878
fix: check if receiver's hir_id matches expr's hir_id 2024-04-01 16:57:31 -04:00
Yuxiang Qiu
b2ea5eef44
fix: incorrect suggestions when .then and .then_some is used 2024-04-01 16:57:31 -04:00
J-ZhengLi
b456ed31e4 fix suggestion for [len_zero] with macros 2024-04-02 01:27:17 +08:00
Aneesh Kadiyala
6a6a917fe4 Check for Default trait in initial expression 2024-04-01 20:18:03 +05:30
Alex Macleod
9d4a36841a Reword arc_with_non_send_sync note and help messages 2024-04-01 13:18:27 +00:00
y21
91f514cc83 fix fallout from previous commit 2024-04-01 15:04:45 +02:00
Quinn Sinclair
eee4db928f Replace elided variable in let_unit with () when used
Situation: `let_unit` lints when an expression binds a unit (`()`)
to a variable. In some cases this binding may be passed down to
another function. Currently, the lint removes the binding without
considering usage.

Change: All usages of the elided variable are now replaced with `()`.

fixes: #12594
2024-04-01 13:40:36 +02:00
Alex Macleod
0f63fa8c33 Move box_default to style, do not suggest turbofishes
`Box::default()` had its `#[rustc_box]` attribute removed in 1.69 so is
no longer a perf related lint

The lint is moved to style but no longer produces suggestions containing
turbofishes, as they're often longer/more annoying to type
2024-03-31 16:46:44 +00:00
bors
797d50dfe6 Auto merge of #12562 - m-rph:12501, r=y21
Allow `filter_map_identity` when the closure is typed

This extends the `filter_map_identity` lint to support typed closures.

For untyped closures, we know that the program compiles, and therefore we can safely suggest using flatten.

For typed closures, they may participate in type resolution. In this case we use `Applicability::MaybeIncorrect`.

Details:
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60filter_map_identity.60.20lint.20when.20closures.20are.20typed.3F

changelog: `filter_map_identity` will now suggest using flatten for typed closures.

r? `@y21` && `@Centri3`
2024-03-31 12:16:01 +00:00
bors
3787a0ccb8 Auto merge of #11350 - y21:issue11349, r=xFrednet
[`type_id_on_box`]: lint on any `Box<dyn _>`

Closes #11349.

It now not only lints when calling `.type_id()` on the type `Box<dyn Any>`, but also on any `Box<dyn Trait>` where `Trait` is a subtrait of `Any`

changelog: FN: [`type_id_on_box`]: lint if `Any` is a sub trait
2024-03-30 21:26:36 +00:00
y21
36e4c2083b lint on any Box<dyn _>, but provide a suggestion for subtypes of dyn Any 2024-03-30 20:52:53 +01:00
bors
cebf879de8 Auto merge of #12312 - pitaj:legacy_numeric_constants, r=xFrednet
new lint `legacy_numeric_constants`

Rework of #10997

- uses diagnostic items
- does not lint imports of the float modules (`use std::f32`)
- does not lint usage of float constants that look like `f32::MIN`

I chose to make the float changes because the following pattern is actually pretty useful
```rust
use std::f32;
let omega = freq * 2 * f32::consts::PI;
```
and the float modules are not TBD-deprecated like the integer modules.

Closes #10995

---

changelog: New lint [`legacy_numeric_constants`]
[#12312](https://github.com/rust-lang/rust-clippy/pull/12312)
2024-03-30 17:50:36 +00:00
bors
e0e7ee183f Auto merge of #12563 - J-ZhengLi:issue11513, r=Alexendoo
make sure checked type implements `Try` trait when linting [`question_mark`]

(indirectly) fixes: #12412 and fixes: #11983

---

changelog: make sure checked type implements `Try` trait when linting [`question_mark`]
2024-03-30 13:21:20 +00:00
bors
88d842ed29 Auto merge of #12579 - J-ZhengLi:issue12569, r=Alexendoo
fix [`manual_unwrap_or_default`] suggestion ignoring side-effects

fixes: #12569
closes: #12580

change applicability to `MaybeIncorrect` base on suggestion in [this zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60manual_unwrap_or_default.60.20suggestion.20removes.20comments)

---

changelog: fix [`manual_unwrap_or_default`] suggestion ignoring side-effects, and adjust its applicability.
2024-03-30 12:32:38 +00:00
J-ZhengLi
5750e4670b fix [manual_unwrap_or_default] suggestion ignoring side-effects 2024-03-30 09:18:53 +08:00
y21
37be3e4dd5 [type_id_on_box]: lint of Any subtraits 2024-03-30 01:16:41 +01:00
Michael Howell
24e1071d21 clippy: fix up include_str! spans in diagnostics 2024-03-29 13:34:01 -07:00
bors
971e4355b9 Auto merge of #12543 - Xaeroxe:manual-clamp-const, r=xFrednet,GuillaumeGomez
restrict manual_clamp to const case, bring it out of nursery

Implements the plan that I described in https://github.com/rust-lang/rust-clippy/pull/9484#issuecomment-1374522054

This does two things primarily

1. Restrict `manual_clamp` such that it will only trigger if we are able to guarantee that `clamp` won't panic at runtime.
2. Bring `manual_clamp` out of nursery status and move it into the complexity group.

changelog: [`manual_clamp`]: Restrict this lint such that it only triggers if max and min are const, and max is greater than or equal to min. Then bring it out of the nursery group.
2024-03-29 19:34:44 +00:00
bors
d928657d9d Auto merge of #12587 - shandongbinzhou:master, r=Jarcho
Fix typo in comment

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change.

It's also helpful for us that the lint name is put within backticks (`` ` ` ``),
and then encapsulated by square brackets (`[]`), for example:
```
changelog: [`lint_name`]: your change
```

If your PR fixes an issue, you can add `fixes #issue_number` into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[ ] Added passing UI tests (including committed `.stderr` file)
- \[ ] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.

---

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

changelog: None
2024-03-29 19:24:01 +00:00
Jacob Kiesel
89588f41f8 Add limitations section, move check 2024-03-29 09:38:59 -06:00
shandongbinzhou
7aac504e41 Fix typo in comment
Signed-off-by: shandongbinzhou <shandongbinzhou@outlook.com>
2024-03-29 16:17:07 +08:00
Kevin Reid
01646457a9 large_stack_frames: print total size and largest component.
Instead of just saying “this function's stack frame is big”, report:

* the (presumed) size of the frame
* the size and type of the largest local contributing to that size
* the configurable limit that was exceeded (once)
2024-03-28 11:00:42 -07:00
bors
124e68bef8 Auto merge of #12570 - J-ZhengLi:issue12569, r=Jarcho
allow [`manual_unwrap_or_default`] in const function

closes: #12568

---

changelog: allow [`manual_unwrap_or_default`] in const function

This is a small fix, I was originally decided to fix it along with `#12568` but there are some problems needs to be addressed (which is why my branch is called `issue12569` 😆 ), so I decide to open a separated PR to fix them one at a time.
2024-03-28 02:00:07 +00:00
Jules Bertholet
11b28d44bd Implement mut ref/mut ref mut 2024-03-27 09:53:23 -04:00
bors
014230ce16 Auto merge of #12572 - y21:mixed_attributes_style_style, r=llogiq
Move `mixed_attributes_style` to style

> It currently is in suspicious. I wouldn't say that the linted code is "most likely wrong or useless"
[...]
> 😅 I would still argue that this doesn't belong in the suspicious group, but rather in the style group.

These are some good points made [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/mixed_attributes_style.20on.20outlined.20modules/near/429823328).

----

changelog: Move [`mixed_attributes_style`] to the `style` category
2024-03-27 13:25:54 +00:00
y21
5b95e9099c move mixed_attributes_style to the style category 2024-03-27 13:06:32 +01:00
J-ZhengLi
c27f52d611 allow [manual_unwrap_or_default] in const function 2024-03-27 16:28:15 +08:00
J-ZhengLi
91f3fad8e7 check for init expr when linting [question_mark] 2024-03-27 08:36:08 +08:00
Matthias Krüger
4b10cb20bc Rollup merge of #123103 - compiler-errors:inherited-is-a-weird-name, r=oli-obk
Rename `Inherited` -> `TypeckRootCtxt`

`Inherited` is a confusing name. Rename it to `TypeckRootCtxt`.

I don't think this needs a type MCP or anything since it's not nearly as pervasive as `FnCtxt` , for example.

r? `@lcnr` `@oli-obk`
2024-03-26 21:23:51 +01:00
Michael Goulet
a6a1f782d6 Inherited -> TypeckRootCtxt 2024-03-26 15:22:46 -04:00
Quinn Sinclair
60937bf2db :adjust applicability for typed identity closures in filter_map_identity 2024-03-26 18:59:57 +01:00
Trevor Gross
57627d254d Change f16 and f128 clippy stubs to be nonpanicking
It turns out there is a bit of a circular dependency - I cannot add
anything to `core` because Clippy fails, and I can't actually add
correct Clippy implementations without new implementations from `core`.

Change some of the Clippy stubs from `unimplemented!` to success values
and leave a FIXME in their place to mitigate this.

Fixes <https://github.com/rust-lang/rust/issues/122587>
2024-03-26 13:37:00 -04:00
Jacob Kiesel
4d7d66462f the power of if let chain compels you 2024-03-26 10:53:41 -06:00
Jacob Kiesel
aecdb921ae short circuit logic better 2024-03-26 10:45:27 -06:00
bors
b8b9b27500 Auto merge of #12555 - GuillaumeGomez:duplicated_attribute, r=blyxyas
Don't emit `duplicated_attribute` lint on "complex" `cfg`s

Part of #12537.

changelog: Don't emit `duplicated_attribute` lint on "complex" `cfg`s
2024-03-26 15:12:23 +00:00
Guillaume Gomez
e3f3a4b7dc Don't emit duplicated_attribute lint on "complex" cfgs 2024-03-26 14:28:32 +01:00
Quinn Sinclair
9655231eb8 Allow filter_map_identity when the closure is typed
This extends the `filter_map_identity` lint to support typed closures.

For untyped closures, we know that the program compiles, and therefore
we can safely suggest using flatten.

For typed closures, they may participate in type resolution. In this case
we use `Applicability::MaybeIncorrect`.

Details:
https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60filter_map_identity.60.20lint.20when.20closures.20are.20typed.3F
2024-03-25 23:40:30 +01:00
bors
ca6a647490 Auto merge of #12554 - Kobzol:assigning-clones-unspecified, r=blyxyas
Change applicability of `assigning_clones` to `Unspecified`

Before we deal with https://github.com/rust-lang/rust-clippy/pull/12473 and the borrow checker errors, I think that it would be better to downgrade this lint, since it can break code.

changelog: Change the applicability of `assigning_clones` to `Unspecified`

r? `@blyxyas`
2024-03-25 21:39:32 +00:00
bors
b1b7352880 Auto merge of #12536 - samueltardieu:issue-12505, r=Manishearth
`manual_assert`: do not add extra semicolon

Fixes #12505

changelog: [`manual_assert`]: do not add extra semicolon to suggestion
2024-03-25 20:07:54 +00:00
y21
9e82ad87b9 [let_and_return]: avoid linting when #[cfg] attributes are present 2024-03-25 17:48:05 +00:00
bors
c3948d16b9 Auto merge of #12549 - granddaifuku:fix/suspicious_else_formatting-false-positive-when-commented-else, r=Alexendoo
fix: `suspicious_else_formatting` false positive when else is included …

This PR addresses an issue where invalid suggestions are generated for `if-else` formatting if comments contain the keyword `else`.

The root of the problem is identified [here](95c62ffae9/clippy_lints/src/formatting.rs (L217)). Specifically, when a comment contains the word `else`, the lint mistakenly interprets it as part of an `if-else` clause. This misinterpretation leads to an incorrect splitting of the snippet, resulting in erroneous suggestions.

fixes: #12497

changelog: [`suspicious_else_formatting`]: Fixes invalid suggestions when comments include word else
2024-03-25 16:51:43 +00:00
Stanislav Tkach
e0b6f30397
Remove unnecessary dot in the 'unconditional recursion' lint description 2024-03-25 17:10:26 +01:00
granddaifuku
b9da637655 Refine the logic to accurately assess if 'else' resides within comments 2024-03-26 00:46:57 +09:00
Jakub Beránek
dafb7f6d63
Change applicability of assigning_clones to Unspecified 2024-03-25 10:24:13 +01:00
granddaifuku
2a62200b8d fix: suspicious_else_formatting false positive when else is included in comments 2024-03-25 02:17:56 +09:00
Peter Jaszkowiak
f2e91ab1b9 match syms, remove lint_reasons 2024-03-24 10:16:45 -06:00
Alex Macleod
733c7af87f Rename {enter,exit}_lint_attrs to check_attributes{,_post} 2024-03-24 14:57:57 +00:00
Jacob Kiesel
0cf9d9c440 restrict manual_clamp to const case, bring it out of nursery 2024-03-23 21:28:58 -06:00
bors
95c62ffae9 Auto merge of #12239 - GuillaumeGomez:missing_transmute_annotation, r=y21
Add `missing_transmute_annotations` lint

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

r? `@blyxyas`

changelog: Add `missing_transmute_annotations` lint
2024-03-24 00:20:28 +00:00
Guillaume Gomez
ee2558223f Do no emit missing_transmute_annotations lint if the transmute is the only expr in the function 2024-03-24 00:50:28 +01:00
Guillaume Gomez
ffa12798c0 Correctly handle transmute as return value from block and let var: _ = transmute 2024-03-24 00:50:26 +01:00
Matthias Krüger
21a6f0ce87 Rollup merge of #122780 - GuillaumeGomez:rename-hir-local, r=oli-obk
Rename `hir::Local` into `hir::LetStmt`

Follow-up of #122776.

As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F).

I made this change into a separate PR because I'm less sure about this change as is. For example, we have `visit_local` and `LocalSource` items. Is it fine to keep these two as is (I supposed it is but I prefer to ask) or not? Having `Node::Local(LetStmt)` makes things more explicit but is it going too far?

r? ```@oli-obk```
2024-03-23 15:00:18 +01:00
bors
12f7c17ae0 Auto merge of #12535 - samueltardieu:issue-12528, r=y21
`useless_asref`: do not lint `.as_ref().map(Arc::clone)`

This applies to `Arc`, `Rc`, and their weak variants. Using `.clone()` would be less idiomatic.

This follows the discussion in <https://github.com/rust-lang/rust-clippy/issues/12528#issuecomment-2014444305>.

changelog: [`useless_asref`]: do not lint `.as_ref().map(Arc::clone)` and similar
2024-03-23 10:46:18 +00:00
Samuel Tardieu
fed2f28223 Do not rewrite .as_ref().map(Arc::clone) and similar 2024-03-23 09:59:14 +01:00
Samuel Tardieu
02fc25635e Add should_call_clone_as_function() utility function 2024-03-23 09:59:14 +01:00
bors
db416211d6 Auto merge of #12486 - J-ZhengLi:issue12435, r=y21
don't lint [`mixed_attributes_style`] when mixing docs and other attrs

fixes: #12435
fixes: #12436
fixes: #12530

---

changelog: don't lint [`mixed_attributes_style`] when mixing different kind of attrs; and move it to late pass;
2024-03-23 04:28:19 +00:00
J-ZhengLi
e9f25b3b09 add test cases for #12435
don't lint [`mixed_attributes_style`] when mixing docs and other attrs

add test files for issue #12436

move [`mixed_attributes_style`] to `LateLintPass` to enable global `allow`

stop [`mixed_attributes_style`] from linting on different attributes

add `@compile-flags` to [`mixed_attributes_style`]'s test;

turns out not linting in test mod is not a FN.

Apply suggestions from code review

Co-authored-by: Timo <30553356+y21@users.noreply.github.com>

move [`mixed_attributes_style`] to late pass and stop it from linting on different kind of attributes
2024-03-23 12:13:39 +08:00
bors
e5ece90f64 Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlin
Replace visibility test with reachability test in dead code detection

Fixes https://github.com/rust-lang/rust/issues/119545

Also included is a fix for an error now flagged by the lint
2024-03-23 00:37:05 +00:00
Samuel Tardieu
c137c78ba2 manual_assert: do not add extra semicolon 2024-03-23 01:32:25 +01:00
Samuel Tardieu
6b12829943 Move is_parent_stmt to clippy_utils 2024-03-23 01:30:47 +01:00
bors
02e11b98dd Auto merge of #122900 - matthiaskrgr:rollup-nls90mb, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #114009 (compiler: allow transmute of ZST arrays with generics)
 - #122195 (Note that the caller chooses a type for type param)
 - #122651 (Suggest `_` for missing generic arguments in turbofish)
 - #122784 (Add `tag_for_variant` query)
 - #122839 (Split out `PredicatePolarity` from `ImplPolarity`)
 - #122873 (Merge my contributor emails into one using mailmap)
 - #122885 (Adjust better spastorino membership to triagebot's adhoc_groups)
 - #122888 (add a couple more tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-22 22:35:11 +00:00
Jeremy S
2d499d8f4a
Fix typo in exhaustive_items.rs 2024-03-22 22:19:31 +00:00
bors
c7bb200054 Auto merge of #12532 - samueltardieu:issue-12531, r=llogiq
Add necessary parentheses to `manual_unwrap_or_default` lint output

Fix #12531

----

changelog: [`manual_unwrap_or_default`]: add parentheses to suggestion when appropriate
2024-03-22 19:53:26 +00:00
Guillaume Gomez
43a61e9aca Rename hir::Node::Local into hir::Node::LetStmt 2024-03-22 20:48:36 +01:00
Guillaume Gomez
bd9efd5265 Rename hir::Local into hir::LetStmt 2024-03-22 20:36:21 +01:00
bors
44a5edaaab Auto merge of #12507 - Alexendoo:unused-qualifications, r=dswij
Enable unused_qualifications lint

Fixes a common nit

changelog: none
2024-03-22 16:15:06 +00:00
Alex Macleod
a24d12b7aa Enable unused_qualifications lint 2024-03-22 15:58:29 +00:00
Michael Goulet
6b04fc24fc Fix clippy 2024-03-22 11:16:57 -04:00
Michael Goulet
f9ad628acd And the tools too 2024-03-22 11:13:29 -04:00
Michael Goulet
c92b350581 Programmatically convert some of the pat ctors 2024-03-22 11:13:29 -04:00
Michael Goulet
0b810866ef Eagerly convert some ctors to use their specialized ctors 2024-03-22 11:12:01 -04:00
bors
52b2a5e50d Auto merge of #12529 - samueltardieu:issue-12528, r=y21
Do not warn on .map(_::clone) for Arc, Rc, and their weak variants

Those constructions are idiomatic, and using `Arc::clone(x)` and `Rc::clone(x)` is often the recommended way of cloning a `Arc` or a `Rc`.

Fix #12528

changelog: [`map_clone`]: do not warn on `.map(_::clone)` for `Arc`, `Rc`, and their `Weak` variants
2024-03-22 15:11:52 +00:00
Samuel Tardieu
2ffd1336c7 Add necessary parentheses to manual_unwrap_or_default lint output 2024-03-22 15:42:55 +01:00
bors
f2020c884f Auto merge of #12508 - y21:issue12506, r=llogiq
Fix infinite loop in `cast_sign_loss` when peeling unwrap method calls

Fixes #12506

The lint wants to peel method calls but didn't actually reassign the expression, leading to an infinite loop.

----

changelog: Fix infinite loop in [`cast_sign_loss`] when having two chained `.unwrap()` calls
2024-03-22 13:19:09 +00:00
bors
403433f2f7 Auto merge of #12526 - kpreid:patch-2, r=blyxyas
Mention `size_hint()` effect in `flat_map_option` lint documentation.

The previous documentation for `flat_map_option` mentioned only readability benefits, but there is also at least one performance benefit: the `size_hint()` upper bound is preserved, whereas `flat_map().size_hint()` is always `(0, None)`.

Program demonstrating this difference:

```rust
fn main() {
    let evens = |i| if i % 2 == 0 { Some(i) } else { None };

    dbg!(
        [1, 2, 3].iter().flat_map(evens).size_hint(),
        [1, 2, 3].iter().filter_map(evens).size_hint(),
    );
}
```

changelog: [`flat_map_option`]: Mention the benefit to `size_hint()`.
2024-03-22 13:09:28 +00:00
bors
879899ca89 Auto merge of #122869 - matthiaskrgr:rollup-0navj4l, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #121619 (Experimental feature postfix match)
 - #122370 (Gracefully handle `AnonConst` in `diagnostic_hir_wf_check()`)
 - #122537 (interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit)
 - #122542 (coverage: Clean up marker statements that aren't needed later)
 - #122800 (Add `NonNull::<[T]>::is_empty`.)
 - #122820 (Stop using `<DefId as Ord>` in various diagnostic situations)
 - #122847 (Suggest `RUST_MIN_STACK` workaround on overflow)
 - #122855 (Fix Itanium mangling usizes)
 - #122863 (add more ice tests )

r? `@ghost`
`@rustbot` modify labels: rollup
2024-03-22 12:29:42 +00:00
Matthias Krüger
a580b4e6e0 Rollup merge of #121619 - RossSmyth:pfix_match, r=petrochenkov
Experimental feature postfix match

This has a basic experimental implementation for the RFC postfix match (rust-lang/rfcs#3295, #121618). [Liaison is](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Postfix.20Match.20Liaison/near/423301844) ```@scottmcm``` with the lang team's [experimental feature gate process](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md).

This feature has had an RFC for a while, and there has been discussion on it for a while. It would probably be valuable to see it out in the field rather than continue discussing it. This feature also allows to see how popular postfix expressions like this are for the postfix macros RFC, as those will take more time to implement.

It is entirely implemented in the parser, so it should be relatively easy to remove if needed.

This PR is split in to 5 commits to ease review.

1. The implementation of the feature & gating.
2. Add a MatchKind field, fix uses, fix pretty.
3. Basic rustfmt impl, as rustfmt crashes upon seeing this syntax without a fix.
4. Add new MatchSource to HIR for Clippy & other HIR consumers
2024-03-22 11:36:58 +01:00
bors
fc053c3296 Auto merge of #12522 - rust-lang:Manishearth-patch-1, r=xFrednet
Correct version for incompatible_msrv

Unsure what happened here

Probably what caused https://github.com/rust-lang/blog.rust-lang.org/issues/1277

changelog: none
2024-03-22 10:12:29 +00:00
Samuel Tardieu
7c9fe30ce4 Do not warn on .map(_::clone) for Arc, Rc, and their weak variants
Those constructions are idiomatic, and using `Arc::clone(x)` and
`Rc::clone(x)` is often the recommended way of cloning a `Arc` or a
`Rc`.
2024-03-22 10:02:09 +01:00
León Orell Valerian Liehr
b7026f87f5 Update (doc) comments
Several (doc) comments were super outdated or didn't provide enough context.

Some doc comments shoved everything in a single paragraph without respecting
the fact that the first paragraph should be a single sentence because rustdoc
treats these as item descriptions / synopses on module pages.
2024-03-22 06:31:51 +01:00
León Orell Valerian Liehr
75390b9f7f Rename AstConv to HIR ty lowering
This includes updating astconv-related items and a few local variables.
2024-03-22 06:31:40 +01:00
Catherine
0c392d918a new lint legacy_numeric_constants 2024-03-21 17:10:02 -06:00
Philipp Krones
0e62b18435 Merge commit '9d6f41691ed9dbfaec2a2df2661c42451f2fe0d3' into clippy-subtree-update 2024-03-21 22:20:40 +01:00
Kevin Reid
15da6e735a
Mention size_hint() effect in flat_map_option lint documentation. 2024-03-21 14:06:45 -07:00
Philipp Krones
e1d15b5b87
Bump Clippy version -> 0.1.79 2024-03-21 22:06:41 +01:00
Philipp Krones
7d42d736c5
Merge remote-tracking branch 'upstream/master' into rustup 2024-03-21 22:05:29 +01:00
Rua
238cd36671 Fix documentation typo "appects" > "affects" 2024-03-21 18:22:23 +01:00
Michael Goulet
bc0965e2ff Implement macro-based deref!() syntax for deref patterns
Stop using `box PAT` syntax for deref patterns, as it's misleading and
also causes their semantics being tangled up.
2024-03-21 11:42:49 -04:00
Manish Goregaokar
87b93520a8
Correct version for incompatible_msrv
Unsure what happened here

Probably what caused https://github.com/rust-lang/blog.rust-lang.org/issues/1277
2024-03-21 15:41:12 +00:00
Matthias Krüger
fb1b198cea Rollup merge of #122799 - estebank:issue-122569, r=fee1-dead
Replace closures with `_` when suggesting fully qualified path for method call

```
error[E0283]: type annotations needed
  --> $DIR/into-inference-needs-type.rs:12:10
   |
LL |         .into()?;
   |          ^^^^
   |
   = note: cannot satisfy `_: From<...>`
   = note: required for `FilterMap<...>` to implement `Into<_>`
help: try using a fully qualified path to specify the expected types
   |
LL ~     let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec
LL |         .iter()
LL |         .map(|s| s.strip_prefix("t"))
LL ~         .filter_map(Option::Some))?;
   |
```

Fix #122569.
2024-03-21 12:05:08 +01:00
bors
e8794ff541 Auto merge of #121123 - compiler-errors:item-assumptions, r=oli-obk
Split an item bounds and an item's super predicates

This is the moral equivalent of #107614, but instead for predicates this applies to **item bounds**. This PR splits out the item bounds (i.e. *all* predicates that are assumed to hold for the alias) from the item *super predicates*, which are the subset of item bounds which share the same self type as the alias.

## Why?

Much like #107614, there are places in the compiler where we *only* care about super-predicates, and considering predicates that possibly don't have anything to do with the alias is problematic. This includes things like closure signature inference (which is at its core searching for `Self: Fn(..)` style bounds), but also lints like `#[must_use]`, error reporting for aliases, computing type outlives predicates.

Even in cases where considering all of the `item_bounds` doesn't lead to bugs, unnecessarily considering irrelevant bounds does lead to a regression (#121121) due to doing extra work in the solver.

## Example 1 - Trait Aliases

This is best explored via an example:

```
type TAIT<T> = impl TraitAlias<T>;

trait TraitAlias<T> = A + B where T: C;
```

The item bounds list for `Tait<T>` will include:
* `Tait<T>: A`
* `Tait<T>: B`
* `T: C`

While `item_super_predicates` query will include just the first two predicates.

Side-note: You may wonder why `T: C` is included in the item bounds for `TAIT`? This is because when we elaborate `TraitAlias<T>`, we will also elaborate all the predicates on the trait.

## Example 2 - Associated Type Bounds

```
type TAIT<T> = impl Iterator<Item: A>;
```

The `item_bounds` list for `TAIT<T>` will include:
* `Tait<T>: Iterator`
* `<Tait<T> as Iterator>::Item: A`

But the `item_super_predicates` will just include the first bound, since that's the only bound that is relevant to the *alias* itself.

## So what

This leads to some diagnostics duplication just like #107614, but none of it will be user-facing. We only see it in the UI test suite because we explicitly disable diagnostic deduplication.

Regarding naming, I went with `super_predicates` kind of arbitrarily; this can easily be changed, but I'd consider better names as long as we don't block this PR in perpetuity.
2024-03-21 06:12:24 +00:00
Esteban Küber
9022122b8b Replace closures with _ when suggesting fully qualified path for method call
```
error[E0283]: type annotations needed
  --> $DIR/into-inference-needs-type.rs:12:10
   |
LL |         .into()?;
   |          ^^^^
   |
   = note: cannot satisfy `_: From<...>`
   = note: required for `FilterMap<...>` to implement `Into<_>`
help: try using a fully qualified path to specify the expected types
   |
LL ~     let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec
LL |         .iter()
LL |         .map(|s| s.strip_prefix("t"))
LL ~         .filter_map(Option::Some))?;
   |
```

Fix #122569.
2024-03-21 00:07:44 +00:00
bors
a16a9ed4c6 Auto merge of #12509 - xFrednet:changelog-1-77, r=dswij
Changelog for Clippy 1.77 🏫

Roses are violets,
Red is blue,
Let's create a world,
Perfect for me and you

---

### The cat of this release is: *Luigi*

<img width=500 src="https://github.com/rust-lang/rust-clippy/assets/17087237/ea13d05c-e5ba-4189-9e16-49bf1b43c468" alt="The cats of this Clippy release" />

The cat for the next release can be voted on: [here](https://forms.gle/57gbrNvXtCUmrHYh6)

The cat for the next next release can be nominated in the comments and will be voted in the next changelog PR (Submission deadline is 2024-03-30 23:59CET)

---

changelog: none
2024-03-20 23:43:14 +00:00
bors
34766a6792 Auto merge of #12496 - Jacherr:issue-12492, r=blyxyas
Disable `cast_lossless` when casting to u128 from any (u)int type

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

Disables `cast_lossless` when casting to u128 from any int or uint type. The lint states that when casting to any int type, there can potentially be lossy behaviour if the source type ever exceeds the size of the destination type in the future, which is impossible with a destination of u128.

It's possible this is a bit of a niche edge case which is better addressed by just disabling the lint in code, but I personally couldn't think of any good reason to still lint in this specific case - maybe except if the source is a bool, for readability reasons :).

changelog: FP: `cast_lossless`: disable lint when casting to u128 from any (u)int type
2024-03-20 23:08:45 +00:00
bendn
a356785065 reasoning 2024-03-21 05:48:16 +07:00
bors
5b7efe827f Auto merge of #12516 - humannum14916:assigning_clones_msrv, r=Alexendoo
Make `assigning_clones` MSRV check more precise

Continuation of #12511

`clone_into` is the only suggestion subject to the 1.63 MSRV requirement, and the lint should still emit other suggestions regardless of the MSRV.

changelog: [assigning_clones]: only apply MSRV check to `clone_into` suggestions.
2024-03-20 20:41:41 +00:00
humannum14916
5f7b3c5eea Only enforce MSRV check on .clone_into() suggestions 2024-03-20 14:04:12 -04:00
Michael Goulet
1dbabc1767 Bless test fallout (duplicate diagnostics) 2024-03-20 13:00:34 -04:00
bendn
22f57ff584 fix for x in y unsafe { } 2024-03-20 23:33:16 +07:00
Guillaume Gomez
54d1260174 Rename hir::Let into hir::LetExpr 2024-03-20 16:47:11 +01:00
Jacherr
477108d382 FP: cast_lossless: disable lint when casting to (u)128 from any (u)int type 2024-03-20 13:20:51 +00:00
bors
89aba8d45d Auto merge of #12511 - humannum14916:assigning_clones_msrv, r=Alexendoo
`assigning_clones` should respect MSRV

Fixes: #12502

This PR fixes the `assigning_clones` lint suggesting to use `clone_from` or `clone_into` on incompatible MSRVs.

`assigning_clones` will suggest using either `clone_from` or `clone_into`, both of which were stabilized in 1.63. If the current MSRV is below 1.63, the lint should not trigger.

changelog: [`assigning_clones`]: don't lint when the MSRV is below 1.63.
2024-03-19 23:46:51 +00:00
humannum14916
21a97f0192 Specify an MSRV of 1.63.0 for assigning_clones 2024-03-19 17:05:32 -04:00
goodmost
e7c3e049f8 chore: fix typo
Signed-off-by: goodmost <zhaohaiyang@outlook.com>
2024-03-19 22:09:05 +08:00
bors
56288a72be Auto merge of #122021 - oli-obk:delangitemification, r=compiler-errors
Use hir::Node helper methods instead of repeating the same impl multiple times

I wanted to do something entirely different and stumbled upon a bunch of cleanups
2024-03-19 11:05:45 +00:00
y21
3930f8b45d fix infinite loop when peeling unwrap method calls 2024-03-19 00:13:18 +01:00
xFrednet
83af0e5928
Update version attribute for 1.77 lints 2024-03-18 22:59:52 +01:00
Oli Scherer
0dc876991c Deduplicate associated_body and body_id
They match on almost the same patterns, which is fishy.

Also turn `associated_body` into a method and do some cleanups nearby the call sites
2024-03-18 18:12:32 +00:00
Oli Scherer
003c4bc7bf Avoid various uses of Option<Span> in favor of using DUMMY_SP in the few cases that used None 2024-03-18 09:34:08 +00:00
bors
b5dcaae844 Auto merge of #12498 - y21:issue12489, r=blyxyas
[`map_entry`]: call the visitor on the local's `else` block

Fixes #12489

The lint already has all the logic it needs for figuring out if it can or can't suggest a closure if it sees control flow expressions like `break` or `continue`, but it was ignoring the local's else block, which meant that it didn't see the `return None;` in a `let..else`.

changelog: [`map_entry`]: suggest `if let` instead of a closure when `return` expressions exist in the else block of a `let..else`
2024-03-18 06:28:47 +00:00
bors
e9a50f2859 Auto merge of #12451 - Jacherr:issue-12391, r=llogiq
new restriction lint: `integer_division_remainder_used`

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

Introduces a restriction lint which disallows the use of `/` and `%` operators on any `Int` or `Uint` types (i.e., any that use the default `Div` or `Rem` trait implementations). Custom implementations of these traits are ignored.

----

changelog: Add new restriction lint [`integer_division_remainder_used`]
2024-03-17 08:10:32 +00:00
bors
d202eb653b Auto merge of #12450 - cookie-s:fix-optopt-duplicate-diags, r=llogiq
[`option_option`]: Fix duplicate diagnostics

Relates to #12379

This `option_option` lint change skips checks against `ty`s inside `field_def`s defined by external macro to prevent duplicate diagnostics to the same span `ty` by multiple `Struct` definitions.

---

changelog: [`option_option`]: Fix duplicate diagnostics
2024-03-17 07:51:49 +00:00
bors
67fa36a9f2 Auto merge of #12479 - y21:readonly_write_lock_perf, r=Jarcho
move `readonly_write_lock` to perf

[There haven't been any issues](https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+readonly_write_lock) since its creation and it's a pretty useful lint I think, so I'd say it's worth giving it a try?

Did a lintcheck run on 300 crates with no results, but I guess `RwLock` is usually not something that's used much in libraries.

changelog: move [`readonly_write_lock`] to perf (now warn-by-default)
2024-03-17 03:35:17 +00:00
bors
12ecaa8367 Auto merge of #12482 - J-ZhengLi:issue12131, r=Jarcho
fix [`dbg_macro`] FN when dbg is inside some complex macros

fixes: #12131

It appears that [`root_macro_call_first_node`] only detects `println!` in the following example:
```rust
println!("{:?}", dbg!(s));
```
---

changelog: fix [`dbg_macro`] FN when `dbg` is inside some complex macros

(re-opening b'cuz bors doesn't like my previous one)
2024-03-17 03:22:20 +00:00
bors
59a5ad4840 Auto merge of #12441 - CBSpeir:dedup-else-if-without-else, r=dswij
[`else_if_without_else`]: Fix duplicate diagnostics

Relates to: #12379

changelog:  Fix duplicate lint diagnostic emission from [`else_if_without_else`]
2024-03-16 15:55:11 +00:00
y21
4e72ca31b5 [map_entry]: call the visitor on the local's else block 2024-03-16 14:15:45 +01:00
kcz
9408c5974e
[option_option]: Use span.from_expansion 2024-03-15 21:25:24 -04:00
Guillaume Gomez
79766577f2 Add missing_transmute_annotation lint 2024-03-15 20:31:51 +01:00
bors
c9f24827b3 Auto merge of #12493 - y21:issue12491, r=Alexendoo
fix span calculation for non-ascii in `needless_return`

Fixes #12491

Probably fixes #12328 as well, but that one has no reproducer, so 🤷

The bug was that the lint used `rfind()` for finding the byte index of the start of the previous non-whitespace character:
```
// abc\n     return;
     ^
```
... then subtracting one to get the byte index of the actual whitespace (the `\n` here).
(Subtracting instead of adding because it treats this as the length from the `return` token to the `\n`)

That's correct for ascii, like here, and will get us to the `\n`, however for non ascii, the `c` could be multiple bytes wide, which would put us in the middle of a codepoint if we simply subtract 1 and is what caused the ICE.

There's probably a lot of ways we could fix this.
This PR changes it to iterate backwards using bytes instead of characters, so that when `rposition()` finally finds a non-whitespace byte, we *know* that we've skipped exactly 1 byte. This was *probably*(?) what the code was intending to do

changelog: Fix ICE in [`needless_return`] when previous line end in a non-ascii character
2024-03-15 17:30:23 +00:00
Guillaume Gomez
1e30c2915b Rollup merge of #122513 - petrochenkov:somehir4, r=fmease
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`

Also replace a few `hir_node()` calls with `hir_node_by_def_id()`.

Follow up to https://github.com/rust-lang/rust/pull/120943.
2024-03-15 17:24:09 +01:00
y21
d3f8f3e9d7 fix span calculation for non-ascii in needless_return 2024-03-15 16:59:23 +01:00
bors
5a11fefc25 Auto merge of #12432 - Ethiraric:fix-12411, r=y21
[`unused_enumerate_index`]: trigger on method calls

The lint used to check for patterns looking like:
```rs
for (_, x) in some_iter.enumerate() {
    // Index is ignored
}
```

This commit further checks for chained method calls constructs where we
can detect that the index is unused. Currently, this checks only for the
following patterns:
```rs
some_iter.enumerate().map_function(|(_, x)| ..)
let x = some_iter.enumerate();
x.map_function(|(_, x)| ..)
```
where `map_function` is one of `all`, `any`, `filter_map`, `find_map`,
`flat_map`, `for_each` or `map`.

Fixes #12411.

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

changelog: [`unused_enumerate_index`]: add detection for method chains such as `iter.enumerate().map(|(_, x)| x)`
2024-03-14 22:26:06 +00:00
Ethiraric
dadcd94b2a [unused_enumerate_index]: Keep explicit element type
Prior to this change, it might be that the lint would remove an explicit
type that was necessary for the type system to keep track of types.

This should be the last change that prevented this lint to be machine
applicable.
2024-03-14 23:12:47 +01:00
bors
b667d02340 Auto merge of #12472 - GuillaumeGomez:fix-10262, r=blyxyas
Don't emit `doc_markdown` lint for missing backticks if it's inside a quote

Fixes #10262.

changelog: Don't emit `doc_markdown` lint for missing backticks if it's inside a quote
2024-03-14 21:39:25 +00:00
Vadim Petrochenkov
f55a04928f hir: Remove opt_local_def_id_to_hir_id and opt_hir_node_by_def_id
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-14 22:34:24 +03:00
bors
8a78128e9d Auto merge of #12386 - Ethiraric:fix-12381, r=blyxyas
[`use_self`]: Make it aware of lifetimes

Have the lint trigger even if `Self` has generic lifetime parameters.

```rs
impl<'a> Foo<'a> {
    type Item = Foo<'a>; // Can be replaced with Self

    fn new() -> Self {
        Foo { // No lifetime, but they are inferred to be that of Self
              // Can be replaced as well
            ...
        }
    }

    // Don't replace `Foo<'b>`, the lifetime is different!
    fn eq<'b>(self, other: Foo<'b>) -> bool {
        ..
    }
```

Fixes #12381

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

changelog: [`use_self`]: Have the lint trigger even if `Self` has generic lifetime parameters
2024-03-14 16:28:57 +00:00
Guillaume Gomez
0e2897fd4f Rename hir::StmtKind::Local into hir::StmtKind::Let 2024-03-14 12:42:04 +01:00
maekawatoshiki
5f8d8f1656
Simplify logic 2024-03-14 12:48:34 +09:00
maekawatoshiki
560a5a8cd1 Fix logic 2024-03-14 12:36:55 +09:00
maekawatoshiki
20e4c74521 Handle false positive with map_clone 2024-03-14 12:36:54 +09:00
J-ZhengLi
fe4e0aca73 checks dbg inside other macros as well (but no ext macro);
some refractoring;
2024-03-14 09:32:05 +08:00
J-ZhengLi
0535f55831 lint nested dbg! macros, split tests 2024-03-14 09:29:29 +08:00
J-ZhengLi
1fe884401a fix [dbg_macro] FN when dbg is inside some complex macros 2024-03-14 09:29:29 +08:00
y21
adcbb4a9b7 move readonly_write_lock to perf 2024-03-13 20:56:53 +01:00
Ethiraric
7cdeac5773 [unused_enumerate_index]: trigger on method calls
The lint used to check for patterns looking like:
```rs
for (_, x) in some_iter.enumerate() {
    // Index is ignored
}
```

This commit further checks for chained method calls constructs where we
can detect that the index is unused. Currently, this checks only for the
following patterns:
```rs
some_iter.enumerate().map_function(|(_, x)| ..)
let x = some_iter.enumerate();
x.map_function(|(_, x)| ..)
```
where `map_function` is one of `all`, `any`, `filter_map`, `find_map`,
`flat_map`, `for_each` or `map`.

Fixes #12411.
2024-03-13 20:28:01 +01:00
Guillaume Gomez
03d7ae8153 Also handle <blockquote> and <q> HTML tags 2024-03-13 19:31:01 +01:00
Guillaume Gomez
11759d1bad Don't emit doc_markdown lint for missing backticks if it's inside a quote 2024-03-13 19:25:36 +01:00
bors
73be4863f0 Auto merge of #12459 - y21:unconditional_recursion_from_into, r=Jarcho
lint when calling the blanket `Into` impl from a `From` impl

Closes #11150
```
warning: function cannot return without recursing
  --> x.rs:9:9
   |
9  | /         fn from(value: f32) -> Self {
10 | |             value.into()
11 | |         }
   | |_________^
   |
note: recursive call site
  --> x.rs:10:13
   |
10 |             value.into()
   |             ^^^^^^^^^^^^
```

I'm also thinking that we can probably generalize this lint to #11032 at some point (instead of hardcoding a bunch of impls), like how rustc's `unconditional_recursion` works, at least up to one indirect call, but this still seems useful for now :)

I've also noticed that we use `fn_def_id` in a bunch of lints and then try to get the node args of the call in a separate step, so I made a helper function that does both in one. I intend to refactor a bunch of uses of `fn_def_id` to use this later

I can add more test cases, but this is already using much of the same logic that exists for the other impls that this lint looks for (e.g. making sure that there are no conditional returns).

changelog: [`unconditional_recursion`]: emit a warning inside of `From::from` when unconditionally calling the blanket `.into()` impl
2024-03-13 16:32:25 +00:00
y21
65defdb474 [unconditional_recursion]: catch From -> Into -> From 2024-03-13 17:22:54 +01:00
bors
99e8000b92 Auto merge of #12466 - J-ZhengLi:issue12377, r=blyxyas
fix [`empty_docs`] trigger in proc-macro

fixes: #12377

---

changelog: fix [`empty_docs`] trigger in proc-macros
2024-03-12 19:23:26 +00:00
Catherine Flores
244d7da817 [cast_lossless]: Suggest type alias instead of the aliased type 2024-03-12 10:16:27 -05:00
bors
3a149111ba Auto merge of #12469 - pavedroad:master, r=y21
chore: fix some typos

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change.

It's also helpful for us that the lint name is put within backticks (`` ` ` ``),
and then encapsulated by square brackets (`[]`), for example:
```
changelog: [`lint_name`]: your change
```

If your PR fixes an issue, you can add `fixes #issue_number` into this
PR description. This way the issue will be automatically closed when
your PR is merged.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[x] Followed [lint naming conventions][lint_naming]
- \[ ] Added passing UI tests (including committed `.stderr` file)
- \[ ] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.

---

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

changelog:
2024-03-12 10:00:15 +00:00