-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
Currently impl Trait
is only allowed as the return type of a free-standing functions and inherent methods. I would like to see it opened to a few more positions.
Local variable signatures
let x: impl Foo = bar();
can already be simulated by:
fn wrapper<T: Foo>(x: T) -> impl Foo { x }
let x = wrapper(bar());
Also,
let x: Option<impl Foo> = bar();
If bar
returns Option<Baz>
, Baz
would be checked for an implementation of Foo
.
Parameters of free-standing functions and methods
fn bar(x: impl Foo) { }
can be equivalent to:
fn bar<T: Foo>(x: T) { }
Furthermore,
fn bar(x: Option<impl Foo>) { }
can be equivalent to:
fn bar<T: Foo>(x: Option<T>) { }
This cuts down a bit on boilerplate.
Other positions in return types of free-standing functions and methods
fn bar() -> Option<impl Foo> { }
durka, gabomgp, vittorioromeo, dashed, tupshin and 3 more
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.