Skip to content

Tuple struct associated constants can't be initialized with Self() #44846

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

Closed
jsgf opened this issue Sep 25, 2017 · 3 comments
Closed

Tuple struct associated constants can't be initialized with Self() #44846

jsgf opened this issue Sep 25, 2017 · 3 comments

Comments

@jsgf
Copy link
Contributor

jsgf commented Sep 25, 2017

There's an inconsistency when initializing tuple structs as associated constants with Self:

struct Foo(i32);

impl Foo {
const A: Self = Self(1); // Fails with "did you mean `Self { /* fields */ }`?"
const B: Self = Self { 0: 2 }; // succeeds
}

I'd expect Self(1) to work if Self { 0: 2 } works.

@jsgf
Copy link
Contributor Author

jsgf commented Sep 25, 2017

Actually, this looks like a general problem with Self and tuple types. This also doesn't work:

impl Foo {
    fn new(x: i32) -> Self {
        Self(x) // same failure
    }
}

@petrochenkov
Copy link
Contributor

petrochenkov commented Sep 25, 2017

Duplicate of #42601 and maybe a couple of other closed issues.

This is not supposed to work and the fix is kinda on the RFC territory, but given that it's requested regularly, I think it's reasonable to make this change and support Self in value namespace as a constructor alias.

@TimNN
Copy link
Contributor

TimNN commented Sep 27, 2017

Closing as duplicate.

@TimNN TimNN closed this as completed Sep 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants