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

Noncompilable output on attribute containing string literal containing brace #4724

Closed
dtolnay opened this issue Feb 25, 2021 · 1 comment · Fixed by #4727
Closed

Noncompilable output on attribute containing string literal containing brace #4724

dtolnay opened this issue Feb 25, 2021 · 1 comment · Fixed by #4727
Assignees
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@dtolnay
Copy link
Member

dtolnay commented Feb 25, 2021

As of current master (2e1a982):

$  echo 'struct x{/** */#[x="{"]x:x}' | CFG_RELEASE_CHANNEL=dev CFG_RELEASE=1 cargo run --features rustfmt --bin rustfmt

struct x {
    /** */#[x="{
    /** */
    #[x = "{"]
    x: x,
}

That output has mismatched " and some duplication of parts of the input.

It seems to do a better job if you swap "{" to "}". But my expectation would be that the formatting is the same regardless of which string is in the attribute.

$  echo 'struct x{/** */#[x="}"]x:x}' | CFG_RELEASE_CHANNEL=dev CFG_RELEASE=1 cargo run --features rustfmt --bin rustfmt

struct x {
    /** */
    #[x = "}"]
    x: x,
}

#4452 appears similar but is specific to attributes on expressions, so I am filing this separately.

@dtolnay dtolnay added the bug Panic, non-idempotency, invalid code, etc. label Feb 25, 2021
@calebcartwright
Copy link
Member

Thanks for the report. The differing behavior between opening and closing braces makes me think it's likely a bug in our searching for the body opening vs. the type of span issue that caused #4452 so agreed on separate issue 👍

Have a little free time so will look at this one shortly

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