Skip to content

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

Description

@est31

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]| {}}
   |                   ^^^^^^^^

Activity

  1. self-assigned this
    on Jun 24, 2018
  2. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Jun 24, 2018
  3. varkor commented on Jun 25, 2018

    @varkor
    Contributor

    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.

  4. hanna-kruppe commented on Jun 25, 2018

    @hanna-kruppe
    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.

  5. varkor commented on Jun 25, 2018

    @varkor
    Contributor

    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?

  6. hanna-kruppe commented on Jun 25, 2018

    @hanna-kruppe
    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 } }.

  7. DutchGhost commented on Jun 25, 2018

    @DutchGhost

    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] | {}
        }
    }
  8. est31 commented on Jun 25, 2018

    @est31
    MemberAuthor

    @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.

  9. added a commit that references this issue on Jul 2, 2018
    7c9ba44
  10. added a commit that references this issue on Jul 5, 2018
    69b9e1e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions