Skip to content

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

@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

Activity

alexcrichton

alexcrichton commented on Aug 29, 2014

@alexcrichton
Member
FranklinChen

FranklinChen commented on Aug 29, 2014

@FranklinChen
Contributor

Similarly, just today (yes, I know the code should not compile, but it is the internal compiler error that is the issue): http://is.gd/tVfINu

fn foo() -> Iterator<uint> {
    range(0u, 10).map(|i| i*i) as Iterator<uint>
}
Valloric

Valloric commented on Aug 31, 2014

@Valloric
Contributor

Getting the same ICE.

$ RUST_BACKTRACE=1 ./test.sh
error: internal compiler error: trying to take the sizing type of base::Expression, 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>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/ast_util.rs:784

stack backtrace:
   1:     0x7f92be37e120 - rt::backtrace::imp::write::h3c0523c13636656fOLq
   2:     0x7f92be381310 - failure::on_fail::h9a355b0a53be785cw7q
   3:     0x7f92beb69740 - unwind::begin_unwind_inner::h0ab5484e74ee0101rje
   4:     0x7f92ba5c1310 - unwind::begin_unwind::h13307728250319235624
   5:     0x7f92ba5c1c80 - diagnostic::Handler::bug::h71ea0abb056f036fCdF
   6:     0x7f92bef5ca50 - driver::session::Session::bug::he64b8581f4fba397U5C
   7:     0x7f92bf327a90 - middle::trans::type_of::sizing_type_of::h3b1d93e5efb712d5Qc9
   8:     0x7f92bf357a60 - middle::trans::expr::trans_unadjusted::h838117360a218d5eJj3
   9:     0x7f92bf314030 - middle::trans::expr::trans::hdcfc6f99615b9e0aIy2
  10:     0x7f92bf366310 - middle::trans::expr::trans_addr_of::h477361cd3bceafb4jK4
  11:     0x7f92bf357a60 - middle::trans::expr::trans_unadjusted::h838117360a218d5eJj3
  12:     0x7f92bf312860 - middle::trans::expr::trans_into::h1423af8cb4e82c3dMu2
  13:     0x7f92bf3f94f0 - middle::trans::_match::store_local::closure.121546
  14:     0x7f92bf3f91e0 - middle::trans::_match::mk_binding_alloca::h6724705899647199174
  15:     0x7f92bf3bfff0 - middle::trans::_match::store_local::hf89815ececead9d8G4h
  16:     0x7f92bf311ed0 - middle::trans::base::init_local::heb1cfcf6c59d83fe1Hd
  17:     0x7f92bf3113e0 - middle::trans::controlflow::trans_stmt::he0a1d9a619a4044drhY
  18:     0x7f92bf312e00 - middle::trans::controlflow::trans_block::h7863f52e43c06945CmY
  19:     0x7f92bf3c8e80 - middle::trans::base::trans_closure::ha6113b08bc17793cAAe
  20:     0x7f92bf303840 - middle::trans::base::trans_fn::hb06093de10539f75nMe
  21:     0x7f92bf2feae0 - middle::trans::base::trans_item::hd285e8d770107116n4e
  22:     0x7f92bf2feae0 - middle::trans::base::trans_item::hd285e8d770107116n4e
  23:     0x7f92bf2feae0 - middle::trans::base::trans_item::hd285e8d770107116n4e
  24:     0x7f92bf2feae0 - middle::trans::base::trans_item::hd285e8d770107116n4e
  25:     0x7f92bf3d3b20 - middle::trans::base::trans_crate::hc2a811966285ee0aOYf
  26:     0x7f92bf8083d0 - driver::driver::phase_4_translate_to_llvm::h06435122d6db3633XHB
  27:     0x7f92bf7ffbf0 - driver::driver::compile_input::ha48623fcead7bd7e5jB
  28:     0x7f92bf893890 - driver::run_compiler::h0b258b9c360b66ddjRE
  29:     0x7f92bf8937a0 - driver::main_args::closure.141085
  30:     0x7f92bf8a7dc0 - task::TaskBuilder<S>::try_future::closure.142270
  31:     0x7f92bf8a7bc0 - task::TaskBuilder<S>::spawn_internal::closure.142247
  32:     0x7f92c03120b0 - task::spawn_opts::closure.8370
  33:     0x7f92bebc2490 - rust_try_inner
  34:     0x7f92bebc2480 - rust_try
  35:     0x7f92beb66cf0 - unwind::try::hea1640d217ab7457H7d
  36:     0x7f92beb66a90 - task::Task::run::hb52aad40b24ebf23Ndd
  37:     0x7f92c0311e10 - task::spawn_opts::closure.8316
  38:     0x7f92beb68930 - thread::thread_start::h741158bbfb282555MCd
  39:     0x7f92bde120c0 - start_thread
  40:     0x7f92be82ff89 - __clone
  41:                0x0 - <unknown>
$ rustc --version
rustc 0.12.0-pre-nightly (5419b2ca2 2014-08-29 22:16:20 +0000)

Repro steps: check out Valloric/nailgun@3e1408e and run ./test.sh.

mrmonday

mrmonday commented on Sep 9, 2014

@mrmonday
Contributor

Another test case:

#![allow(dead_code)]
trait A {}
fn foo<'a>() -> A + 'a { unimplemented!() }

fn main() {}

Play pen: http://is.gd/kTRaZL

Djuffin

Djuffin commented on Sep 11, 2014

@Djuffin

+1
code similar to mrmonday's code

ollie

ollie commented on Sep 16, 2014

@ollie
Author

I tested it with latest rust and my problem seems fixed now. :)

Valloric

Valloric commented on Sep 16, 2014

@Valloric
Contributor

The playpen link from @mrmonday's post now produces the following output from rustc:

<anon>:7:5: 8:2 error: cannot move a value of type A+'a: the size of A+'a cannot be statically determined [E0161]
<anon>:7     unimplemented!()
<anon>:8 }
error: aborting due to previous error
playpen: application terminated with error code 101
Program ended.

So the ICE seems to be gone; haven't yet tried it out my code though.

Valloric

Valloric commented on Sep 17, 2014

@Valloric
Contributor

I cannot repro the ICE on my own code anymore after upgrading to latest nightly. This might actually be fixed now.

ollie

ollie commented on Sep 17, 2014

@ollie
Author

I'll close it then. I think there should be a new issue if there are other problems.

mikedilger

mikedilger commented on Sep 17, 2014

@mikedilger
Contributor

I just compiled a project that compiled fine until tonight's nightly, and the backtrace looks very similar to the original poster's, so I'm putting it here (rather than opening a new issue)

src/main.rs:85:25: 85:51 warning: use of deprecated item: use into_iter, #[warn(deprecated)] on by default
src/main.rs:85     for serverconfig in config.servers.move_iter() {
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~

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>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/ast_util.rs:694

stack backtrace:
   1:     0x7f2e84b7eb80 - rt::backtrace::imp::write::hadb95304cd6b59a2iHq
   2:     0x7f2e84b81d40 - failure::on_fail::h88a79ad90b452a8dK2q
   3:     0x7f2e85331f60 - unwind::begin_unwind_inner::hd810389f34a8dc8bMTd
   4:     0x7f2e80f92570 - unwind::begin_unwind::h883036773483107899
   5:     0x7f2e80f92d10 - diagnostic::Handler::bug::ha03a127ac108cb809ND
   6:     0x7f2e85712040 - driver::session::Session::bug::hd8091c59ae3b07effyx
   7:     0x7f2e85af8300 - middle::trans::type_of::sizing_type_of::h12d44c3ad0a509b9NP9
   8:     0x7f2e85b27670 - middle::trans::meth::get_vtable::h71ff864a2270cfc0kOk
   9:     0x7f2e85b27000 - middle::trans::expr::apply_adjustments::unsized_info::h8041c4d8f81d7431Gl3
  10:     0x7f2e85b2a0e0 - middle::trans::expr::apply_adjustments::unsize_expr::closure.124122
  11:     0x7f2e85b2a220 - middle::trans::expr::apply_adjustments::into_fat_ptr::h012bc185249de733Zs3
  12:     0x7f2e85b25db0 - middle::trans::expr::apply_adjustments::apply_autoref::hff612d8b5d90a70cD82
  13:     0x7f2e85b25db0 - middle::trans::expr::apply_adjustments::apply_autoref::hff612d8b5d90a70cD82
  14:     0x7f2e85ae5960 - middle::trans::expr::trans::h139fd41d89b98122RW2
  15:     0x7f2e85ae4420 - middle::trans::expr::trans_into::hffcd0924abd4fea27S2
  16:     0x7f2e85bc9be0 - middle::trans::tvec::write_content::hd73973faa21b5330vPj
  17:     0x7f2e85b2d780 - middle::trans::tvec::trans_slice_vec::h65d0df732c3725d4PEj
  18:     0x7f2e85b21f10 - middle::trans::expr::trans_unadjusted::hb5708bd9b995e003LD3
  19:     0x7f2e85ae5960 - middle::trans::expr::trans::h139fd41d89b98122RW2
  20:     0x7f2e85b1ab20 - middle::trans::callee::trans_args::h40ba956d7101922f4r2
  21:     0x7f2e85aec7c0 - middle::trans::callee::trans_call_inner::hea87a946e0cffa34961
  22:     0x7f2e85b155b0 - middle::trans::callee::trans_method_call::h5a0bf5976bce0583C21
  23:     0x7f2e85b22da0 - middle::trans::expr::trans_rvalue_dps_unadjusted::h6f9547e6400812f9Sc4
  24:     0x7f2e85b21f10 - middle::trans::expr::trans_unadjusted::hb5708bd9b995e003LD3
  25:     0x7f2e85ae5960 - middle::trans::expr::trans::h139fd41d89b98122RW2
  26:     0x7f2e85b1ab20 - middle::trans::callee::trans_args::h40ba956d7101922f4r2
  27:     0x7f2e85aec7c0 - middle::trans::callee::trans_call_inner::hea87a946e0cffa34961
  28:     0x7f2e85b155b0 - middle::trans::callee::trans_method_call::h5a0bf5976bce0583C21
  29:     0x7f2e85b22da0 - middle::trans::expr::trans_rvalue_dps_unadjusted::h6f9547e6400812f9Sc4
  30:     0x7f2e85b21f10 - middle::trans::expr::trans_unadjusted::hb5708bd9b995e003LD3
  31:     0x7f2e85ae5960 - middle::trans::expr::trans::h139fd41d89b98122RW2
  32:     0x7f2e85b1ab20 - middle::trans::callee::trans_args::h40ba956d7101922f4r2
  33:     0x7f2e85aec7c0 - middle::trans::callee::trans_call_inner::hea87a946e0cffa34961
  34:     0x7f2e85b155b0 - middle::trans::callee::trans_method_call::h5a0bf5976bce0583C21
  35:     0x7f2e85b22da0 - middle::trans::expr::trans_rvalue_dps_unadjusted::h6f9547e6400812f9Sc4
  36:     0x7f2e85b21f10 - middle::trans::expr::trans_unadjusted::hb5708bd9b995e003LD3
  37:     0x7f2e85ae5960 - middle::trans::expr::trans::h139fd41d89b98122RW2
  38:     0x7f2e85b2c9c0 - middle::trans::expr::trans_binary::h5983843557b2865dyf5
  39:     0x7f2e85b21f10 - middle::trans::expr::trans_unadjusted::hb5708bd9b995e003LD3
  40:     0x7f2e85ae4420 - middle::trans::expr::trans_into::hffcd0924abd4fea27S2
  41:     0x7f2e85ae4900 - middle::trans::controlflow::trans_block::h697fa29e838af1025ZY
  42:     0x7f2e85b92810 - middle::trans::base::trans_closure::hf5f648fb424f9c93r1e
  43:     0x7f2e85ad6b60 - middle::trans::base::trans_fn::h17dae15f71272d8eEcf
  44:     0x7f2e85b96490 - middle::trans::meth::trans_impl::h5b1ebd2bcbfeba03Xck
  45:     0x7f2e85ad3780 - middle::trans::base::trans_item::h7f0dc64cc8095e95Nvf
  46:     0x7f2e85ad3780 - middle::trans::base::trans_item::h7f0dc64cc8095e95Nvf
  47:     0x7f2e85ad3780 - middle::trans::base::trans_item::h7f0dc64cc8095e95Nvf
  48:     0x7f2e85b9e780 - middle::trans::base::trans_crate::h40ab1d2d17a4f286Gtg
  49:     0x7f2e85f98330 - driver::driver::phase_4_translate_to_llvm::h9eab234cedcf7a6b7Yw
  50:     0x7f2e85f8f590 - driver::driver::compile_input::h06caa00e975ed0209ww
  51:     0x7f2e860126b0 - driver::run_compiler::h30663c3fdd061b12FnA
  52:     0x7f2e86012590 - driver::main_args::closure.146245
  53:     0x7f2e85740740 - task::TaskBuilder<S>::try_future::closure.101946
  54:     0x7f2e85740530 - task::TaskBuilder<S>::spawn_internal::closure.101917
  55:     0x7f2e8691e590 - task::spawn_opts::closure.8444
  56:     0x7f2e85389480 - rust_try_inner
  57:     0x7f2e85389470 - rust_try
  58:     0x7f2e8532f560 - unwind::try::h985905ef4937434euId
  59:     0x7f2e8532f3c0 - task::Task::run::h3a7021021ab3297dfYc
  60:     0x7f2e8691e300 - task::spawn_opts::closure.8384
  61:     0x7f2e85330fb0 - thread::thread_start::h67b84fc708de7e36rid
  62:     0x7f2e84645100 - start_thread
  63:     0x7f2e8500c929 - clone
  64:                0x0 - <unknown>
MatejLach

MatejLach commented on Sep 17, 2014

@MatejLach
Contributor

@mikedilger It might be better to open it as a new issue for better visibility.
@nick29581 ?

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @ollie@alexcrichton@Djuffin@FranklinChen@mrmonday

        Issue actions

          Compiler error "trying to take the sizing type of str, an unsized type" · Issue #16848 · rust-lang/rust