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

Associated types implementation with where clause are not formatted #5751

Closed
ia0 opened this issue Apr 13, 2023 · 4 comments
Closed

Associated types implementation with where clause are not formatted #5751

ia0 opened this issue Apr 13, 2023 · 4 comments
Labels
blocked Blocked on rustc, an RFC, etc.

Comments

@ia0
Copy link

ia0 commented Apr 13, 2023

trait Foo {
    type Bar;
}

impl Foo for () {
    // The following line doesn't get formatted.
    type Bar = ()    where u8: Copy;
}

playground

Removing the where clause restores formatting, so this looks specific to where clause in associated types.

@ytmimi
Copy link
Contributor

ytmimi commented Apr 13, 2023

@ia0 thanks for the report. Confirming I can reproduce this with rustfmt 1.5.2-nightly (4aacac8e 2023-04-09).

The issue here might be that we haven't defined how to format associated types when the where clause comes after the type.

There doesn't seem to be anything defined in the Style Guide docs for Associated types. @calebcartwright is this something that needs to be brought to t-style's attention? Maybe the Style Guide docs should be brought closer in line with the Rust Reference Associated Types docs

It looks like we can format the deprecated form:

Input

impl Foo for () {
    // The following line doesn't get formatted.
    type Bar = ()    where u8: Copy;

    // The following is formatted.
    type Baz where u8:      Copy   =    ();
}

Output

impl Foo for () {
    // The following line doesn't get formatted.
    type Bar = ()    where u8: Copy;
    type Baz
    where
        u8: Copy,
    = ();
}

@ytmimi ytmimi added the blocked Blocked on rustc, an RFC, etc. label Apr 13, 2023
@ytmimi
Copy link
Contributor

ytmimi commented May 1, 2023

After looking into it I think this is a duplicate of #5580

@ia0
Copy link
Author

ia0 commented May 1, 2023

After looking into it I think this is a duplicate of #5580

I confirm. Feel free to close this issue as duplicate. I subscribed to the other one.

@ytmimi
Copy link
Contributor

ytmimi commented May 7, 2023

Thanks for confirming this is a duplicate

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked on rustc, an RFC, etc.
Projects
None yet
Development

No branches or pull requests

2 participants