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

ICE on loop {|_: [_; continue]| {}} #51761

Closed
est31 opened this issue Jun 24, 2018 · 6 comments
Closed

ICE on loop {|_: [_; continue]| {}} #51761

est31 opened this issue Jun 24, 2018 · 6 comments
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@est31
Copy link
Member

est31 commented Jun 24, 2018

The following code ICEs on nightly, stable and beta:

fn main() {
    loop {|_: [_; continue]| {}}
}

The ICE message is:

error: internal compiler error: librustc_mir/hair/cx/expr.rs:551: invalid loop id for continue: not inside loop scope

As of filing this bug, PR #51731 does not fix it. If I apply it, I'm getting:

error: internal compiler error: librustc_mir/build/scope.rs:552: no enclosing breakable scope found
  --> $DIR/issue-XXXX.rs:12:19
   |
LL |     loop {|_: [_; continue]| {}}
   |                   ^^^^^^^^
@varkor varkor self-assigned this Jun 24, 2018
@estebank estebank added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 24, 2018
@varkor
Copy link
Member

varkor commented Jun 25, 2018

Counterintuitively, this should probably compile successfully. It's not surprising that it's not working, though: it's a really weird edge case. I'll look into it.

@hanna-kruppe
Copy link
Contributor

I don't think it should compile successfully. The continue is in an array length constant expression inside the closure's signature. Therefore, it's not part of the loop body and should cause an "continue outside of loop" error.

@varkor
Copy link
Member

varkor commented Jun 25, 2018

I feel perhaps control-flow should just not be allowed inside type-level constants like this. That seems like the most logical decision. In which case, we should just add a new error for this.

Edit: Just saw @rkruppe's comment. I agree, though I'm not sure there's precedent for that or not? Is there an existing error we can make us of?

@hanna-kruppe
Copy link
Contributor

As I said, I believe this is a plain old "continue outside of loop" errors. The continue token is lexically within the loop { ... }, but it's not part of the loop body, so it's invalid without even considering that it's supposed to be a constant. It's morally the same as loop { fn foo() { continue } }.

@DutchGhost
Copy link
Contributor

What about the break version?
Not sure if the fix is applied in the latest nightly, but this still ICE's:
#51707

Rewritting it using a loop {} instead of while:

fn main() {
    loop {
        |_: [_; break] | {}
    }
}

@est31
Copy link
Member Author

est31 commented Jun 25, 2018

@DutchGhost that's fixed by @varkor 's PR #51731 . The fix is not in nightly yet, not even merged. I've applied the PR locally in order to test whether the loop {loop {|_: [_; continue]| {}} } bug still exists.

It would probably make sense if @varkor would also fix the break version right away.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 2, 2018
…=estebank

Fix various issues with control-flow statements inside anonymous constants

Fixes rust-lang#51761.
Fixes rust-lang#51963 (and the host of other reported issues there).
(Might be easiest to review per commit, as they should be standalone.)

r? @estebank
bors added a commit that referenced this issue Jul 5, 2018
Fix various issues with control-flow statements inside anonymous constants

Fixes #51761.
Fixes #51963 (and the host of other reported issues there).
(Might be easiest to review per commit, as they should be standalone.)

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants