Skip to content

Conversation

Erk-
Copy link
Contributor

@Erk- Erk- commented Jun 6, 2025

Add a new lint that warns when using a rest pattern when destructuring a struct. This lint was requested in this comment #10666 (comment) by @xxchan.

changelog: [rest_when_destructuring_struct] new lint

@rustbot
Copy link
Collaborator

rustbot commented Jun 6, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 6, 2025
@Erk- Erk- force-pushed the lint/rest_when_destructuring_struct branch from 1504461 to 4cdbec3 Compare June 6, 2025 12:47
@Erk- Erk- requested a review from Centri3 June 14, 2025 10:20
@Erk- Erk- force-pushed the lint/rest_when_destructuring_struct branch from 72913a1 to a314686 Compare August 17, 2025 15:09
Copy link

github-actions bot commented Aug 17, 2025

Lintcheck changes for 7770ee6

Lint Added Removed Changed
clippy::rest_when_destructuring_struct 797 0 0

This comment will be updated if you push new changes

jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 24, 2025
…rors

add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 24, 2025
…rors

add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
fmease added a commit to fmease/rust that referenced this pull request Sep 1, 2025
…rors

add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 2, 2025
…rors

add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 2, 2025
…rors

add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
rust-timer added a commit to rust-lang/rust that referenced this pull request Sep 2, 2025
Rollup merge of #145783 - Erk-:et-cetera-span, r=compiler-errors

add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 3, 2025
add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Sep 4, 2025
add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
mohe2015 pushed a commit to tucan-plus/rustfmt that referenced this pull request Sep 6, 2025
add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: rust-lang/rust-clippy#15000 (comment)

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
@rustbot

This comment has been minimized.

@Erk- Erk- force-pushed the lint/rest_when_destructuring_struct branch from 6868cd5 to b52ea0e Compare September 10, 2025 04:47
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@Erk- Erk- force-pushed the lint/rest_when_destructuring_struct branch from b52ea0e to 45d2dfa Compare October 7, 2025 20:36
@rustbot
Copy link
Collaborator

rustbot commented Oct 7, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Contributor

@ada4a ada4a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having the messages be a bit more specific really goes a long way!

Some final touches, and then it should be good to go^^

View changes since this review

let (_, end) = pat_search_pat(tcx, p);
(Pat::Str("box"), end)
},
PatKind::Deref(_) => (Pat::Str("deref!("), Pat::Str(")")),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jarcho these parens should probably be removed, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-fcp S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants