Skip to content

Default the associated return type of unop/binop traits to Self #20399

@japaric

Description

@japaric

Because that's the common case and it's an ergonomic win. For example:

trait Add<RHS=Self> {
   type Result = Self;  // <-- default type

    fn add(self, RHS) -> Self::Result;
}

Would let us write trait Int: Add + Sub + ... instead of trait Int: Add<Result=Self> + Sub<Result=Self> + ....

This has to wait until default type parameters is implemented for associated types (#19476).

cc @aturon / @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API 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