Skip to content

RFC: Return-position impl Trait in trait #291

@tmandry

Description

@tmandry

This is a roadmap item for wg-async. You can view the roadmap here: wg-async roadmap

Allow -> impl Trait methods in traits, e.g.

trait Iterable {
    fn iter(&self) -> impl Iterator;
}

Open questions

Semver hazard caused by auto trait leakage

Auto traits leak from public functions using async fn and return-position impl Trait. This is a pre-existing issue.

Once we make these features available within traits we have a chance to proactively make sure crate authors don't accidentally stabilize auto traits. For example, we could make it a lint or a hard error if you have a publicly-accessible function that is not explicit about its auto traits.

It's obvious how to do this for -> impl Trait (add + Send and probably #[refine]), but not async fn. We could also punt on this and make it a lint for all uses of -> impl Trait later (not only inside traits), upgrading to a hard error over an edition.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions