Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't destructure struct with no public fields #16752

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

Lindronics
Copy link
Contributor

@Lindronics Lindronics commented Mar 4, 2024

Unfortunately I missed this case in #16638.

If a struct only has private members, the assist should not be applicable. Though valid syntax exists (Foo { .. }), it isn't particularly useful. Since this case applies to a lot of common types (Arc, Vec, ...), it probably makes the most sense to hide the action.

As a side effect, this also disables the action for unit structs, where it also isn't particularly useful. I'd be open to changing it though if you think it makes more sense to keep it.

This also fixes the make::record_pat_field_list function to produce valid syntax if the field list is empty, as it is used in other places too.

Current behaviour

// In crate `other_crate`
pub struct Foo { bar: i32 }

// In current crate
fn do_something(foo: other_crate::Foo) {}

// Becomes
fn do_something(other_crate::Foo { , .. }: other_crate::Foo) {}

Fixed behaviour

Assist should not be applicable in this case anymore.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 4, 2024
@Lindronics Lindronics marked this pull request as ready for review March 4, 2024 22:04
@Lindronics Lindronics changed the title fix: Destructure struct with no public fields fix: Don't destructure struct with no public fields Mar 4, 2024
Copy link
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

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

Thanks!

@Veykril
Copy link
Member

Veykril commented Mar 5, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Mar 5, 2024

📌 Commit 2a4ba42 has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Mar 5, 2024

⌛ Testing commit 2a4ba42 with merge 0c2e9fe...

@bors
Copy link
Contributor

bors commented Mar 5, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing 0c2e9fe to master...

@bors bors merged commit 0c2e9fe into rust-lang:master Mar 5, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants