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

Don't lint Default::default if it is the udpate syntax base #8433

Merged
merged 1 commit into from
Feb 17, 2022

Conversation

hellow554
Copy link
Contributor

@hellow554 hellow554 commented Feb 14, 2022

changelog: Don't lint Default::default if it is part of the update syntax

Current clippy warns about this:

warning: calling `Foo::default()` is more clear than this expression
  --> src/main.rs:12:11
   |
12 |         ..Default::default()
   |           ^^^^^^^^^^^^^^^^^^ help: try: `Foo::default()`
   |

With these changes, it will not lint that particular expression anymore.

@rust-highfive
Copy link

r? @flip1995

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 14, 2022
@hellow554
Copy link
Contributor Author

friendly ping @flip1995

@flip1995
Copy link
Member

Sorry, I'm currently really busy with my $day_job :/

What's the reasoning behind not linting this case? Is there an issue about it?

Impl LGTM, except for the position in the if_chain, see comment above.

An Update Syntax looks like this:

   Foo {
      a: 3,
      ..Default::default()
    }

Don't lint `Default::default` here
@hellow554
Copy link
Contributor Author

Sorry, I'm currently really busy with my $day_job :/

Oh. This doesn't have to hurry, it can rest one week or more ;)

What's the reasoning behind not linting this case? Is there an issue about it?

Sort of.
Fields assign with default recommends using the .. Default::default() syntax explicitly and TBH you already write Foo { .... }, which means it is obvious which type you are currently try to default. It should be the same reasoning as with <Foo as Default>::default:

// Detect and ignore <Foo as Default>::default() because these calls do explicitly name the type.

Impl LGTM, except for the position in the if_chain, see comment above.

I moved it down right after the check that that expression is a default call. Thanks for that.

@flip1995
Copy link
Member

That's a convincing argument 👍

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 17, 2022

📌 Commit 504f3af has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Feb 17, 2022

⌛ Testing commit 504f3af with merge a4cf91b...

@bors
Copy link
Collaborator

bors commented Feb 17, 2022

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

@bors bors merged commit a4cf91b into rust-lang:master Feb 17, 2022
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