Rfcs: Self alias as struct constructor

Created on 21 Apr 2016  ·  5Comments  ·  Source: rust-lang/rfcs

Consider the following code

struct Foo { a: i32 }

impl Default for Foo {
    fn default() -> Self {
        Foo { a: 42 }
    }
}

We can't replace the last use of Foo in the impl with Self (you get E0071). But Self is a kind of type alias, or it acts like one anyway, and normally you can construct a struct through a type alias. So we should allow usage of Self like this.

brought up here cc @huonw

T-lang

Most helpful comment

That's something I intended to implement.

All 5 comments

Yes. I'd like to do it too.

An alternative that I've been thinking of is allowing _ instead. (fitting in with a possible extension to enum matching)

That's something I intended to implement.

@arielb1 do you mean you don't think this requires an RFC?

Implemented at rust-lang/rust#37035, thanks @petrochenkov!

Was this page helpful?
0 / 5 - 0 ratings