Skip to content

Compiler error "trying to take the sizing type of str, an unsized type" #16848

Closed
@ollie

Description

@ollie

Hello,

I don't know if this is related to #16822 or not. I was following the example here http://doc.rust-lang.org/getopts/ and wanted to tweak it so the program is only the filename, not the whole path to it. So I started hacking around and extracted it into a function, which resulted into this error.

I'm new to Rust, so… I'm doing silly things probably. :) Feel free to tell me.
Anyway this is not the "getopts" code, I wanted to isolate the problem. I also made the types explicit for illustration.

fn main() {
    let filename: &str = &filename_of_foo();
    // `filename` should be &"foo"
    println!("The filename is {}", filename);
}

fn filename_of_foo() -> str {
    let path: Path     = Path::new("./bar/foo");
    let filename: &str = path.filename_str().unwrap();
    *filename
}
$ RUST_BACKTRACE=1 rustc main.rs
error: internal compiler error: trying to take the sizing type of str, an unsized type
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'Box<Any>', /Users/olda/Code/rust/rust-lang/src/libsyntax/ast_util.rs:776

stack backtrace:
   1:        0x10e7ea9b5 - rt::backtrace::imp::write::hbe93ad1ca3375f7ai9q
   2:        0x10e7edd33 - failure::on_fail::ha008d924473a588cbqr
   3:        0x10eab3d23 - unwind::begin_unwind_inner::h53af0f566031f9f14fe
   4:        0x10c7b643a - unwind::begin_unwind::h3612296561932415380
   5:        0x10c7b6e40 - diagnostic::Handler::bug::h6cd4a0f0829e2050shF
   6:        0x10b3a5c58 - driver::session::Session::bug::hba3620fae1af216dkXz
   7:        0x10b75c121 - middle::trans::type_of::sizing_type_of::h7963730f82cd4b33Ma9
   8:        0x10b78aeac - middle::trans::expr::trans_unadjusted::he74a35bd5ea421c1Fh3
   9:        0x10b748380 - middle::trans::expr::trans::hd79efa6056358d2dEw2
  10:        0x10b798ca1 - middle::trans::expr::trans_addr_of::hff42e1cdb8b6828bfI4
  11:        0x10b78b4f8 - middle::trans::expr::trans_unadjusted::he74a35bd5ea421c1Fh3
  12:        0x10b748380 - middle::trans::expr::trans::hd79efa6056358d2dEw2
  13:        0x10b746b48 - middle::trans::expr::trans_into::h4adfb7ed4c8e4c8eIs2
  14:        0x10b82a54f - middle::trans::_match::store_local::closure.119296
  15:        0x10b82a321 - middle::trans::_match::mk_binding_alloca::h11723812663586266914
  16:        0x10b7f2233 - middle::trans::_match::store_local::h15ef2e60d6b94e5cA2h
  17:        0x10b7463b2 - middle::trans::base::init_local::hf1089f76e4fd41bdWFd
  18:        0x10b7458ea - middle::trans::controlflow::trans_stmt::h2ab88f6dc40905eblhY
  19:        0x10b74701c - middle::trans::controlflow::trans_block::hee6f69106b0dfacewmY
  20:        0x10b7fd0e2 - middle::trans::base::trans_closure::h9bdf3049defa1b73vye
  21:        0x10b7382a0 - middle::trans::base::trans_fn::hf0c57f353c923cd3iKe
  22:        0x10b73361f - middle::trans::base::trans_item::hbe3f225a458737f5i2e
  23:        0x10b8060bc - middle::trans::base::trans_crate::h430604ba8b62ae67JWf
  24:        0x10bbc0811 - driver::driver::phase_4_translate_to_llvm::h3758d3df9e2a7401pzy
  25:        0x10bbb9d3d - driver::driver::compile_input::hf84c86c09fa7f085Qby
  26:        0x10bc43dc7 - driver::run_compiler::hd0616be9c11c6733JIB
  27:        0x10bc42506 - driver::main_args::closure.138223
  28:        0x10bc53dbb - task::TaskBuilder<S>::try_future::closure.139341
  29:        0x10bc53cc3 - task::TaskBuilder<S>::spawn_internal::closure.139318
  30:        0x10e71e2ec - task::spawn_opts::closure.8459
  31:        0x10eb18b0c - rust_try_inner
  32:        0x10eb18af6 - rust_try
  33:        0x10eab1177 - unwind::try::h5bbc3fdef4df0c47k4d
  34:        0x10eab0f3b - task::Task::run::h3fd23eb8e2343898bbd
  35:        0x10e71e132 - task::spawn_opts::closure.8404
  36:        0x10eab2cb6 - thread::thread_start::hb6d4d41faea4249bXzd
  37:     0x7fff8ce03899 - _pthread_body
  38:     0x7fff8ce0372a - _pthread_struct_init

My system:
OS X 10.9.4

$ uname -v
Darwin Kernel Version 13.3.0: Tue Jun  3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64
$ rustc --version
rustc 0.12.0-pre (0d3bd7720 2014-08-27 21:31:13 +0000)
$ cargo --version
cargo 0.0.1-pre (89259f1 2014-08-28 18:28:57 +0000)

Thanks,
Ollie

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