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

Panic in src/tools/rustfmt/src/lists.rs:678:54 on a bad comment #4552

Closed
kvark opened this issue Nov 24, 2020 · 3 comments
Closed

Panic in src/tools/rustfmt/src/lists.rs:678:54 on a bad comment #4552

kvark opened this issue Nov 24, 2020 · 3 comments
Labels
1x-backport:completed bug Panic, non-idempotency, invalid code, etc.

Comments

@kvark
Copy link

kvark commented Nov 24, 2020

Describe the bug

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/tools/rustfmt/src/lists.rs:678:54
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To Reproduce

fn main() {
    panic!("Foo {:?}", /*"*/
                    1
                );
}

Expected behavior

Formatting succeeds

Meta

  • rustfmt version: rustfmt 1.4.18-stable (8157a3f 2020-07-15)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: cargo fmt
@kvark kvark added the bug Panic, non-idempotency, invalid code, etc. label Nov 24, 2020
@calebcartwright
Copy link
Member

There was a similar report in #4312 that was addressed by 98efebd on master (hasn't been backported to a release version). That update does prevent the panic in this case when the comment is within a mac call, but the formatting still isn't correct with that change on master either, as the comment gets moved before the comma thus likely losing the arg association.

@davidBar-On
Copy link
Contributor

... as the comment gets moved before the comma thus likely losing the arg association

Submitted PR #4581 with a proposed fix for this issue.

@calebcartwright calebcartwright added 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release and removed help wanted labels Dec 24, 2020
@karyon
Copy link
Contributor

karyon commented Oct 22, 2021

The backport of 98efebd has been done in #4796. I have tested the snippet in the OP and it does not panic and produces this here, which looks good to me:

fn main() {
    panic!("Foo {:?}" /*"*/, 1);
}

@karyon karyon added 1x-backport:completed and removed 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release labels Oct 25, 2021
@karyon karyon closed this as completed Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1x-backport:completed bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

4 participants