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

where clauses in GAT impls aren't formatted #5580

Closed
clarfonthey opened this issue Oct 31, 2022 · 13 comments
Closed

where clauses in GAT impls aren't formatted #5580

clarfonthey opened this issue Oct 31, 2022 · 13 comments

Comments

@clarfonthey
Copy link

Playground example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1ef166f9e2b31f3f4093728719de4efc

pub trait Test {
    type Ref<'a> where Test: 'a;
}

impl<T, U> Test for (T,) {
    type Ref<'a> = (&'a T,) where T: 'a;
}

impl<T, U> Test for (T, U) {
    type Ref<'a> = (&'a T, &'a U) where T: 'a, U: 'a;
}

The above autoformats to:

pub trait Test {
    type Ref<'a>
    where
        Test: 'a;
}

impl<T, U> Test for (T,) {
    type Ref<'a> = (&'a T,) where T: 'a;
}

impl<T, U> Test for (T, U) {
    type Ref<'a> = (&'a T, &'a U) where T: 'a, U: 'a;
}

You'll notice that the where clauses for the impls aren't formatted at all, whereas I would expect:

pub trait Test {
    type Ref<'a>
    where
        Test: 'a;
}

impl<T, U> Test for (T,) {
    type Ref<'a> = (&'a T,)
    where
        T: 'a;
}

impl<T, U> Test for (T, U) {
    type Ref<'a> = (&'a T, &'a U)
    where
        T: 'a,
        U: 'a;
}
@ytmimi
Copy link
Contributor

ytmimi commented Oct 31, 2022

Thanks for reaching out!

I haven't had a chance to look into this yet, but I'll try to dig into this when I've got a little more time

@richard-uk1
Copy link

I hit an issue where a longer GAT where clause had a linebreak inserted. This then caused an internal error on rustfmt --check. I suspect this issue will go away as and when formatting for GATs is implemented, but wanted to record it.

@ytmimi
Copy link
Contributor

ytmimi commented Nov 4, 2022

@derekdreery would it be possible for you to post a code snippet? It would help in the investigation!

@richard-uk1
Copy link

Hi @ytmimi. It seems like I can't reproduce the problem - good news! It might have been something to do with the upgrade that is now resolved. Will report back here if I manage to reproduce it again.

@ytmimi
Copy link
Contributor

ytmimi commented Nov 4, 2022

That is good news! I appreciate you taking the time to look into it

@richard-uk1
Copy link

@ytmimi no worries thanks for an awesome tool!

@CJKay
Copy link

CJKay commented Apr 21, 2023

Still seems to be occurring - the associated type declaration in the trait formats fine, but the impl remains untouched. This is very simple to reproduce: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9bd99971b4d896d785caed1506993ee4

@tamird
Copy link
Contributor

tamird commented Sep 7, 2023

Note that this doesn't require GATs; it happens on any associated type in an impl that has a where clause. From #5751: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=448e25cc22bb316f236e5ee6aeb455de.

@clarfonthey
Copy link
Author

Aren't those still considered GATs? I was under the impression that any conditions on associated types were forbidden before GATs were stabilised, and the code is shared for all of them.

@ia0
Copy link

ia0 commented Oct 29, 2024

I suspect this is now fixed, although in a weird way. Notice how the actual output differs from the expected output in the original issue comment. You can use the playground link provided there to reproduce.

pub trait Test {
    type Ref<'a>
    where
        Test: 'a;
}

impl<T, U> Test for (T,) {
    type Ref<'a>
        = (&'a T,)
    where
        T: 'a;
}

impl<T, U> Test for (T, U) {
    type Ref<'a>
        = (&'a T, &'a U)
    where
        T: 'a,
        U: 'a;
}

@ytmimi
Copy link
Contributor

ytmimi commented Oct 29, 2024

@ia0 Thanks for pointing out that this one is now resolved. The current formatting is expected. As of rustfmt 1.8.0 trailing where clauses in type aliases started to get formatted, and formatting is following the rules outlined by the style guide.

If you'd like to propose a different default style you can open an issue on the style-team's repo, or if you'd like to propose a new formatting option in rustfmt you can open a new issue to outline the idea.

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 29, 2024
@ytmimi ytmimi reopened this Oct 29, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Oct 29, 2024

closed by #5887

@ytmimi ytmimi closed this as completed Oct 29, 2024
@ia0
Copy link

ia0 commented Oct 29, 2024

Sounds good, thanks for the link!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants