Skip to content

rustfmt on impl with const generic adds unwanted code #3601

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

Closed
hellow554 opened this issue Jun 5, 2019 · 1 comment · Fixed by #3602
Closed

rustfmt on impl with const generic adds unwanted code #3601

hellow554 opened this issue Jun 5, 2019 · 1 comment · Fixed by #3602
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@hellow554
Copy link
Contributor

Before formatting:

trait A {}
pub struct B<const N: usize>([usize; N]);

impl<const N: usize> A for B<{ N }> { }

After formatting:

trait A {}
pub struct B<const N: usize>([usize; N]);

impl<const N: usize> A for B<{ N }> { N }> {}

Used 1.2.2 nightly (2019-04-24 5274b49)

@hellow554
Copy link
Contributor Author

hellow554 commented Jun 5, 2019

It gets a little bit weirder, if the trait has a method:

#![feature(const_generics)]

trait A {
    fn foo(&self);
}

pub struct B<const N: usize>([usize; N]);

impl<const N: usize> A for B<{ N }> {
    fn foo(&self) {}
}
trait A {
    fn foo(&self);
}

pub struct B<const N: usize>([usize; N]);

impl<const N: usize> A for B<{ N }> { N }> {
    N }>
{
    fn foo(&self) {}
}

There's yet another additional { N } showing up.

@scampi scampi added the bug Panic, non-idempotency, invalid code, etc. label Jun 5, 2019
rchaser53 added a commit to rchaser53/rustfmt that referenced this issue Jun 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants