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

Pattern matching with overlapping matches crash the compiler #12369

Closed
haralkar opened this issue Feb 18, 2014 · 5 comments
Closed

Pattern matching with overlapping matches crash the compiler #12369

haralkar opened this issue Feb 18, 2014 · 5 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@haralkar
Copy link

The following code, compiled on Ubuntu 12.04.3 LTS Precise Pangolin - Release i386 (20130820.1) :

fn main() {
    let sl = ~[1,2,3];
    let v : int = match sl.as_slice() {
        [] => 0,
        [a,b,c] => 3,
        [a, ..rest] => a,
        [10,a, ..rest] => 10
    };
}

causes rustc to spew forth:

error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: the compiler hit an unexpected failure path. this is a bug
Ok(task 'rustc' failed at 'called `Option::unwrap()` on a `None` value', /home/haralkar/source/other/rust/src/libstd/option.rs:152
)

stack trace:

#0  0xb7b201f0 in rust_fail () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#1  0xb7b201ca in rt::unwind::Unwinder::begin_unwind::h0fb1c94e84003260fVl::v0.10.pre () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#2  0xb7a5b8fc in rt::unwind::begin_unwind_inner::h773d77f533ab0b7f63l::v0.10.pre () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#3  0xb4d92472 in rt::unwind::begin_unwind::hef0624ac43bd2c30lut::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#4  0xb5115c1d in middle::check_match::is_useful_specialized::h2768080653796199dAv::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#5  0xb511238a in middle::check_match::is_useful::he651c1f6fa4baa58Osv::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#6  0xb510acc3 in middle::check_match::check_expr::h7a2f3f3075653f85L6u::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#7  0xb511be40 in visit::walk_local::h62e699c47b530baa6Nx::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#8  0xb510d091 in middle::check_match::CheckMatchVisitor.Visitor$LT$$LP$$RP$$GT$::visit_local::ha5f445c46fcd4cdeV4u::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#9  0xb510f4b8 in visit::walk_decl::h56fc78a0011a49f22Mx::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#10 0xb510f3a7 in visit::walk_stmt::h5a83bf7c9e1926ddKLx::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#11 0xb510f300 in visit::walk_block::h5fe9aa45b8c870b51Gx::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#12 0xb511c3ea in visit::walk_fn::h2d0a7d76b5928a56TXx::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#13 0xb510d3c1 in middle::check_match::CheckMatchVisitor.Visitor$LT$$LP$$RP$$GT$::visit_fn::h5d86c04b034efca9h5u::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#14 0xb510e166 in visit::walk_item::h2046ebdf6b6a01e8o6z::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#15 0xb510d62c in middle::check_match::check_crate::h743fc3cd5a0af3f1Z5u::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#16 0xb53a124c in driver::driver::phase_3_run_analysis_passes::closure () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#17 0xb5105333 in util::common::time::h03cd35a5f105859447j::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#18 0xb539e988 in driver::driver::phase_3_run_analysis_passes::h3d5ff619b94fc529sZh::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#19 0xb53a41b6 in driver::driver::compile_input::hcf12d2e8a6a52e3f2mi::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#20 0xb53c6f42 in run_compiler::haa0a4958670ee4faueq::v0.10.pre () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#21 0xb53d800c in main_args::closure () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#22 0xb53d6583 in monitor::closure () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#23 0xb53d1c16 in task::TaskBuilder::try::closure () from /usr/local/bin/../lib/librustc-0d83f02f-0.10-pre.so
#24 0xb79bc808 in task::bootstrap_green_task::closure () from /usr/local/bin/../lib/libgreen-80d9e76a-0.10-pre.so
#25 0xb7b19659 in rt::task::Task::run::closure () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#26 0xb7b20134 in rt::unwind::Unwinder::try::try_fn::h7ffff9688f83cea7bUl::v0.10.pre () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#27 0xb7b23573 in rust_try () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#28 0xb7b1951b in rt::task::Task::run::he29d8027dadeaed4wvj::v0.10.pre () from /usr/local/bin/../lib/libstd-966edb7e-0.10-pre.so
#29 0xb79bc6d7 in task::bootstrap_green_task::h24b4ab701c781efax8b::v0.10.pre () from /usr/local/bin/../lib/libgreen-80d9e76a-0.10-pre.so
#30 0x00000000 in ?? ()
@Armavica
Copy link
Contributor

Very similar to #11241.
I managed to get a shorter MCE:

fn main() {
    match ~[] {
        [] => (),
        [2, ..] => (),
        [3, 4, ..] => ()
    };
}

@daimrod
Copy link

daimrod commented Apr 17, 2014

I think I've encounter the same error with the following code:

fn main() {
    enum List {
        Cons(int, ~List),
        Nil
    }

    let x = ~Cons(1, ~Nil);
    match *x {
        Cons(a, ~ref next) => (),
        Cons(b, ~Nil) => (),
        _ => ()
    }
}

With this build:

$ rustc -v
rustc 0.11-pre-nightly (e415c25 2014-04-07 21:21:47 -0700)
host: x86_64-unknown-linux-gnu

(I couldn't use the shorter MCE because apparently unique vector patterns are no longer supported)

Here is the backtrace:

task 'rustc' failed at 'index out of bounds: the len is 0 but the index is 0', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/librustc/middle/check_match.rs:250
stack backtrace:
   1:     0x7ffff4cf08d0 - rt::backtrace::imp::write::hbf83dfcc05310575AAa::v0.11.pre
   2:     0x7ffff4c52410 - rt::unwind::begin_unwind_inner::h72aa261e64bf1fd83aa::v0.11.pre
   3:     0x7ffff4c52380 - rt::unwind::begin_unwind::h4b893fbf219dd919Daa::v0.11.pre
   4:     0x7ffff4cf04e0 - rt::unwind::begin_unwind_raw::h93661c3a4ab845afc89::v0.11.pre
   5:     0x7ffff4c516b0 - rt::unwind::fail_::h01af7c814d53a60dQ59::v0.11.pre
   6:     0x7ffff4cf0550 - rt::unwind::fail_bounds_check::closure.41280
   7:     0x7ffff4c535e0 - rt::unwind::fail_bounds_check::h4ad50d6b3ee732e1d69::v0.11.pre
   8:     0x7ffff5c7f740 - middle::check_match::is_useful::h50ad727595973596onu::v0.11.pre
   9:     0x7ffff5c86d20 - middle::check_match::is_useful_specialized::h7bf269c0b1d4ff84Itu::v0.11.pre
  10:     0x7ffff5c7f740 - middle::check_match::is_useful::h50ad727595973596onu::v0.11.pre
  11:     0x7ffff5c86d20 - middle::check_match::is_useful_specialized::h7bf269c0b1d4ff84Itu::v0.11.pre
  12:     0x7ffff5c7f740 - middle::check_match::is_useful::h50ad727595973596onu::v0.11.pre
  13:     0x7ffff5c7f740 - middle::check_match::is_useful::h50ad727595973596onu::v0.11.pre
  14:     0x7ffff5c86d20 - middle::check_match::is_useful_specialized::h7bf269c0b1d4ff84Itu::v0.11.pre
  15:     0x7ffff5c7f740 - middle::check_match::is_useful::h50ad727595973596onu::v0.11.pre
  16:     0x7ffff5c79000 - middle::check_match::check_expr::hf7e16ae699ad3b0ai4t::v0.11.pre
  17:     0x7ffff5c7ebd0 - visit::walk_expr_opt::h2b6380fdab1223ffi4t::v0.11.pre
  18:     0x7ffff5c7b9f0 - middle::check_match::check_fn::h732a3f7e2aef6fbbD6u::v0.11.pre
  19:     0x7ffff5c7c5f0 - visit::walk_item::h5b4743caefa33010p4v::v0.11.pre
  20:     0x7ffff5c7bc70 - middle::check_match::check_crate::hf456e2a1e5a27a8eD3t::v0.11.pre
  21:     0x7ffff5c74600 - util::common::time::h7270488e3f9a7dadMug::v0.11.pre
  22:     0x7ffff60a9290 - driver::driver::phase_3_run_analysis_passes::h5bc132a1236cdb1dqje::v0.11.pre
  23:     0x7ffff60afcc0 - driver::driver::compile_input::h5158f3c2b13a0794nIe::v0.11.pre
  24:     0x7ffff60d3540 - run_compiler::h462d0269b5e002b949l::v0.11.pre
  25:     0x7ffff60ea810 - main_args::closure.91855
  26:     0x7ffff60e9140 - monitor::closure.91740
  27:     0x7ffff60e4a70 - task::TaskBuilder::try::closure.91515
  28:     0x7ffff53754d0 - task::spawn_opts::closure.7786
  29:     0x7ffff4cebd60 - rt::task::Task::run::closure.41185
  30:     0x7ffff4cf7310 - rust_try
  31:     0x7ffff4cebba0 - rt::task::Task::run::h2c4ca697d400385cz37::v0.11.pre
  32:     0x7ffff53752a0 - task::spawn_opts::closure.7759
  33:     0x7ffff4cef410 - rt::thread::thread_start::h934e1ab986d86e35gI8::v0.11.pre
  34:     0x7ffff2525fa0 - start_thread
  35:     0x7ffff4926a09 - __clone
  36:                0x0 - <unknown>

@huonw
Copy link
Member

huonw commented Apr 17, 2014

@daimrod that's possibly slightly different (at least, the failure message is different, although they're in the same area of code).

Btw, the MCE still works when used without unique vectors:

fn main() {
    match &[] {
        [] => (),
        [2, ..] => (),
        [3, 4, ..] => ()
    }
}
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'called `Option::unwrap()` on a `None` value', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libstd/option.rs:264
stack backtrace:
   1:     0x7fde205896a0 - rt::backtrace::imp::write::h167f38c59baeff8aqRa::v0.11.pre
   2:     0x7fde204eafa0 - rt::unwind::begin_unwind_inner::hc4665026b45f6a5aTra::v0.11.pre
   3:     0x7fde21141f60 - rt::unwind::begin_unwind::ha806566b31ba8340qXp::v0.11.pre
   4:     0x7fde21538520 - middle::check_match::is_useful_specialized::h5bccec681de6c692gAu::v0.11.pre
   5:     0x7fde21530f40 - middle::check_match::is_useful::h5ffe9bbdddc6b96fWtu::v0.11.pre
   6:     0x7fde2152a770 - middle::check_match::check_expr::hd8afce200b8873afQau::v0.11.pre
   7:     0x7fde215303d0 - visit::walk_expr_opt::h85f69636933670ccMku::v0.11.pre
   8:     0x7fde2152d160 - middle::check_match::check_fn::h67f8bdc6ca535dcbbdv::v0.11.pre
   9:     0x7fde2152de10 - visit::walk_item::hd4abe3032d44eb0fQjw::v0.11.pre
  10:     0x7fde2152d3e0 - middle::check_match::check_crate::h945724cd4dbeabc2bau::v0.11.pre
  11:     0x7fde21525c70 - util::common::time::h8ad21ae303e4a453Swg::v0.11.pre
  12:     0x7fde21963e80 - driver::driver::phase_3_run_analysis_passes::h679c7da862d3eab5sje::v0.11.pre
  13:     0x7fde2196a890 - driver::driver::compile_input::h78d619679e701e77nIe::v0.11.pre
  14:     0x7fde2198edf0 - run_compiler::h304797548f90c81exgm::v0.11.pre
  15:     0x7fde219a64f0 - main_args::closure.91891
  16:     0x7fde219a4e20 - monitor::closure.91776
  17:     0x7fde219a0700 - task::TaskBuilder::try::closure.91542
  18:     0x7fde20c1aab0 - task::spawn_opts::closure.7971
  19:     0x7fde205846d0 - rt::task::Task::run::closure.40115
  20:     0x7fde20590230 - rust_try
  21:     0x7fde20584510 - rt::task::Task::run::h5360bb699175a8aefi8::v0.11.pre
  22:     0x7fde20c1a880 - task::spawn_opts::closure.7944
  23:     0x7fde205881e0 - rt::thread::thread_start::h8ec2412a6038d9b80W8::v0.11.pre
  24:     0x7fde1ddbdfa0 - start_thread
  25:     0x7fde201bea09 - __clone
  26:                0x0 - <unknown>

@daimrod
Copy link

daimrod commented Apr 17, 2014

@huonw Ok, should I open a dedicated issue?

@huonw
Copy link
Member

huonw commented Apr 17, 2014

@daimrod it seems to be covered by #12116.

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 7, 2024
…gression, r=flip1995

Fix `nonminimal_bool` lint regression

Fixes rust-lang#12371.
Fixes rust-lang#12369.

cc `@RalfJung`

The problem was an invalid condition. Shame on me...

changelog: Fix `nonminimal_bool` lint regression
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