Skip to content

ICE in nightly with patterns and nested enums #39362

Closed

Description

@tomaka
enum Foo {
    Bar { bar: Bar, id: usize }
}

enum Bar {
    A, B, C, D, E, F
}

fn test(f: Foo) {
    match f {
        Foo::Bar { bar: Bar::A, .. } => (),
        Foo::Bar { bar: Bar::B, .. } => (),
    }
}

The match doesn't cover all patterns, but instead of triggering an error (like stable does) it panics.

Playpen link
Version: c8af93f 2017-01-18
Backtrace:

thread 'rustc' panicked at 'assertion failed: !self.is_enum()', C:\bot\slave\nightly-dist-rustc-win-msvc-64\build\src\librustc\ty/mod.rs:1497
stack backtrace:
   0:     0x7ffa070208f8 - std::panicking::Location::line::h8c528bbdf4eef8a3
   1:     0x7ffa0701fd82 - std::panicking::Location::line::h8c528bbdf4eef8a3
   2:     0x7ffa070237bd - std::panicking::rust_panic_with_hook::h7abc6e334345e341
   3:     0x7ffa00a82293 - <unknown>
   4:     0x7ffa00cfe5d1 - rustc::ty::AdtDef::struct_variant::h3407c5d1765959c4
   5:     0x7ffa14c5bbf2 - <rustc_const_eval::pattern::Pattern<'tcx> as core::fmt::Display>::fmt::hd436f1763f102376
   6:     0x7ffa07036f31 - core::fmt::write::h17329881d672cff3
   7:     0x7ffa14c5617d - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body::heaaeacf8d46cf425
   8:     0x7ffa14c52dc9 - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr::h8a811e2d6152dd49
   9:     0x7ffa14c51ae5 - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr::h8a811e2d6152dd49
  10:     0x7ffa14c54130 - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body::heaaeacf8d46cf425
  11:     0x7ffa14c5056d - <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::he57f23671b55c8bb
  12:     0x7ffa14c3042f - <unknown>
  13:     0x7ffa14c3009e - <unknown>
  14:     0x7ffa14c2e8d5 - <unknown>
  15:     0x7ffa14c50503 - <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::he57f23671b55c8bb
  16:     0x7ffa14c31ad3 - <unknown>
  17:     0x7ffa14c50a7a - rustc_const_eval::check_match::check_crate::h80f0ce25c2e773dc
  18:     0x7ffa0cbf6c0e - rustc_driver::driver::count_nodes::h761a1dba824a4f1e
  19:     0x7ffa0cb3ad9b - <unknown>
  20:     0x7ffa0cbd137c - rustc_driver::driver::compile_input::h44e43be0fc34a1a1
  21:     0x7ffa0cc22cdb - rustc_driver::run_compiler::h5e34a930c0929e5c
  22:     0x7ffa0caff0ae - <unknown>
  23:     0x7ffa07026801 - _rust_maybe_catch_panic
  24:     0x7ffa0cb2c6e6 - <unknown>
  25:     0x7ffa0701dd2e - std::sys::imp::thread::Thread::new::h7a1b2b1b6bab390a
  26:     0x7ffa2a998363 - BaseThreadInitThunk

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Feb 14, 2017
  2. Mark-Simulacrum commented on May 23, 2017

    @Mark-Simulacrum
    Member

    This no longer ICEs. E-needstest.

  3. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on May 23, 2017
  4. venkatagiri commented on May 25, 2017

    @venkatagiri
    Contributor

    Have created a test for this - https://is.gd/8rwE7u but tidy is failing for the ERROR check.
    How do I make it multi-line?
    Can I re-write the error check from

    //~^ ERROR non-exhaustive patterns: `Bar { bar: C, .. }`, `Bar { bar: D, .. }`, `Bar { bar: E, .. }` and 1 more not covered

    as

    //~^ ERROR non-exhaustive patterns
    //~| `Bar { bar: C, .. }`, `Bar { bar: D, .. }`, `Bar { bar: E, .. }` and 1 more not covered

    Edit: Even splitting into two lines, it is exactly at width 100.

  5. Mark-Simulacrum commented on May 25, 2017

    @Mark-Simulacrum
    Member

    You can cut it short at non-exhaustive patterns; we check for substring not exact match.

  6. venkatagiri commented on May 25, 2017

    @venkatagiri
    Contributor

    How is this different compared to #42217 (comment)?
    Was that just being explicit when possible?

  7. Mark-Simulacrum commented on May 25, 2017

    @Mark-Simulacrum
    Member

    That one needs both since the original error is reported on two lines, IIRC; here, it's a single line with no additional information (other than the span) from what I can tell.

  8. venkatagiri commented on May 25, 2017

    @venkatagiri
    Contributor

    I am still not clear on the differences.
    Here's the playpen for #42217 and playpen for this issue.
    Except for the exact error, both look quite similar to me.

  9. Mark-Simulacrum commented on May 25, 2017

    @Mark-Simulacrum
    Member

    Hm, yeah, you might need two lines here too, actually, now that I look at it. Sorry for the confusion; something like the following should work for this issue (similar to how to format the other issue).

    fn test(f: Foo) {
        match f {
            //~^ ERROR non-exhaustive patterns
            //~| patterns
            Foo::Bar { bar: Bar::A, .. } => (),
            Foo::Bar { bar: Bar::B, .. } => (),
        }
    }
    
  10. added a commit that references this issue on May 26, 2017
    e988851
  11. added 2 commits that reference this issue on May 26, 2017
    076a422
    2c3aa91
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

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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