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

internal error: entered unreachable code #4357

Closed
ehuss opened this issue Jul 29, 2020 · 2 comments · Fixed by #4416
Closed

internal error: entered unreachable code #4357

ehuss opened this issue Jul 29, 2020 · 2 comments · Fixed by #4416
Labels
1x-backport:completed bug Panic, non-idempotency, invalid code, etc.

Comments

@ehuss
Copy link
Contributor

ehuss commented Jul 29, 2020

Describe the bug
In some situations, rustfmt will panic with the following error:

thread 'main' panicked at 'internal error: entered unreachable code', src/tools/rustfmt/src/types.rs:764:59

To Reproduce

This is a repost of rust-lang/cargo#8388, so I don't know the original code (the reporter said it was close source and could not share). However, here are some examples that can trigger it:

type T = typeof(1);
struct S;

impl T for .. {

}

Of course these aren't valid, but they hit this line. I'm not sure if there are legitimate cases that would hit this. Another guess is that maybe the user had format-on-save, and was in the middle of some unfinished code?

Meta

  • rustfmt version: rustfmt 1.4.19-nightly (cef1c0d5 2020-07-21)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: cargo fmt
@calebcartwright
Copy link
Member

Thanks for sharing @ehuss , and providing the additional details and minimal repro!

Invalid code scenarios are a little tricky. The general rule of thumb is that if the rustc parser can still successfully generate an AST (which is clearly the case here) then rustfmt should be able to format. However, there's been a few other cases where invalid code was too problematic to be format-able.

If anyone knows a valid minimal repro scenario please feel free to share

topecongiro added a commit to topecongiro/rustfmt that referenced this issue Sep 7, 2020
topecongiro added a commit that referenced this issue Sep 9, 2020
* Add a test for #4357

* Format error and typeof types
@calebcartwright calebcartwright added the 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release label Dec 12, 2020
calebcartwright pushed a commit to calebcartwright/rustfmt that referenced this issue Dec 19, 2020
* Add a test for rust-lang#4357

* Format error and typeof types
calebcartwright pushed a commit that referenced this issue Dec 20, 2020
* Add a test for #4357

* Format error and typeof types
@calebcartwright calebcartwright removed the 1x-backport:pending Fixed/resolved in source but not yet backported to a 1x branch and release label Dec 24, 2020
@calebcartwright
Copy link
Member

Backported in v1.4.30

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

Successfully merging a pull request may close this issue.

2 participants