Skip to content

Conversation

@Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Apr 25, 2023

Using default to construct a unit struct increases code complexity and adds a function call. This can be avoided by simply removing the call to default and simply construct by name.

changelog: [default_constructed_unit_structs]: detects construction of unit structs using default

fixes #10609

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2023

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 25, 2023
@Icxolu Icxolu force-pushed the unitstruct_default_construction branch 2 times, most recently from e64f1c5 to e9889a4 Compare April 26, 2023 19:10
Using `default` to construct a unit struct increases code complexity and
adds a function call. This can be avoided by simply removing the call to
`default` and simply construct by name.
@Icxolu Icxolu force-pushed the unitstruct_default_construction branch from e9889a4 to 9428138 Compare April 26, 2023 19:13
@Manishearth
Copy link
Member

Some of the tests fail.

Also, this suggestion from the tests seems incorrect:

     fn vals(_: Self) -> Self {
-        Self::default()
+        Self::()
     }

@Icxolu
Copy link
Contributor Author

Icxolu commented May 1, 2023

I updated the span to fix the broken suggestion and updated the uitest output to reflect this as well as the updated diagnostics message (forget about that in the last commit)

@Manishearth
Copy link
Member

Tests still fail, since a bunch of the other tests use this syntax. You should allow this lint in those tests, or update the test code to not have this problem (if possible)

@Manishearth
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented May 3, 2023

📌 Commit 48ae5a0 has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented May 3, 2023

⌛ Testing commit 48ae5a0 with merge f9c1d15...

@bors
Copy link
Contributor

bors commented May 3, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing f9c1d15 to master...

@Icxolu Icxolu deleted the unitstruct_default_construction branch May 4, 2023 16:45
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.

Lint PhantomData::default() -> PhantomData

6 participants