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

Trailing comma is duplicated when obstructed by comments #3876

Closed
Proximyst opened this issue Oct 19, 2019 · 4 comments · Fixed by #4520
Closed

Trailing comma is duplicated when obstructed by comments #3876

Proximyst opened this issue Oct 19, 2019 · 4 comments · Fixed by #4520
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-chains a-comments bug Panic, non-idempotency, invalid code, etc.

Comments

@Proximyst
Copy link

Proximyst commented Oct 19, 2019

In the following snippet, there is a trailing comment following the entire builder chain after normal_message:

    // Client set up {{{
    discord_client.with_framework(
        StandardFramework::new()
            // Framework configuration {{{{
            .configure(|c| {
                c.with_whitespace(true) // allow `{prefix} command`
                    .case_insensitivity(true) // allow `{prefix}cOmMaNd`
                    .no_dm_prefix(true) // allow `command` in DMs
                    .prefix(config.prefix()) // set the prefix to use for commands
                    .delimiters(vec![" "]) // split arguments at space; `{prefix} test a b c` => [{prefix test}, a, b, c]
            })
            // Normal message {{{{
            .normal_message(|_ctx, _msg| {
            })
            // }}}}
            ,
            // wee
    );
    // }}}

When I run rustfmt on this with default settings:

$ rustfmt --version
rustfmt 1.4.8-nightly (afb1ee1 2019-09-08)

I get this result:

    // Client set up {{{
    discord_client.with_framework(
        StandardFramework::new()
            // Framework configuration {{{{
            .configure(|c| {
                c.with_whitespace(true) // allow `{prefix} command`
                    .case_insensitivity(true) // allow `{prefix}cOmMaNd`
                    .no_dm_prefix(true) // allow `command` in DMs
                    .prefix(config.prefix()) // set the prefix to use for commands
                    .delimiters(vec![" "]) // split arguments at space; `{prefix} test a b c` => [{prefix test}, a, b, c]
            })
            // Normal message {{{{
            .normal_message(|_ctx, _msg| {}), // }}}}
                                              , // uh oh.. there's a comma over this one as well! ;o
                                              // wee
    );
    // }}}

The comma clearly duplicated where it wasn't supposed to.
The //uh oh comment was added in the issue creation; the rest was from my source code, except "a bit" stripped down.

@calebcartwright
Copy link
Member

The //uh oh comment was added in the issue creation

When I first glanced through the snippet I was thinking.. how in the world did rustfmt inject an // uh oh.. comment 😄

Definitely a bug, and still reproducible with 1.4.9 and latest

@topecongiro topecongiro added a-chains a-comments bug Panic, non-idempotency, invalid code, etc. labels Oct 21, 2019
@topecongiro
Copy link
Contributor

A minimal working example:

fn main() {
    foo(
        x
        // comment 1
        ,
        // comment 2
    )
}

It looks like rustfmt fails to figure out that there are two comments separated by a trailing comma and considers it as a continuous multi-lined comment.

@kryptan
Copy link

kryptan commented Apr 25, 2020

Just hit a similar issue with commas in where clauses:

fn f<S>(s: S)
where
    S: Send /* */,
             //
{
}

Redundant comma is added:

fn f<S>(s: S)
where
    S: Send, /* */,
             //
{
}

@whizsid
Copy link
Contributor

whizsid commented Oct 31, 2020

I am working on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release a-chains a-comments bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants