Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Self alias as struct constructor #1588

Closed
durka opened this issue Apr 21, 2016 · 5 comments
Closed

Self alias as struct constructor #1588

durka opened this issue Apr 21, 2016 · 5 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@durka
Copy link
Contributor

durka commented Apr 21, 2016

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

@KalitaAlexey
Copy link

Yes. I'd like to do it too.

@thepowersgang
Copy link
Contributor

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

@arielb1
Copy link
Contributor

arielb1 commented Apr 26, 2016

That's something I intended to implement.

@durka
Copy link
Contributor Author

durka commented Apr 27, 2016

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

@nrc nrc added the T-lang Relevant to the language team, which will review and decide on the RFC. label Aug 18, 2016
@durka
Copy link
Contributor Author

durka commented Oct 8, 2016

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

@durka durka closed this as completed Oct 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants