Skip to content

assertion failure in trans_alt when combining if, nested patterns #3121

Closed

Description

@nikomatsakis

The following test:

enum side { mayo, catsup, vinegar }
enum order { hamburger, fries(side), shake }
enum meal { to_go(order), for_here(order) }

fn foo(m: @meal, cond: bool) {
    match *m {
      to_go(_) => { }
      for_here(_) if cond => {}
      for_here(hamburger) => {}
      for_here(fries(s)) => {}
      for_here(shake) => {}
    }
}

fn main() {
    foo(@for_here(hamburger), true)
}

results in an assertion failure in trans:

;RUST_LOG=rustc=0 rustc ~/tmp/pat-bug-in-trans.rs 
rust: task failed at 'Assertion m.len() > 0u || is_some(chk) failed', /Users/nmatsakis/versioned/rust-gold/src/rustc/middle/trans/alt.rs:431
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=0,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues
rust: task failed at 'explicit failure', /Users/nmatsakis/versioned/rust-gold/src/rustc/driver/rustc.rs:264
rust: domain main @0x7f8d99800010 root task failed
rust: task failed at 'killed', /Users/nmatsakis/versioned/rust-gold/src/libcore/task.rs:520

The problem has to do with the if, something in the logic there gets a bit confused.

Activity

  1. catamorphism commented on Aug 7, 2012

    @catamorphism
    Contributor

    This looks very similar to #2869

  2. catamorphism commented on Dec 8, 2012

    @catamorphism
    Contributor

    I have a fix for this; running tests. Basically, enter_default needs to know whether a pattern has a guard, and not consider a guarded pattern to be a default.

  3. catamorphism commented on Dec 8, 2012

    @catamorphism
    Contributor

    Oops, it's not as simple as that. Still working on it.

  4. graydon commented on Dec 18, 2012

    @graydon
    Contributor

    Bumping this since it can always be worked around. Should fix but non blocking.

  5. pnkfelix commented on Mar 22, 2013

    @pnkfelix
    Contributor

    Not critical for 0.6; de-milestoning

  6. catamorphism commented on May 7, 2013

    @catamorphism
    Contributor

    Nominating for milestone 5, production-ready. I have an old branch that partially fixes it, but it needs more work.

  7. graydon commented on Jun 13, 2013

    @graydon
    Contributor

    reproduced, and people run into it often, sure

  8. graydon commented on Jun 13, 2013

    @graydon
    Contributor

    accepted for production-ready milestone

  9. jasom commented on Jul 16, 2013

    @jasom

    Is this fixed in 0.7? I think I've run into it recently. Is there a workaround?

  10. pnkfelix commented on Jul 16, 2013

    @pnkfelix
    Contributor

    @jasom: combine the caes with the same patterns, moving their ifs to the right-hand side of the pattern?

  11. added a commit that references this issue on Aug 8, 2013
    25e487d
  12. msullivan commented on Aug 9, 2013

    @msullivan
    Contributor

    I think I have a pretty good idea of how to fix this, although it seems a little subtle/hacky.

  13. added a commit that references this issue on Aug 10, 2013
    437a4c2
  14. added a commit that references this issue on Oct 21, 2023
  15. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenI-ICE

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions