Skip to content

Match bytes and &str #26510

Closed
Closed
@ctjhoa

Description

@ctjhoa

I tried this code:

#![feature(slice_patterns)]

fn main() {
    let buf = [0u8; 4];
    match &buf {
        &[0, 1, 0, 0] => (),
        b"true" => (),
        _ => ()
    }   

}

I expected to see this happen:
I'm relatively new to rust, I tried to match a &str and &[u8] which seems to be the same type according to the doc :
http://doc.rust-lang.org/std/primitive.str.html#method.as_bytes

Instead, this happened:
The compiler panicked. I have maybe done something wrong but the compiler should not panicked for that.

Meta

rustc --version --verbose:

rustc 1.2.0-nightly (2f5683913 2015-06-18)
binary: rustc
commit-hash: 2f5683913c9815d9f12494784747f79b0f3b3066
commit-date: 2015-06-18
host: x86_64-unknown-linux-gnu
release: 1.2.0-nightly

Backtrace:

stack backtrace:
   1:     0x7fefaea8f3d3 - sys::backtrace::write::hac6f7844a2c08518pqs
   2:     0x7fefaea97551 - panicking::on_panic::he3a077dab5880a1969w
   3:     0x7fefaea5628a - rt::unwind::begin_unwind_inner::h07f84ceedf6e11d3KPw
   4:     0x7fefac86127e - rt::unwind::begin_unwind::h10696837115463997933
   5:     0x7fefac9d6525 - middle::check_match::is_useful::h9a04b6e449073316V6h
   6:     0x7fefac9feb34 - middle::check_match::is_useful_specialized::h6788c2bb0c1a90c7Yfi
   7:     0x7fefac9ffd01 - middle::check_match::is_useful::closure.84515
   8:     0x7fefac9ffa36 - option::Option<T>::map::h16552866249183522699
   9:     0x7fefac9d69ff - middle::check_match::is_useful::h9a04b6e449073316V6h
  10:     0x7fefac9cde61 - middle::check_match::check_expr::h992a26755f1102e2jsh
  11:     0x7fefac9cfe7a - middle::check_match::check_fn::h9f9b0f213eee3b189Fi
  12:     0x7fefac9d06e0 - visit::walk_item::h1113646532361864268
  13:     0x7fefac9d056a - middle::check_match::check_crate::hd23a048468bf7963Wrh
  14:     0x7fefaeff943e - driver::phase_3_run_analysis_passes::h0789c185cb5142aeIGa
  15:     0x7fefaefd94fa - driver::compile_input::h673b093cab67a345Tba
  16:     0x7fefaf094f37 - run_compiler::hd964f53796cdaa72G7b
  17:     0x7fefaf092526 - boxed::F.FnBox<A>::call_box::h4406333435808980122
  18:     0x7fefaf091d29 - rt::unwind::try::try_fn::h10492881588876420525
  19:     0x7fefaeb13ed8 - rust_try_inner
  20:     0x7fefaeb13ec5 - rust_try
  21:     0x7fefaea82147 - rt::unwind::try::inner_try::h18f1f3c9b9ec8956DLw
  22:     0x7fefaf091f49 - boxed::F.FnBox<A>::call_box::h8032357446467525174
  23:     0x7fefaea96181 - sys::thread::Thread::new::thread_start::h6ee35face9d3fb15AVv
  24:     0x7fefa881f353 - start_thread
  25:     0x7fefae6eabfc - __clone
  26:                0x0 - <unknown>

Thanks

Metadata

Metadata

Assignees

No one assigned

    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