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

ICE: Unexpected type returned from struct_tail #16812

Closed
ftxqxd opened this issue Aug 28, 2014 · 11 comments · Fixed by #37111
Closed

ICE: Unexpected type returned from struct_tail #16812

ftxqxd opened this issue Aug 28, 2014 · 11 comments · Fixed by #37111
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Aug 28, 2014

enum Foo {
    Bar(int, [int]),
}

fn main() {
    // Either of these lines can cause the ICE
    let _x: &(int, [int]);
    let _y: &Foo;
}

Backtrace:

   1:     0x7f2a127e8580 - rt::backtrace::imp::write::h0180e7ded76a3ff2c0q
   2:     0x7f2a127eb770 - failure::on_fail::h3f169393c89b5f90Tlr
   3:     0x7f2a12fd24f0 - unwind::begin_unwind_inner::haeb9517b5061bc86Zie
   4:     0x7f2a133ad670 - unwind::begin_unwind::h17017358962417336117
   5:     0x7f2a13803a20 - middle::ty::unsized_part_of_type::h8eae6d239e9b7af3tnG
   6:     0x7f2a138037c0 - middle::trans::type_of::type_of::type_of_unsize_info::h67819f63aa2acfb5Xh9
   7:     0x7f2a1377b050 - middle::trans::type_of::type_of::h3c89a1738d384c45Ih9
   8:     0x7f2a1377b050 - middle::trans::type_of::type_of::h3c89a1738d384c45Ih9
   9:     0x7f2a137b0860 - middle::trans::base::alloc_ty::h5485998eeb61d023mTd
  10:     0x7f2a13859870 - middle::trans::_match::mk_binding_alloca::h11628361498234501597
  11:     0x7f2a1385bdf0 - middle::trans::_match::store_local::create_dummy_locals::closure.119283
  12:     0x7f2a13681560 - middle::pat_util::pat_bindings::closure.112016
  13:     0x7f2a0ea1ccb0 - ast_util::walk_pat::hc858153057fb5965oRB
  14:     0x7f2a138205f0 - middle::trans::_match::store_local::h9195017fe21b4124A2h
  15:     0x7f2a13772d10 - middle::trans::base::init_local::h5e8a493dc2ae05b1WFd
  16:     0x7f2a13772220 - middle::trans::controlflow::trans_stmt::hf26d5cee55a6056blhY
  17:     0x7f2a13773c40 - middle::trans::controlflow::trans_block::h004dea36138a75c8wmY
  18:     0x7f2a13829560 - middle::trans::base::trans_closure::h655acfc433ac13fevye
  19:     0x7f2a13764670 - middle::trans::base::trans_fn::hf0a444fa9ff43aebiKe
  20:     0x7f2a1375f9b0 - middle::trans::base::trans_item::hda4d4160cb2b58dfi2e
  21:     0x7f2a138341f0 - middle::trans::base::trans_crate::hff0f87c98e6356c8JWf
  22:     0x7f2a13c058d0 - driver::driver::phase_4_translate_to_llvm::h8223ee9d7ab4951cpzy
  23:     0x7f2a13bfd280 - driver::driver::compile_input::hfa4fd95c9e6a2ceeQby
  24:     0x7f2a13c8f0a0 - driver::run_compiler::h32bdccca6ed9465cJIB
  25:     0x7f2a13c8efb0 - driver::main_args::closure.138206
  26:     0x7f2a13ca1240 - task::TaskBuilder<S>::try_future::closure.139324
  27:     0x7f2a13ca1040 - task::TaskBuilder<S>::spawn_internal::closure.139301
  28:     0x7f2a146dcf10 - task::spawn_opts::closure.8369
  29:     0x7f2a1302af90 - rust_try_inner
  30:     0x7f2a1302af80 - rust_try
  31:     0x7f2a12fcfb20 - unwind::try::h03d8d1d4cb0de0c1f7d
  32:     0x7f2a12fcf8e0 - task::Task::run::hafab6bcab45e61e5zdd
  33:     0x7f2a146dcc70 - task::spawn_opts::closure.8315
  34:     0x7f2a12fd16e0 - thread::thread_start::hba588af1f803bb5blCd
  35:     0x7f2a1227f0c0 - start_thread
  36:     0x7f2a12c99359 - __clone
  37:                0x0 - <unknown>

This seems to occur when using a non-struct type that contains an unsized type. This is probably because unsized_part_of_type only handles ty_struct and the base unsized types. This should be extended to handle enums and tuples as well.

@pythonesque
Copy link
Contributor

This is still happening. Does this mean we should avoid using DSTs for complex custom types for now?

@frewsxcv
Copy link
Member

frewsxcv commented Feb 7, 2015

Visiting for triage

This is still an issue:

/tmp $ rustc hi.rs
hi.rs:2:9: 2:12 warning: the `int` type is deprecated; use `isize` or a fixed-sized integer
hi.rs:2     Bar(int, [int]),
                ^~~
hi.rs:2:9: 2:12 help: add #![feature(int_uint)] to the crate attributes to silence this warning
hi.rs:2     Bar(int, [int]),
                ^~~
hi.rs:2:15: 2:18 warning: the `int` type is deprecated; use `isize` or a fixed-sized integer
hi.rs:2     Bar(int, [int]),
                      ^~~
hi.rs:2:15: 2:18 help: add #![feature(int_uint)] to the crate attributes to silence this warning
hi.rs:2     Bar(int, [int]),
                      ^~~
hi.rs:7:15: 7:18 warning: the `int` type is deprecated; use `isize` or a fixed-sized integer
hi.rs:7     let _x: &(int, [int]);
                      ^~~
hi.rs:7:15: 7:18 help: add #![feature(int_uint)] to the crate attributes to silence this warning
hi.rs:7     let _x: &(int, [int]);
                      ^~~
hi.rs:7:21: 7:24 warning: the `int` type is deprecated; use `isize` or a fixed-sized integer
hi.rs:7     let _x: &(int, [int]);
                            ^~~
hi.rs:7:21: 7:24 help: add #![feature(int_uint)] to the crate attributes to silence this warning
hi.rs:7     let _x: &(int, [int]);
                            ^~~
hi.rs:2:5: 2:20 warning: variant is never used: `Bar`, #[warn(dead_code)] on by default
hi.rs:2     Bar(int, [int]),
            ^~~~~~~~~~~~~~~
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. 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
thread 'rustc' panicked at 'unsized_part_of_type failed even though ty is unsized', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc_trans/trans/common.rs:166

stack backtrace:
   1:        0x10cdf4ef7 - sys::backtrace::write::h88d0d05790f5fe63uvy
   2:        0x10ce1b1d2 - failure::on_fail::h254ebaa74a16f795dOF
   3:        0x10cd70828 - rt::unwind::begin_unwind_inner::ha4f653fd236db381FvF
   4:        0x10948a235 - rt::unwind::begin_unwind::h12190706954857531769
   5:        0x10955e7f1 - trans::common::unsized_part_of_type::heb51b171ecadcb48HMk
   6:        0x10958f3b2 - trans::type_of::type_of::type_of_unsize_info::hd1a63e34e2e99b94A2o
   7:        0x1094e2e81 - trans::type_of::type_of::h2372af414ad01c3ag2o
   8:        0x1095114fd - trans::base::alloc_ty::h3d6cf8c39435c8c2yut
   9:        0x1095d95a5 - ast_util::walk_pat::walk_pat_::h12916028195929177049
  10:        0x1094d763f - trans::base::init_local::hfb21acfe815478f3Ggt
  11:        0x1094d8933 - trans::controlflow::trans_block::h924ca481d4b4516asae
  12:        0x1095a486d - trans::base::trans_closure::h818341d4fc835178E5t
  13:        0x1094c45d6 - trans::base::trans_fn::h13435eb2cf011516Ogu
  14:        0x1094bf723 - trans::base::trans_item::hd9986468b8457cd3fFu
  15:        0x1095aab7c - trans::base::trans_crate::h3c7ea32f1a6ebc96ZBv
  16:        0x109360757 - driver::phase_4_translate_to_llvm::h2222bdf86d2278693Oa
  17:        0x10933c772 - driver::compile_input::h024fc27312c2cbcbCba
  18:        0x10940f6fe - run_compiler::h655f217f5987c6497ac
  19:        0x10940c6ef - thunk::F.Invoke<A, R>::invoke::h3444412781138926669
  20:        0x10940b380 - rt::unwind::try::try_fn::h12649063132436107851
  21:        0x10ce923c9 - rust_try_inner
  22:        0x10ce923b6 - rust_try
  23:        0x10940ba40 - thunk::F.Invoke<A, R>::invoke::h6921957054689317792
  24:        0x10ce057d3 - sys::thread::thread_start::h6219f4f9fd58602fhDB
  25:     0x7fff9201f268 - _pthread_body
  26:     0x7fff9201f1e5 - _pthread_body

@tomjakubowski
Copy link
Contributor

ICE also happens with a tupled trait object:

fn main() {
    let x: &(Clone, Iterator) = panic!();
}
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. 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
thread 'rustc' panicked at 'unsized_part_of_type failed even though ty is unsized', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/common.rs:166

stack backtrace:
   1:     0x7f197e3b3750 - sys::backtrace::write::h49b06c4e5fa1765dZTA
   2:     0x7f197e3d83e0 - failure::on_fail::h128a61ca90111ec2JFJ
   3:     0x7f197e330350 - rt::unwind::begin_unwind_inner::h142cc6242e7988934jJ
   4:     0x7f197d002e90 - rt::unwind::begin_unwind::h13556005847138426690
   5:     0x7f197d0dc3e0 - trans::common::unsized_part_of_type::h4971bfd82c960f177Sk
   6:     0x7f197d10c5e0 - trans::type_of::type_of::type_of_unsize_info::hc9a1771493b5585eB9o
   7:     0x7f197d05fd20 - trans::type_of::type_of::h45cc5a0ffa907939h9o
   8:     0x7f197d08ef50 - trans::base::alloc_ty::h23dd60deb6e81842ODt
   9:     0x7f197d1563c0 - trans::_match::mk_binding_alloca::h10681521704565058413
  10:     0x7f197d053f30 - trans::base::init_local::hca973ce50444bab8Cpt
  11:     0x7f197d054ea0 - trans::controlflow::trans_block::hfb3d01e31adc3da5Qee
  12:     0x7f197d120030 - trans::base::trans_closure::hd99a1fe118eadd85ofu
  13:     0x7f197d040670 - trans::base::trans_fn::hb1bc39659fd54f79Equ
  14:     0x7f197d03b6f0 - trans::base::trans_item::hf71bcbd6c9a9283ftPu
  15:     0x7f197d1275f0 - trans::base::trans_crate::h3465dd947f56ed22NMv
  16:     0x7f197e9e80e0 - driver::phase_4_translate_to_llvm::h130c1ed11c0c6b37wPa
  17:     0x7f197e9c1190 - driver::compile_input::ha0cf61571709f853Eba
  18:     0x7f197ea922b0 - run_compiler::h331ebfa0d68f5ee75bc
  19:     0x7f197ea90910 - thunk::F.Invoke<A, R>::invoke::h10527493330292840218
  20:     0x7f197ea8f800 - rt::unwind::try::try_fn::h13426443671359034537
  21:     0x7f197e444a70 - rust_try_inner
  22:     0x7f197e444a60 - rust_try
  23:     0x7f197ea8fab0 - thunk::F.Invoke<A, R>::invoke::h16144672682574185653
  24:     0x7f197e3c4050 - sys::thread::thread_start::h76415ad3898ce7eaaOE
  25:     0x7f19783c7250 - start_thread
  26:     0x7f197dfb8219 - clone
  27:                0x0 - <unknown>

@codyps
Copy link
Contributor

codyps commented Mar 9, 2015

I've seen this too with:

Reproducer:

fn main() {
        let _ : Box<Fn([u8])> = Box::new(|ref _a| {});
}

Version:

rustc 1.0.0-nightly (91bdf23f5 2015-03-09) (built 2015-03-09)

Backtrace:

error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'unsized_part_of_type failed even though ty is unsized', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/common.rs:168

stack backtrace:
   1:     0x7f79f57642f2 - sys::backtrace::write::hd861c9cad5664affQBA
   2:     0x7f79f578a342 - panicking::on_panic::h2d36a117ae395cb9jHJ
   3:     0x7f79f56d0a89 - rt::unwind::begin_unwind_inner::h020c424433824dc2mnJ
   4:     0x7f79f4decf8c - rt::unwind::begin_unwind::h13525811864842182597
   5:     0x7f79f4ea8a1b - trans::common::unsized_part_of_type::h58de00457dffddfcVxk
   6:     0x7f79f4e4f5b2 - trans::type_of::in_memory_type_of::hf3dc8a7490292449DHo
   7:     0x7f79f4ee8543 - trans::base::trans_closure::h70b835bf44b08f62ent
   8:     0x7f79f4e9fe2e - trans::closure::trans_closure_expr::he9af68f514bf9e21Gnx
   9:     0x7f79f4ecde63 - trans::consts::const_expr_unadjusted::hf36c0cdf480a0885ZTn
  10:     0x7f79f4ed1667 - trans::consts::const_expr::h29a9ed2c5e375d82tHn
  11:     0x7f79f4e6bcde - trans::consts::get_const_expr_as_global::hcd5ecd875acacf4bEEn
  12:     0x7f79f4e2ebfc - trans::expr::trans::h66ceb310b9edf1f9bwh
  13:     0x7f79f4e6086b - trans::callee::trans_args::hf2cfa069a4970bdbG3g
  14:     0x7f79f4e6624c - trans::callee::trans_call_inner::h17056753389190948462
  15:     0x7f79f4e6f077 - trans::expr::trans_rvalue_dps_unadjusted::hbd2cd1fd54de27cayCi
  16:     0x7f79f4e6d1bb - trans::expr::trans_unadjusted::h98b3a24d34abc9f436h
  17:     0x7f79f4e2f0e0 - trans::expr::trans::h66ceb310b9edf1f9bwh
  18:     0x7f79f4e2d625 - trans::expr::trans_to_lvalue::h8c97fd7e77062732c6h
  19:     0x7f79f4e2d18d - trans::base::init_local::h6b5a17c439dc15bfGBs
  20:     0x7f79f4e2e662 - trans::controlflow::trans_block::h47e6e8902755cf9cv7d
  21:     0x7f79f4ee9ed0 - trans::base::trans_closure::h70b835bf44b08f62ent
  22:     0x7f79f4e1df4b - trans::base::trans_fn::h88672d255f7695867xt
  23:     0x7f79f4e19ef6 - trans::base::trans_item::h1cf2dcffa3cf86bfZVt
  24:     0x7f79f4ef067c - trans::base::trans_crate::h88960ef764a955bcaSu
  25:     0x7f79f5d88f92 - driver::phase_4_translate_to_llvm::h5d3ca9bd44c7f33agOa
  26:     0x7f79f5d648ea - driver::compile_input::h124aae68147ae8b8Nba
  27:     0x7f79f5e2915d - run_compiler::hffd5283ae5d6d3abG6b
  28:     0x7f79f5e26ecc - thunk::F.Invoke<A, R>::invoke::h16438916220137010031
  29:     0x7f79f5e25b20 - rt::unwind::try::try_fn::h17325604874211535233
  30:     0x7f79f57f6118 - rust_try_inner
  31:     0x7f79f57f6105 - rust_try
  32:     0x7f79f5e262ab - thunk::F.Invoke<A, R>::invoke::h5807416775295653773
  33:     0x7f79f5777b45 - sys::thread::thread_start::h2188587ec04914c6t8E
  34:     0x7f79ef7e4373 - start_thread
  35:     0x7f79f535927c - __clone
  36:                0x0 - <unknown>

@Stebalien
Copy link
Contributor

fn main() {
        let _ : Box<Fn([u8])> = Box::new(|ref _a| {});
}

No longer reproduces but the other tests do.

@ftxqxd ftxqxd changed the title ICE: unsized_part_of_type failed even though ty is unsized ICE: Unexpected type returned from struct_tail May 15, 2015
@arielb1
Copy link
Contributor

arielb1 commented Jun 18, 2015

cc #25388

@comex
Copy link
Contributor

comex commented Jun 22, 2015

Is this the same as or related to #24957?

@AndiDog
Copy link
Contributor

AndiDog commented Sep 25, 2015

use std::path::Path;
use std::path::PathBuf;

pub enum Source
{
    File(Path), // compiler error :(
    // File(PathBuf), // works :)
}

pub fn source_to_dbtype(src: &Source) -> u8
{
    match src
    {
        &Source::File(..) => 1,
    }
}

leads to thread 'rustc' panicked at 'Unexpected type returned from struct_tail: Source for ty=Source', src/librustc_trans/trans/type_of.rs:385. As mentioned inline, using the correct type works (PathBuf).

I'm using the Ubuntu PPA "rust-nightly", version 201509240405f0666b4vivid.

@bltavares
Copy link
Contributor

fn main() {
    let x: &(Clone, Iterator) = panic!();
}

Does not compile for other reasons that the ICE anymore.

I've adjusted to the following and could not reproduce it anymore.

trait T {}

fn main() {
    let x: &(T, Iterator<Item = u32>) = panic!();
}

@dylanede
Copy link
Contributor

dylanede commented Nov 7, 2015

Another example hitting this same ICE:

use std::any::Any;

enum MyOption<T: ?Sized> {
    None,
    Some(T)
}

fn main() {
    let _: Box<MyOption<Any>> = panic!();
}

@apasel422
Copy link
Contributor

Bugs similar to this one have been reported numerous times (most of the references to this issue are duplicates). Although it would be nice for reporters to search for similar issues before filing a new one, it's hard to blame them, since the ICE message from rustc tells people to file an issue.

This issue itself was opened over two years ago. Separate from fixing the underlying problem, we should at least investigate displaying a real error instead of an ICE.

bors added a commit that referenced this issue Oct 25, 2016
Disallow Unsized Enums

Fixes #16812.

This PR is a potential fix for #16812, an issue which is reported [again](#36801) and [again](#36975), with over a dozen duplicates by now.

This PR is mainly meant to promoted discussion about the issue and the correct way to fix it.

This is a [breaking-change] since the error is now reported during wfchecking, so that even the definition of a (potentially) unsized enum will cause an error (whereas it would previously cause an ICE at trans time if the enum was used in an unsized manner).
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 31, 2024
fix: Goto implementation to impls inside blocks

Fixes rust-lang#3739
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

Successfully merging a pull request may close this issue.