Skip to content

Specialization should allow for delegation to default trait method implementation #68309

Open
@jazzfool

Description

Given the following trait:

trait Trait {
    fn test(&self) { println!("default implementation"); }
}

To provide a default specialization on Trait::test, test must be redefined;

impl<T> Trait for T {
    default fn test(&self) { println!("default implementation"); }
}

However this violates the DRY principle. The solution here would be to provide a way to delegate the implementation of test to the already existing default implementation found in the trait definition.

Proposed syntax to allow for this delegation:

impl<T> Trait for T {
    default fn test(&self);
}

Activity

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

Metadata

Assignees

No one assigned

    Labels

    A-specializationArea: Trait impl specializationC-feature-requestCategory: A feature request, i.e: not implemented / a PR.F-associated_type_defaults`#![feature(associated_type_defaults)]`F-specialization`#![feature(specialization)]`T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions