Skip to content

DRY Self initialization syntax with tuple structs too? #42601

Closed
@leonardo-m

Description

@leonardo-m

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 */ }`?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions