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

Rust Analyzer automatically removes valid generic args in GAT type constraint #10196

Closed
b-naber opened this issue Sep 10, 2021 · 5 comments
Closed

Comments

@b-naber
Copy link

b-naber commented Sep 10, 2021

In the following code rust analyzer automatically deletes code (the generic args on the associated type in the type constraint) that is necessary for the code to compile. This happens in the VS code extension.

#![feature(generic_associated_types)]

trait Trait {
    type Assoc<'a>;
}

// this requires a constraint on the associated type (Assoc<'a> = ()), but rust analyzer always automatically deletes the generic args on the associated type
fn f<'a, T: Trait<Assoc = ()>>(_: T, _: impl Fn(T::Assoc<'a>) -> T::Assoc<'a>) -> T::Assoc<'a> {}

struct Type;

impl Trait for Type {
    type Assoc<'a> = ();
}

fn main() {
    f(Type, |_| ());
}
@flodiebold
Copy link
Member

If by "automatically" you mean when formatting, then this is a rustfmt bug. Does the same happen if you run cargo fmt in the command line?

@b-naber
Copy link
Author

b-naber commented Sep 10, 2021

Yes that's what I meant, sorry for not being clear. This also happens when cargo fmt is run. I'll open an issue in the rustfmt repo.

@lnicola
Copy link
Member

lnicola commented Sep 10, 2021

Which toolchain version are you using? This was fixed IIRC.

@b-naber
Copy link
Author

b-naber commented Sep 10, 2021

I've updated to the latest nightly toolchain, but this still occurs.

@jonas-schievink
Copy link
Contributor

Closing in favor of rust-lang/rustfmt#4987

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

No branches or pull requests

4 participants