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 when implementing Drop for a struct with a lifetime, without #[unsafe_destructor]. #15090

Closed
sebcrozet opened this issue Jun 22, 2014 · 1 comment

Comments

@sebcrozet
Copy link
Contributor

The following compiles:

#![feature(unsafe_destructor)]

struct A;

struct B<'a> {
    a: &'a mut A
}

#[unsafe_destructor]
impl<'a> Drop for B<'a> {
    fn drop(&mut self) {
    }
}

fn main() {
} 

Removing the unsafe_destructor gives an ICE:

struct A;

struct B<'a> {
    a: &'a mut A
}

impl<'a> Drop for B<'a> {
    fn drop(&mut self) {
    }
}

fn main() {
}
error: internal compiler error: unexpected failure
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 'index out of bounds: the len is 0 but the index is 0', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/librustc/lib.rs:1

stack backtrace:
   1:     0x7fe7c0b40710 - rt::backtrace::imp::write::h70be4bfca778d3deKGp::v0.11.0.pre
   2:     0x7fe7c0b47e40 - failure::on_fail::h04d04700f5348da7Z1p::v0.11.0.pre
   3:     0x7fe7c2c79940 - unwind::begin_unwind_inner::h97af3d04f923ce77QRd::v0.11.0.pre
   4:     0x7fe7c2c793d0 - unwind::begin_unwind_fmt::he34766b08c9c3bffjPd::v0.11.0.pre
   5:     0x7fe7c2c79390 - rust_begin_unwind
   6:     0x7fe7c2cc2120 - failure::begin_unwind::he173e4b304989dc8k2v::v0.11.0.pre
   7:     0x7fe7c2cc5f10 - failure::fail_bounds_check::h5d25220010d9234cw0v::v0.11.0.pre
   8:     0x7fe7c35cd370 - middle::subst::SubstFolder<'a>.TypeFolder::fold_region::h87f3a88e034f0808awU::v0.11.0.pre
   9:     0x7fe7c3573d00 - middle::subst::SubstFolder<'a>.TypeFolder::fold_ty::hfe8a92cc8f6786e4JwU::v0.11.0.pre
  10:     0x7fe7c3573c10 - middle::subst::T.Subst::subst_spanned::h7311720506834529690::v0.11.0.pre
  11:     0x7fe7c36fb0b0 - middle::ty::lookup_field_type::hddf6e164c6d23ce9XbS::v0.11.0.pre
  12:     0x7fe7c35b3cc0 - middle::ty::struct_fields::hc733bb5e62aec902ekS::v0.11.0.pre
  13:     0x7fe7c372ab20 - middle::ty::type_contents::tc_ty::hb4fb865b8c9b3a21YrP::v0.11.0.pre
  14:     0x7fe7c36c1b70 - middle::ty::type_contents::ha9a882bed7271f1dUqP::v0.11.0.pre
  15:     0x7fe7c3ac5160 - middle::kind::check_item::h32f6a93801c8fc8cN5V::v0.11.0.pre
  16:     0x7fe7c3ac8050 - middle::kind::check_crate::h633ef117cb58f864cWV::v0.11.0.pre
  17:     0x7fe7c3ebbcb0 - driver::driver::phase_3_run_analysis_passes::hc133de981f2c567e91v::v0.11.0.pre
  18:     0x7fe7c3eb4210 - driver::driver::compile_input::hf9ab49f375606457oQv::v0.11.0.pre
  19:     0x7fe7c3f82e30 - driver::run_compiler::h943691fce94537a0jAy::v0.11.0.pre
  20:     0x7fe7c3f82d40 - driver::main_args::closure.99055
  21:     0x7fe7c3f98790 - task::TaskBuilder<S>::try_future::closure.100185
  22:     0x7fe7c3f983b0 - task::TaskBuilder<S>::spawn_internal::closure.100162
  23:     0x7fe7c2fd5880 - task::spawn_opts::closure.7220
  24:     0x7fe7c2c76510 - task::Task::run::closure.5243
  25:     0x7fe7c2cdb9a0 - rust_try
  26:     0x7fe7c2c78f60 - unwind::try::h0c05741f8b8835e1fGd::v0.11.0.pre
  27:     0x7fe7c2c76390 - task::Task::run::h88fa45777ee68cfeVVc::v0.11.0.pre
  28:     0x7fe7c2fd5620 - task::spawn_opts::closure.7185
  29:     0x7fe7c2c78520 - thread::thread_start::hd6e04bc6ce5c8296kdd::v0.11.0.pre
  30:     0x7fe7c05b2fe0 - start_thread
  31:     0x7fe7c2942ce9 - clone
  32:                0x0 - <unknown>

Note that ommiting the unsafe_destructor and not storing the pointer to A does compile too:

struct A;

struct B<'a>;

impl<'a> Drop for B<'a> {
    fn drop(&mut self) {
    }
}

fn main() {
}
@alexcrichton
Copy link
Member

Closing as a dupe of #14889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants