Skip to content

Tracking issue for std::default::default() #73014

Closed

Description

@illia-bobyr

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

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

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Jun 5, 2020
  2. changed the title [-]Tracking Issue for free `default()` function forwarding to `Default::default()`[/-] [+]Tracking issue for std::default::default()[/+] on Jun 5, 2020
  3. illia-bobyr commented on Jun 5, 2020

    @illia-bobyr
    ContributorAuthor

    @rustbot modify labels to +F-default_free_fn

  4. bluss commented on Jun 5, 2020

    @bluss
    Contributor

    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.

  5. illia-bobyr commented on Jun 5, 2020

    @illia-bobyr
    ContributorAuthor

    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: #73001

  6. RalfJung commented on Jun 5, 2020

    @RalfJung
    Member

    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).

  7. illia-bobyr commented on Jun 6, 2020

    @illia-bobyr
    ContributorAuthor

    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().

  8. birkenfeld commented on Jun 12, 2020

    @birkenfeld
    Contributor

    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.

    Default::default() happens a lot in struct displays, with StructType { ..., StructType::default() } being as redundant as StructType { ..., Default::default() }.

  9. bestouff commented on Jun 17, 2020

    @bestouff
    Contributor

    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.

  10. illia-bobyr commented on Jun 19, 2020

    @illia-bobyr
    ContributorAuthor

    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 #73001

  11. added
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    Libs-SmallLibs issues that are considered "small" or self-contained
    I-libs-radarLibs issues that are tracked on the team's radar.
    on Jul 29, 2020
  12. robinmoussu commented on Nov 18, 2020

    @robinmoussu

    Is there a reason why this new free function isn't added in the prelude when the feature default_free_fn is used?

  13. 41 remaining items

  14. added and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Jul 7, 2023
  15. rfcbot commented on Jul 7, 2023

    @rfcbot

    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.

  16. added 2 commits that reference this issue on Jul 9, 2023
    28ed0ec
    ec479ba
  17. dscottboggs commented on Jul 20, 2023

    @dscottboggs

    So, the feature has been removed in favor of a language change, but without actually formally proposing the language change? Disappointing.

  18. minghu6 commented on Aug 18, 2023

    @minghu6

    We discussed this in the libs-api meeting today. We would prefer to see a language feature to import the Default::default method directly. The language team seems to be open to this, but someone needs to write up a language proposal and drive the design of this feature.

    Since we are unlikely to stabilize the default function as-is, we would like to remove it from the standard library.

    @rfcbot fcp close

    TL;DR

  19. DanieliusDev commented on Sep 3, 2023

    @DanieliusDev

    maybe we can have a language feature (alias) specifically for when creating structs with StructName {} to support .. which expands to ..Default::default.

    Example:

    MyStruct {
      a: 1,
      b: 2,
      ..,
    }

    This makes sense because the language already has this syntax is places such as pattern matching

  20. LunarLambda commented on Nov 29, 2023

    @LunarLambda

    has there been any followup RFC/tracking issue for an eventual use Trait::method; syntax?

  21. crumblingstatue commented on Dec 29, 2023

    @crumblingstatue
    Contributor

    has there been any followup RFC/tracking issue for an eventual use Trait::method; syntax?

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: 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-SmallLibs issues that are considered "small" or self-containedT-libs-api[DEPRECATED; DO NOT USE]disposition-closeThis 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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions