Repository navigation
Closed
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Description
The feature gate for the issue is #![feature(default_free_fn)].
Addition of a free default() function to the default module.
When constructing a value using Default::default() the word "default" is repeated twice.
See #73001 for additional details, including alternative solutions.
Steps
- Implement the RFC: Free
default()forwarding toDefault::default()#73001 - Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
- Update examples in the documentation that currently use
Default::default()to usedefault()where it makes sense.
Unresolved Questions
- Should the language allow direct import of trait methods, this feature becomes redundant. This addition is likely to be stabilized only when we decide that direct import of trait methods is will not be supported.
Implementation history
Reacted by Georg Brandl, Marc-André Lureau, KC, WGH, Robin Moussu, museun, Nathan West, Kevin, Christos Papadopoulos, bluss and 35 more
Reacted by Vadim Petrochenkov, Danny, Oscar Walter, Thomas B, jyn and Sherlock Holo
Reacted by Squirrel
Metadata
Metadata
Assignees
Labels
B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCI-libs-radarLibs issues that are tracked on the team's radar.Libs issues that are tracked on the team's radar.Libs-SmallLibs issues that are considered "small" or self-containedLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-closeThis PR / issue is in PFCP or FCP with a disposition to close it.This PR / issue is in PFCP or FCP with a disposition to close it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Activity
[-]Tracking Issue for free `default()` function forwarding to `Default::default()`[/-][+]Tracking issue for std::default::default()[/+]illia-bobyr commentedon Jun 5, 2020
@rustbot modify labels to +F-default_free_fn
bluss commentedon Jun 5, 2020
You call out
Default::default()in the description here - but why aren'tT::default()or<$any_type>::default()good alternatives? They work today, if the Default trait is in scope, and it is in the prelude.illia-bobyr commentedon Jun 5, 2020
T::default()is convenient when the compiler can not infer the type. But when it can,Tbecause redundant. Here is a discussion where this was mentioned as well: #73001RalfJung commentedon Jun 5, 2020
FWIW I think it is often still good style to say
T::default()to communicate to the human reader the type being constructed away, which can be declared very far away in the code (even in a different file).illia-bobyr commentedon Jun 6, 2020
I do no think this change takes away that and in certain cases you have to say
T::default(). The change allows you to saydefault()in cases where you are currently sayingDefault::default().birkenfeld commentedon Jun 12, 2020
Default::default()happens a lot in struct displays, withStructType { ..., StructType::default() }being as redundant asStructType { ..., Default::default() }.bestouff commentedon Jun 17, 2020
A bit late to the party, but why not just a
use Default::default()in the prelude instead ?That's less code to inline for the optimizer.
illia-bobyr commentedon Jun 19, 2020
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
robinmoussu commentedon Nov 18, 2020
Is there a reason why this new free function isn't added in the prelude when the feature
default_free_fnis used?41 remaining items
rfcbot commentedon Jul 7, 2023
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.
Rollup merge of rust-lang#113469 - JohnTitor:rm-default-free-fn, r=Am…
Rollup merge of rust-lang#113469 - JohnTitor:rm-default-free-fn, r=Am…
dscottboggs commentedon Jul 20, 2023
So, the feature has been removed in favor of a language change, but without actually formally proposing the language change? Disappointing.
minghu6 commentedon Aug 18, 2023
TL;DR
DanieliusDev commentedon Sep 3, 2023
maybe we can have a language feature (alias) specifically for when creating structs with
StructName {}to support..which expands to..Default::default.Example:
This makes sense because the language already has this syntax is places such as pattern matching
LunarLambda commentedon Nov 29, 2023
has there been any followup RFC/tracking issue for an eventual
use Trait::method;syntax?crumblingstatue commentedon Dec 29, 2023
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.