Compiler panics while compiling the following code:
use libc::c_char;
use std::ffi;
use std::str;
use std::vec;
struct TokenCollection {
parts: Vec<&str>,
name: &str
}
fn c_str_to_slice(c_str: *mut c_char) -> &str {
let c_bytes = unsafe { ffi::c_str_to_bytes(&c_str); };
std::from_utf8(c_bytes).unwrap()
}
impl TokenCollection {
fn new(str: &str) -> &TokenCollection {
TokenCollection {
parts: str.split(|c| c.is_whitespace()).collect()
}
}
fn len(&self) -> usize {
self.parts.len()
}
}
// impl Drop for TokenCollection {
// fn drop(&self) {
// println!("drop it like it's hot");
// }
// }
#[no_mangle]
pub extern fn token_collection_create(c_str: *c_char) -> *mut TokenCollection {
let str = c_str_to_slice(c_str);
unsafe { transmute(box TokenCollection::new(str)) }
}
#[no_mangle]
pub extern fn token_collection_len(pimpl: *mut TokenCollection) -> libc::uint64_t {
pimpl.len()
}
#[no_mangle]
pub extern fn token_collection_destroy(pimpl: *mut TokenCollection) {
let str = c_str_to_slice(c_str);
unsafe { transmute(box TokenCollection::new(str)) }
}
I expected running the compiler would show the errors it found in the code, which it did, but then it paniced:
Compiler command: rustc foo.rs --crate-type="staticlib" -o foo.a
Compiler output:
foo.rs:35:46: 35:47 error: bare raw pointers are no longer allowed, you should likely use `*mut T`, but otherwise `*T` is now known as `*const T`
foo.rs:35 pub extern fn token_collection_create(c_str: *c_char) -> *mut TokenCollection {
^
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
...
Meta
rustc --version --verbose:
rustc 1.0.0-nightly (91bdf23f5 2015-03-09) (built 2015-03-08)
binary: rustc
commit-hash: 91bdf23f504f79ed59617cde3dfebd3d5e39a476
commit-date: 2015-03-09
build-date: 2015-03-08
host: x86_64-apple-darwin
release: 1.0.0-nightly
Backtrace:
stack backtrace:
1: 0x1080af27d - sys::backtrace::write::h8bb5f05fb3b15b46KDA
2: 0x1080d8c34 - panicking::on_panic::h774322e801e90255MsJ
3: 0x10800a299 - rt::unwind::begin_unwind_inner::h91fe489b48891c2fibJ
4: 0x10800a71e - rt::unwind::begin_unwind_fmt::h611a8fe214a71d11T9I
5: 0x1080d870d - rust_begin_unwind
6: 0x108127815 - panicking::panic_fmt::h28951af8a1739750HZs
7: 0x108121b07 - panicking::panic::h1f407e1cc2932c40TXs
8: 0x1047a1667 - driver::build_output_filenames::h2291f05686c39ba461a
9: 0x1047963a9 - driver::compile_input::h65a0e989415894e2Nba
10: 0x104864bd6 - run_compiler::h6bbe5e8fdeccf450G6b
11: 0x1048622c0 - thunk::F.Invoke<A, R>::invoke::h11072616449651537896
12: 0x104860dff - rt::unwind::try::try_fn::h9635732175488659353
13: 0x108152ca8 - rust_try_inner
14: 0x108152c95 - rust_try
15: 0x10486161f - thunk::F.Invoke<A, R>::invoke::h10357567482835563298
16: 0x1080c43f2 - sys::thread::thread_start::h214ccfe780c3e0cb32E
17: 0x7fff88da5898 - _pthread_body
18: 0x7fff88da5729 - _pthread_start
Compiler panics while compiling the following code:
I expected running the compiler would show the errors it found in the code, which it did, but then it paniced:
Compiler command:
rustc foo.rs --crate-type="staticlib" -o foo.aCompiler output:
Meta
rustc --version --verbose:Backtrace: