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

DRY Self initialization syntax with tuple structs too? #42601

Closed
leonardo-m opened this Issue Jun 12, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@leonardo-m
Copy link

leonardo-m commented Jun 12, 2017

Do you want to accept the "Self(0, 0)" syntax too? I think it's more DRY:

struct VecA { x: u32, y: u32 }
impl VecA {
    fn new() -> Self {
        Self { x: 0, y: 0 } // OK
    }
}
struct VecB(u32, u32);
impl VecB {
    fn new() -> Self {
        Self(0, 0) // Error
    }
}
fn main() {}

The current error message is:

error[E0423]: expected function, found self type `Self`
  --> ...\test.rs:10:9
   |
10 |         Self(0, 0) // Error
   |         ^^^^ did you mean `Self { /* fields */ }`?
@leonardo-m

This comment has been minimized.

Copy link
Author

leonardo-m commented Jun 13, 2017

@Centril

This comment has been minimized.

Copy link
Contributor

Centril commented Nov 30, 2018

We are doing this now (#51994) so this can be closed.

@Centril Centril closed this Nov 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.