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

Generic associated impl trait type with bounds on self formatted to broken code #4911

Closed
tim3z opened this issue Jul 20, 2021 · 4 comments · Fixed by #4944
Closed

Generic associated impl trait type with bounds on self formatted to broken code #4911

tim3z opened this issue Jul 20, 2021 · 4 comments · Fixed by #4944
Labels
2x-port:pending bug Panic, non-idempotency, invalid code, etc.

Comments

@tim3z
Copy link

tim3z commented Jul 20, 2021

Describe the bug

When specifying an impl trait type alias for a generic associated type with a lifetime bound on Self, rustfmt will remove the bound, causing a compiler error, i.e.:

impl SomeTrait for SomeType {
    type SomeGAT<'a> where Self: 'a = impl SomeOtherTrait;
}

will be changed to

impl SomeTrait for SomeType {
    type SomeGAT<'a> = impl SomeOtherTrait;
}

To Reproduce

The following code compiles, but when running rustfmt on it it will remove the Self bound where Self" 'a in the implementation for Foo leading to a compiler error:

#![allow(incomplete_features)]
#![feature(generic_associated_types)]
#![feature(min_type_alias_impl_trait)]

struct Foo<'b>(&'b ());

trait Iterable {
    type Iter<'a>
    where
        Self: 'a;
    fn iter(&self) -> Self::Iter<'_>;
}

impl<'b> Iterable for Foo<'b> {
    type Iter<'a> where Self: 'a = impl Iterator + 'a;

    fn iter(&self) -> Self::Iter<'_> {
        std::iter::once(self.0)
    }
}

Expected behavior

The above code compiles and should not be formatted so it doesn't compile.

Meta

  • rustfmt 1.4.37-nightly (014026d 2021-07-19)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: rustfmt, sublime RustFmt package
@calebcartwright
Copy link
Member

Thanks for the report but I'm going to close this as a duplicate of various prior issues. It's been fixed in source but not pulled into a nightly release yet.

@tim3z
Copy link
Author

tim3z commented Jul 21, 2021

Thanks for the response. I looked into other related closed issues (#4257 #4315 #4322) but they are from July 2020 and the examples from these issues are all formatted correctly with the current rustfmt version. So while this seems very similar, I don't think that this is a duplicate. The combination with the impl trait type alias seems to cause another problem.

@calebcartwright calebcartwright added bug Panic, non-idempotency, invalid code, etc. and removed duplicate labels Jul 22, 2021
@calebcartwright
Copy link
Member

Ah I see now. The way the snippets were structured in the issue description was a bit of a misdirection. Would be helpful to update extend that initial snippet to a minimal repro itself (within the impl) since it's not reproducible as is.

@tim3z
Copy link
Author

tim3z commented Jul 22, 2021

Updated initial example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2x-port:pending bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants