Commit graph

19671 commits

Author SHA1 Message Date
Jakub Beránek
571118f4b0 Do not suggest assigning_clones in Clone impl 2024-04-03 20:55:34 +02:00
Francisco Salgueiro
b6486fae5c
add missing links in development guide 2024-04-03 17:07:12 +01:00
joboet
53e31dc45c rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
Jacob Pratt
e530b3d19c Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance

As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).

The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)

The new name nicely matches `ptr::without_provenance`.
2024-04-02 20:37:39 -04: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
3b1b654f56 Auto merge of #12613 - y21:vacation, r=dswij
Pause review rotation for y21

Exams are coming up for me and I want to focus on that, so I'd like to pause PR assignments to me for a bit until that's over (will still continue to look at PRs that are assigned to me and might steal some PRs to review if I find the time). :)

--------------

changelog: none
2024-04-01 21:57:50 +00: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
e36c7d55b6
test: add test cases for str 2024-04-01 16:57:31 -04:00
Yuxiang Qiu
6f6dd880bc
test: update tests 2024-04-01 16:57:31 -04:00
Yuxiang Qiu
56580406b1
style: fix fmt 2024-04-01 16:57:31 -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
y21
989f04d066 pause review rotation for y21 2024-04-01 22:35:54 +02:00
bors
2b30a5924e Auto merge of #11996 - J-ZhengLi:issue11992, r=xFrednet,ARandomDev99
fix suggestion for [`len_zero`] with macros

fixes: #11992

changelog: fix suggestion for [`len_zero`] with macros
2024-04-01 17:42:08 +00:00
J-ZhengLi
b456ed31e4 fix suggestion for [len_zero] with macros 2024-04-02 01:27:17 +08:00
bors
41e814a554 Auto merge of #12605 - xFrednet:00000-ignore-ice, r=y21
Ignore `rustc-ice-` files

When ui-test detects a crash, it writes it into a `rustc-ice-*` file. I find it a bit annoying that git always want's to add them. So this just adds these files to our `.gitignore` :D

---

changelog: none
2024-04-01 16:16:16 +00:00
xFrednet
24d20b4eae
Set RUSTC_ICE=0 in uitests and cargo dev lint 2024-04-01 17:05:55 +02:00
Aneesh Kadiyala
6a6a917fe4 Check for Default trait in initial expression 2024-04-01 20:18:03 +05:30
bors
c2681f2338 Auto merge of #12453 - y21:span_lint_into_diag, r=blyxyas
accept `String` in `span_lint*` functions directly to avoid unnecessary clones

context: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Accepting.20.60Into.3C.7BSub.7DdiagMessage.3E.60.20in.20.60span_lint*.60.20functions/near/425703273

tldr: the `span_lint*` functions now accept both `String`s, which are then reused and not recloned like before, and also `&'static str`, in which case it [doesn't need to allocate](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_error_messages/lib.rs.html#359).
Previously, it accepted `&str` and would always call `.to_string()`, which is worse in any case: it allocates for `&'static str` and forces a clone even if the caller already has a `String`.

---------

This PR has a massive diff, but the only interesting change is in the first commit, which changes the message/help/note parameter in the `span_lint*` functions to not take a `&str`, but an `impl Into<DiagMessage>`.

The second commit changes all of the errors that now occur:
- `&format!(...)` cannot be passed to `span_lint` anymore. Instead, we now simply pass `format!()` directly.
- `Into<DiagMessage>` can be `&'static str`, but not any `&str`. So this requires changing a bunch of other `&str` to `&'static str` at call sites as well.
- Added [`Sugg::into_string`](9fc88bc285/clippy_utils/src/sugg.rs (L362)), which, as opposed to `Sugg::to_string`, can take advantage of the fact that it takes ownership and is able to reuse the `String`

changelog: none
2024-04-01 14:10:40 +00:00
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
y21
bd4d456138 accept Into<{Sub}DiagMessage> in span_lint functions 2024-04-01 14:50:23 +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
xFrednet
17a61b2610
Ignore rustc-ice- files 2024-04-01 12:03:16 +02:00
bors
cb87a574fd Auto merge of #12601 - Alexendoo:box-default-style, r=llogiq
Move `box_default` to style, do not suggest turbofishes

`Box::default()` [had its `#[rustc_box]` attribute removed](https://github.com/rust-lang/rust/pull/108476/files#r1120930164) 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

changelog: [`box_default`]: Move to style

r? `@llogiq`
2024-04-01 07:57:26 +00: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
f6c006364b split up tests into fixable and unfixable now and add annotations 2024-03-30 20:54:16 +01: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
y21
9f5d31ef86 clear DefId when an expression's type changes to non-adt 2024-03-29 16:24:07 +01:00
bors
97ba291d5a Auto merge of #12582 - kpreid:stacksize, r=Manishearth
`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)

Known issues:

* The lint may report an over-estimate because codegen may be able to overlap some of these locals. However, that already affected whether the lint fired at all; I believe this change is still an improvement because it gives the user much more actionable information about _why_ the lint fired.
* Please tell me a better way to determine whether a local has a variable name.

changelog: [`large_stack_frames`]: print total size and largest component.
2024-03-29 15:07:03 +00: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