-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tracking issue for std::default::default() #73014
Comments
default()
function forwarding to Default::default()
@rustbot modify labels to +F-default_free_fn |
You call out |
|
FWIW I think it is often still good style to say |
I do no think this change takes away that and in certain cases you have to say |
|
A bit late to the party, but why not just a |
I am not sure I understand exactly what are you suggesting. But if the motivation described in the issues summary is not enough, please, read the discussion in #73001 |
Is there a reason why this new free function isn't added in the prelude when the feature |
@robinmoussu Any additions to the prelude need to go through their own RFC. The bar is quite high, to say the least. |
What's the status of this feature? I've found that The Book should be updated (Appendix C - Derivable Traits) but not really sure how to proceed. |
One thing that I think is worth calling out is that this is putting a free I also want to bring up the As a more general point, to be honest, I'm not a huge fan of dumping aliases to things into std. I think it invites questions like, "Wait, what's the difference between the free More generally, do we have other aliases like this in std already? I know we have things like
To be honest, this seems infrequent enough where it might be reasonable to just define an internal helper function. |
Isn't the plan to have |
I'm not aware of that plan. Could you please link to it? |
You're right my bad. It was just a reminiscence of some random reddit post. |
We discussed this in today's @rust-lang/libs-api meeting. The general sentiment was:
|
it's possible and already works (not yet in bootstrap libcore though): https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=abd79539fa8900dd7f9e9d657f5f3e9a But we are not yet confident in whether we can safely (in the stability sense) stabilize a function that uses this feature without also stabilizing something of that feature at the same time. |
Are we working on the assumption that something like |
@jhpratt If one day it becomes possible to @oli-obk That looks great. It'd be helpful to know if we could stabilize a function using @rust-lang/libs-api I'm starting an FCP to get consensus on providing the free function @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This came up with Bevy uses of a free Does not raise a warning: #![feature(default_free_fn)]
use std::default::default;
struct SomeStruct;
impl Default for SomeStruct {
fn default() -> Self {
Self { ..default() }
}
} Raises a warning: struct SomeStruct;
impl Default for SomeStruct {
fn default() -> Self {
Self {
..Default::default()
}
}
} This is #102825 |
There is one thing that I noticed: When I initialize a struct |
That’s ok, IDEs will get smarter. It’s not a reason to not do it.
…On Fri, 23 Jun 2023 at 19:12, Jakob Schikowski ***@***.***> wrote:
There is one thing that I noticed:
When I initialize a struct Foo I often start with Foo { ..Foo::default() }
and then jump to the definition of Foo::default (using rust-analyzer) to
see what the defaults are and to decide which fields I want to change.
That's possible with Foo::default() and Default::default(), but that's
not possible with the free default function (e.g. the one from bevy, it
just jumps to definition inside the bevy crate). That's very unfortunate
because from a visual perspective I would prefer ..default().
—
Reply to this email directly, view it on GitHub
<#73014 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGEJCCUR3TTMJ4M4S6HFEDXMXMAXANCNFSM4NTHZFEA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
We discussed this in the libs-api meeting today. We would prefer to see a language feature to import the Since we are unlikely to stabilize the @rfcbot fcp close |
Team member @Amanieu has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I am not familiar with the removal process, but if it is just another issue with, essentially, a revert of the original change, I can do that. Was the consensus to remove it now, or after support for importing trait methods is added to the language? If someone wants to mentor me in writing a language proposal, I could probably do that as well. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
…anieu Remove `default_free_fn` feature Closes rust-lang#73014 r? `@Amanieu`
So, the feature has been removed in favor of a language change, but without actually formally proposing the language change? Disappointing. |
TL;DR |
maybe we can have a language feature (alias) specifically for when creating structs with Example:MyStruct {
a: 1,
b: 2,
..,
} This makes sense because the language already has this syntax is places such as pattern matching |
has there been any followup RFC/tracking issue for an eventual |
For what it's worth, rust-lang/rfcs#1995 is an open issue on this, maybe we could have some discussion there to move things forward. |
The feature gate for the issue is
#![feature(default_free_fn)]
.Addition of a free
default()
function to thedefault
module.When constructing a value using
Default::default()
the word "default" is repeated twice.See #73001 for additional details, including alternative solutions.
Steps
default()
forwarding toDefault::default()
#73001Default::default()
to usedefault()
where it makes sense.Unresolved Questions
Implementation history
The text was updated successfully, but these errors were encountered: