Skip to content

Internal compiler error: pattern.rs:572: impossible case reached #40657

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

Closed
nortiero opened this issue Mar 19, 2017 · 3 comments
Closed

Internal compiler error: pattern.rs:572: impossible case reached #40657

nortiero opened this issue Mar 19, 2017 · 3 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@nortiero
Copy link

nortiero commented Mar 19, 2017

Hi! I was mixing function pointers with match patterns (they don't mix at all, as far as I understand -- please correct me), obtained the following error:

error: internal compiler error: /Users/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-mac/build/src/librustc_const_eval/pattern.rs:572: impossible case reached

Happens in playground too.

Code:

use std::fmt;

fn du() {    println!("booo");  }
fn du2() {    println!("booo2");  }


struct Baonzo(fn());
const PUM: Baonzo = Baonzo(du);

fn main() {
    let fpx = Baonzo(du);
   
    match fpx  {
        PUM => { println!("Here we are"); },
        _ => {},
    } 
}

##Meta
rustc 1.16.0 (30cf806 2017-03-10)
binary: rustc
commit-hash: 30cf806
commit-date: 2017-03-10
host: x86_64-apple-darwin
release: 1.16.0
LLVM version: 3.9

Backtrace:

thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-mac/build/src/librustc_errors/lib.rs:416
stack backtrace:
   1:        0x107788a1c - std::sys::imp::backtrace::tracing::imp::write::h21ca2762819c7ae8
   2:        0x10779537e - std::panicking::default_hook::{{closure}}::h38f99a37d00bb19b
   3:        0x107794f23 - std::panicking::default_hook::ha2186ee24b50729c
   4:        0x107795837 - std::panicking::rust_panic_with_hook::h979db19ee91d2a53
   5:        0x1052b667a - std::panicking::begin_panic::h8030d48880744908
   6:        0x1052cb43c - rustc_errors::Handler::bug::h760c488cd55d4fdd
   7:        0x10470c82c - rustc::session::opt_span_bug_fmt::{{closure}}::hcb2fbcb88915d137
   8:        0x10470c2e9 - rustc::session::opt_span_bug_fmt::ha610cb4388904d76
   9:        0x10470be6a - rustc::session::bug_fmt::ha5b9adbd8728566e
  10:        0x1043c189d - rustc_const_eval::pattern::PatternContext::lower_variant_or_leaf::h2213017936435fa1
  11:        0x1043c1aa1 - rustc_const_eval::pattern::PatternContext::lower_path::h6738fa3412313318
  12:        0x1043c24b3 - rustc_const_eval::pattern::PatternContext::lower_const_expr::h6183b4b4e74d1517
  13:        0x1043a0a10 - <collections::vec::Vec<T> as collections::vec::SpecExtend<T, I>>::from_iter::h4aa641585b72a90f
  14:        0x1043c271d - rustc_const_eval::pattern::PatternContext::lower_const_expr::h6183b4b4e74d1517
  15:        0x1043c1b4b - rustc_const_eval::pattern::PatternContext::lower_path::h6738fa3412313318
  16:        0x1043bfab8 - rustc_const_eval::pattern::PatternContext::lower_pattern::h3af23c0975bb15dd
  17:        0x1043b929f - rustc_const_eval::check_match::MatchVisitor::check_match::{{closure}}::hacf69a1f1c3994c1
  18:        0x1043b8382 - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr::h5cc0afdd47df9e0c
  19:        0x1043b6fd0 - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr::h5cc0afdd47df9e0c
  20:        0x1043b8f90 - <rustc_const_eval::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body::hacb2f5fa0cd27a97
  21:        0x1043b5a37 - <rustc_const_eval::check_match::OuterVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn::h0e4df7e312384e9b
  22:        0x1043987dc - rustc::hir::intravisit::walk_item::h62266a77147d9707
  23:        0x1043b5f73 - rustc_const_eval::check_match::check_crate::hbb131b3de2ff0e4c
  24:        0x10366fe87 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h9e118a56f5957bd6
  25:        0x103651367 - rustc_driver::driver::phase_3_run_analysis_passes::h0569f99df4eb53d4
  26:        0x103640a90 - rustc_driver::driver::compile_input::hb50de2aa3bf90e59
  27:        0x10368848e - rustc_driver::run_compiler::h4b71cb0b28ba1b4a
  28:        0x10359fff8 - std::panicking::try::do_call::h7cd9045c0206869e
  29:        0x10779844a - __rust_maybe_catch_panic
  30:        0x1035c8913 - <F as alloc::boxed::FnBox<A>>::call_box::hca1d0347a9530a7f
  31:        0x1077944a4 - std::sys::imp::thread::Thread::new::thread_start::hca57ad22492f366f
  32:     0x7fff854ef898 - _pthread_body
  33:     0x7fff854ef729 - _pthread_start

Edit to avoid emojis in text.. silly as it is to enable emojis in technical text

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 1, 2017
@estebank
Copy link
Contributor

Triggered at src/librustc_const_eval/pattern.rs:572.

@nikomatsakis am I correct to understand that the accepted way to do this would be to raise and error and recommend using pattern guard instead?

fn main() {
    let fpx = Baonzo(du);
    match &fpx {
        x if *x == PUM => {
            println!("Here we are");
        }
        _ => {}
    }
}

@nikomatsakis
Copy link
Contributor

This does seem like it should be an error, since we only intend to support constants that derive Eq at the moment.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Mar 9, 2018

The error is now

error: to use a constant of type `Baonzo` in a pattern, `Baonzo` must be annotated with `#[derive(PartialEq, Eq)]`
  --> src/main.rs:14:9
   |
14 |         PUM => { println!("Here we are"); },
   |         ^^^

warning: unreachable pattern
  --> src/main.rs:15:9
   |
15 |         _ => {},
   |         ^
   |
   = note: #[warn(unreachable_patterns)] on by default

error: aborting due to previous error

and no more ICE

@oli-obk oli-obk closed this as completed Mar 9, 2018
@RalfJung RalfJung added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

7 participants