8000 feat: Generate `new` for tuple struct by Hmikihiro · Pull Request #20109 · rust-lang/rust-analyzer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Generate new for tuple struct #20109

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Hmikihiro
Copy link
Contributor

Closes: #20071
I will generate fn new for tuple structs just like struct with named fields.
For tuple structs, I use the element index of tuple instead of a field name.

struct S<T>(String, PhantomData<T>, u32);

impl<T> S<T> {
    fn new(_0: String, _2: u32) -> Self {
        Self(_0, PhantomData, _2)
    }
}
struct S<T> {
    text: String,
    _marker: PhantomData<T>,
    value: u32,
}

impl<T> S<T> {
    fn new(text: String, value: u32) -> Self {
        Self { text, _marker: PhantomData, value }
    }
}

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2025
@ChayimFriedman2
Copy link
Contributor

Using _number is a bad idea. We have NameGenerator and you can also place a tabstop on each name.

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
@Hmikihiro
Copy link
Contributor Author

Thanks @ChayimFriedman2 for the feedback.
I would use NameGenerator to generate names instead of _number, and use placeholder to change each name.
スクリーンショット 2025-06-27 18 58 06

Copy link
Member
@ShoyuVanilla ShoyuVanilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate 'new' function assist should also be available for tuple structs
4 participants
0