rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.18k stars 12.7k forks source link

Compiler panic on enum variants with trait objects #32765

Closed weiznich closed 8 years ago

weiznich commented 8 years ago

The compiler panics with certain combinations of enum variants with trait objects. See the minimal example below.

I tried this code:

use std::fmt::Debug;

#[derive(Debug)]
pub enum E {
    A(TraitChild),
}

pub trait TraitParent: Debug{}

pub trait TraitChild: TraitParent {}

I expected to see this happen: A error message or the compiler passing fine

Instead, this happened: The compiler paniced

Meta

$ cargo rustc -- --version --verbose
   Compiling compiler-bug v0.1.0 (file:///tmp/compiler-bug)
rustc 1.7.0 (a5d1e7a59 2016-02-29)
binary: rustc
commit-hash: a5d1e7a59a2a3413c377b003075349f854304b5e
commit-date: 2016-02-29
host: x86_64-unknown-linux-gnu
release: 1.7.0
$ cargo rustc -- --version --verbose
   Compiling compiler-bug v0.1.0 (file:///tmp/compiler-bug)
rustc 1.9.0-nightly (5ab11d72c 2016-04-02)
binary: rustc
commit-hash: 5ab11d72cab23f0cea63cbf7a88817ff2a45bab0
commit-date: 2016-04-02
host: x86_64-unknown-linux-gnu
release: 1.9.0-nightly

Backtrace: (build with stable release)

$ RUST_BACKTRACE=1 cargo build  
   Compiling compiler-bug v0.1.0 (file:///tmp/compiler-bug)
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
thread 'rustc' panicked at 'Unexpected type returned from struct_tail: E for ty=E', ../src/librustc_trans/trans/type_of.rs:391
stack backtrace:
   1:     0x7f320079dd50 - sys::backtrace::tracing::imp::write::hf7e21f48f7cb711bEju
   2:     0x7f32007a4bf5 - panicking::default_handler::_<closure>::closure.42502
   3:     0x7f32007a465e - panicking::default_handler::hac4d0be12e3129d2Gwy
   4:     0x7f320076d416 - sys_common::unwind::begin_unwind_inner::hf13a3e016c1e78e1bct
   5:     0x7f320076de18 - sys_common::unwind::begin_unwind_fmt::h878e9fd8b85e0857hbt
   6:     0x7f31fec7800d - trans::type_of::in_memory_type_of::h593071fa1c7a88b5IUR
   7:     0x7f31feca1827 - trans::type_of::arg_type_of::h3d363dab76b0535a6SR
   8:     0x7f31fed56b10 - trans::type_of::type_of_rust_fn::h5d71e0357c84d3abDER
   9:     0x7f31fec98a3c - trans::declare::declare_rust_fn::h52167f891835ed397yC
  10:     0x7f31fecc6cf5 - trans::base::register_fn::hffc4a9f6758ed15cGlk
  11:     0x7f31fecc8891 - trans::base::register_method::hef8bc997fd575557JLk
  12:     0x7f31fecc22e3 - trans::base::get_item_val::h0a9a752f98588e3d2xk
  13:     0x7f31fecc018d - trans::base::trans_item::h756f54b4e629ccb0Odk
  14:     0x7f31fecd9e4a - trans::base::TransItemsWithinModVisitor<'a, 'tcx>.Visitor<'v>::visit_item::h3b5bc0bcbe5b15a04dl
  15:     0x7f31feccb827 - trans::base::trans_crate::h226b7eed3e3bb400zXk
  16:     0x7f3200cd5df4 - driver::phase_4_translate_to_llvm::h876e6f0b6afd272d5Ta
  17:     0x7f3200ccbba6 - driver::phase_3_run_analysis_passes::_<closure>::closure.26772
  18:     0x7f3200cac45d - middle::ty::context::ctxt<'tcx>::create_and_enter::h11454974807351631650
  19:     0x7f3200ca7d52 - driver::phase_3_run_analysis_passes::h12040458575817631055
  20:     0x7f3200c788cb - driver::compile_input::h71d4e311662cb5e0nca
  21:     0x7f3200c69e2b - run_compiler::h002f3bf18be58fd27wc
  22:     0x7f3200c66c61 - sys_common::unwind::try::try_fn::h13318254547800529440
  23:     0x7f320079bb18 - __rust_try
  24:     0x7f320079332b - sys_common::unwind::try::inner_try::h7232ca0b9dac160cJ8s
  25:     0x7f3200c66fc0 - boxed::F.FnBox<A>::call_box::h7593089220679888244
  26:     0x7f32007a2dc3 - sys::thread::Thread::new::thread_start::h93f164b37c9b35e1Ctx
  27:     0x7f31f9d136f9 - start_thread
  28:     0x7f320041a2dc - clone
  29:                0x0 - <unknown>

Could not compile `compiler-bug`.

To learn more, run the command again with --verbose.
bluss commented 8 years ago

Thanks. It is also present in nightly, where the error message is

error: internal compiler error: ../src/librustc_trans/type_of.rs:134: Unexpected tail in unsized_info_ty: E for ty=E
jonhoo commented 8 years ago

Following on from #34182, this code also produces the error:

pub trait A {}

pub enum C {
    A(A),
}

fn main() {
    let _: Option<Box<C>> = None;
}
eightbitraptor commented 8 years ago

I've come here from https://github.com/rust-lang/rust/issues/34182

I think I have run into the same issue from the code in this commit: https://github.com/eightbitraptor/otaku/commit/0ef3e0d06f5c72e8a51de3861e6fa8f58e276061

Which I expected to compile without issue (I introduce a new enum that is not yet used anywhere)

I am using

active toolchain
----------------

stable-x86_64-apple-darwin (default)
rustc 1.9.0 (e4e8b6668 2016-05-18)

And the error I get is:

error: internal compiler error: ../src/librustc_trans/type_of.rs:166: Unexpected tail in unsized_info_ty: errors::AppError for ty=errors::AppError
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 'Box<Any>', ../src/libsyntax/errors/mod.rs:575
stack backtrace:
   1:        0x10c3a23a8 - std::sys::backtrace::tracing::imp::write::h4c73fcd3363076f5
   2:        0x10c3ae7f5 - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::h0422dbb3077e6747
   3:        0x10c3ae32f - std::panicking::default_hook::haac48fa641db8fa2
   4:        0x10c372f86 - std::sys_common::unwind::begin_unwind_inner::h39d40f52add53ef7
   5:        0x10b970aca - std::sys_common::unwind::begin_unwind::hb6dfe67d47a39536
   6:        0x10b9708f9 - syntax::errors::Handler::bug::hec53df68774c03a0
   7:        0x10acf63dc - rustc::session::opt_span_bug_fmt::_$u7b$$u7b$closure$u7d$$u7d$::hda87a029f26efa73
   8:        0x10acf6241 - rustc::session::opt_span_bug_fmt::h9fde00dba42c5dbe
   9:        0x10ad0cad9 - rustc::session::bug_fmt::h3174fdeee89ebd23
  10:        0x108952524 - rustc_trans::type_of::unsized_info_ty::h31cd36d2b8d5affd
  11:        0x10882d0d2 - rustc_trans::type_of::in_memory_type_of::h3452b62d9f897a08
  12:        0x10881fbc1 - rustc_trans::abi::FnType::unadjusted::_$u7b$$u7b$closure$u7d$$u7d$::h43c6b7965bb3af53
  13:        0x10881d426 - rustc_trans::abi::FnType::unadjusted::h6c7ddebd02b4cfc6
  14:        0x10882cbbf - rustc_trans::type_of::in_memory_type_of::h3452b62d9f897a08
  15:        0x10888eaa8 - rustc_trans::callee::get_fn::haaf760d478d95498
  16:        0x108838b27 - rustc_trans::callee::Callee::def::he88e0427a7068fef
  17:        0x1088667b4 - rustc_trans::base::trans_item::hf167e469e36b8935
  18:        0x10887e416 - _<base..TransItemsWithinModVisitor<'a, 'tcx> as rustc..hir..intravisit..Visitor<'v>>::visit_item::hfd0663a7c8d5f16c
  19:        0x10887c356 - rustc::hir::intravisit::walk_item::h511d7aa5180d79ae
  20:        0x10886ceae - rustc_trans::base::trans_crate::h62301dd3c79c73a7
  21:        0x107f0c73a - rustc_driver::driver::phase_4_translate_to_llvm::hd44e506f53bb81e3
  22:        0x107f0aeec - rustc_driver::driver::compile_input::_$u7b$$u7b$closure$u7d$$u7d$::h9811bece2a8f1da7
  23:        0x107f077dd - rustc_driver::driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::hc699330eb6f2bc1e
  24:        0x107f01392 - rustc::ty::context::TyCtxt::create_and_enter::h656b2d3a4956519e
  25:        0x107efdcdc - rustc_driver::driver::phase_3_run_analysis_passes::h83da042ec4b8ea10
  26:        0x107ed1571 - rustc_driver::driver::compile_input::h6491aaddd9e61258
  27:        0x107eb7d8f - rustc_driver::run_compiler::h80b2ba5e4d787c5f
  28:        0x107eb5122 - std::sys_common::unwind::try::try_fn::h34e27823ddd1d5e9
  29:        0x10c39fb3b - __rust_try
  30:        0x10c39fac3 - std::sys_common::unwind::inner_try::h9eebd8dc83f388a6
  31:        0x107eb59b9 - _<F as std..boxed..FnBox<A>>::call_box::h3d5d78986dfac5b2
  32:        0x10c3ad6c8 - std::sys::thread::Thread::new::thread_start::h471ad90789353b5b
  33:     0x7fff9350d99c - _pthread_body
  34:     0x7fff9350d919 - _pthread_start
apasel422 commented 8 years ago

This is essentially a duplicate of #16812.

apasel422 commented 8 years ago

Closing in favor of #16812.