RFC: Return-position impl Trait in trait
tmandry opened this issue · comments
This is a roadmap item for wg-async. You can view the roadmap here: https://github.com/orgs/rust-lang/projects/28
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.
Could you add a description here?
RFC is up: rust-lang/rfcs#3425
RFC was merged. Tracking issue: rust-lang/rust#91611