The feature gate for the issue is #![feature(default_free_fn)].
default() function to the default module.When constructing a value using Default::default() the word "default" is repeated twice.
See https://github.com/rust-lang/rust/pull/73001 for additional details, including alternative solutions.
Default::default() to use default() where it makes sense.@rustbot modify labels to +F-default_free_fn
You call out Default::default() in the description here - but why aren't T::default() or <$any_type>::default() good alternatives? They work today, if the Default trait is in scope, and it is in the prelude.
T::default() is convenient when the compiler can not infer the type. But when it can, T because redundant. Here is a discussion where this was mentioned as well: https://github.com/rust-lang/rust/pull/73001
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).
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).
I do no think this change takes away that and in certain cases you have to say T::default(). The change allows you to say default() in cases where you are currently saying Default::default().
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.
Default::default() happens a lot in struct displays, with StructType { ..., StructType::default() } being as redundant as StructType { ..., Default::default() }.
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.
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.
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 https://github.com/rust-lang/rust/pull/73001
Most helpful comment
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).