Skip to content

Specialized Drop impl causes 'internal compiler error' #40132

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

Closed
Lazarus535 opened this issue Feb 27, 2017 · 3 comments
Closed

Specialized Drop impl causes 'internal compiler error' #40132

Lazarus535 opened this issue Feb 27, 2017 · 3 comments
Labels
A-specialization Area: Trait impl specialization I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Lazarus535
Copy link

Lazarus535 commented Feb 27, 2017

Possible duplicate of: #38868

Problem:

rustc crashes with 'internal compiler error' if a special file (see the 'Input' section) is compiled.

Exact error output (run via cargo run):

[me@my_machine rustc_bug_1]$ cargo run
   Compiling rustc_bug_1 v0.1.0 (file:///home/me/some_folder/rustc_bug_1)
error: internal compiler error: /checkout/src/librustc_typeck/check/dropck.rs:650: substs for an impl must map types to TyParam

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 'Box<Any>', /checkout/src/librustc_errors/lib.rs:417
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `rustc_bug_1`.

To learn more, run the command again with --verbose.

How to reproduce the error:

  1. Create a new (binary) project with cargo new rustc_bug_1 --bin

  2. Put the attached source inside main.rs

  3. Run the project with cargo run

  4. Witness the error ;-)

The error-causeing source:

struct A<T> {
  a: T,
}

fn main() {
    struct Z {}

    let x: A<Z> = A{ a: Z{} };

    struct DropStruct;

    impl Drop for A<DropStruct> {
      fn drop(&mut self) {
        println!("I'm dropping an A<DropStruct>!");
      }
    }
}

Explanation:

I tried some crazy stuff in Rust in order to better understand the languages' semantics when i encountered the bug. I know....usually you cannot specialize the Drop impl, or so the compiler keeps telling me if i further minimize the provided source.

Used OS and rust toolchain:

Arch x64 (up2date)
Rust Toolchains:

stable-x86_64-unknown-linux-gnu
beta-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu

Tested with all three.

@TimNN TimNN added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 27, 2017
@arielb1
Copy link
Contributor

arielb1 commented Feb 27, 2017

cc @pnkfelix

@TimNN TimNN added the A-specialization Area: Trait impl specialization label Feb 27, 2017
@TimNN
Copy link
Contributor

TimNN commented Feb 27, 2017

Drop implementations cannot be specialised, and an error to that regard is (in theory) reported. The let statement however causes the ICE before that error can be reported.

Slightly minified / cleaned up code:

struct A<T> {
    a: T,
}

struct DropStruct;

impl Drop for A<DropStruct> {
    fn drop(&mut self) {}
}

fn main() {
    // Comment the next line to get the real error
    let _ = A { a: 0 };
}

Backtrace:

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:417
stack backtrace:
   1:     0x7fb011745f29 - std::sys::imp::backtrace::tracing::imp::write::hbb14611794d3841b
                        at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7fb0117545c9 - std::panicking::default_hook::{{closure}}::h6ed906c7818ac88c
                        at /checkout/src/libstd/panicking.rs:351
   3:     0x7fb011754166 - std::panicking::default_hook::h23eeafbf7c1c05c3
                        at /checkout/src/libstd/panicking.rs:361
   4:     0x7fb011754a2b - std::panicking::rust_panic_with_hook::hd0067971b6d1240e
                        at /checkout/src/libstd/panicking.rs:545
   5:     0x7fb009d54d27 - std::panicking::begin_panic::hc300cc1c3c24c382
   6:     0x7fb009d6a27d - rustc_errors::Handler::bug::h86684df8c5f40d57
   7:     0x7fb00e86c45a - rustc::session::opt_span_bug_fmt::{{closure}}::h3ad09996f9e31eb1
   8:     0x7fb00e86c267 - rustc::session::opt_span_bug_fmt::h4b0bb8c3e1670f11
   9:     0x7fb00e86bec2 - rustc::session::bug_fmt::h2dbe8dc3b71c81a2
  10:     0x7fb00eeaeaaa - rustc_typeck::check::dropck::revise_self_ty::{{closure}}::h8443f32a5645dfbf
  11:     0x7fb00ee7642a - rustc::ty::subst::<impl rustc::ty::Slice<rustc::ty::subst::Kind<'tcx>>>::fill_item::he6f2b1605174404e
  12:     0x7fb00eeae031 - rustc_typeck::check::dropck::iterate_over_potentially_unsafe_regions_in_type::h8efc493a06003174
  13:     0x7fb00eead4ec - rustc_typeck::check::dropck::check_safety_of_destructor_if_necessary::hfedb806f05d4f478
  14:     0x7fb00eec404a - rustc_typeck::check::regionck::RegionCtxt::check_safety_of_rvalue_destructor_if_necessary::h173d44d06b412e45
  15:     0x7fb00eec294d - <rustc_typeck::check::regionck::RegionCtxt<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr::h230f54fb51bf130b
  16:     0x7fb00eec1d27 - <rustc_typeck::check::regionck::RegionCtxt<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_local::h09384b04d000dbf1
  17:     0x7fb00ee810c5 - rustc::hir::intravisit::walk_expr::h8b16d458f89904f3
  18:     0x7fb00eec35fc - <rustc_typeck::check::regionck::RegionCtxt<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr::h230f54fb51bf130b
  19:     0x7fb00eec10da - rustc_typeck::check::regionck::RegionCtxt::visit_fn_body::hcd276f56b41f29b7
  20:     0x7fb00eec0847 - rustc_typeck::check::regionck::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::regionck_fn::h6101a1bf9ef6ab14
  21:     0x7fb00ef11b92 - rustc_typeck::check::check_bare_fn::hb24e70a67e127683
  22:     0x7fb00ef0eec5 - rustc_typeck::check::check_item_bodies::h0cab204d56268561
  23:     0x7fb00ef7b627 - rustc_typeck::check_crate::h441df7c8151905be
  24:     0x7fb011af24e4 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h7d2a6da150c7eba7
  25:     0x7fb011a60a14 - rustc::ty::context::TyCtxt::create_and_enter::h825fbad7d24d1480
  26:     0x7fb011ad5e13 - rustc_driver::driver::compile_input::hf3e3aa4173908b86
  27:     0x7fb011b1d3dd - rustc_driver::run_compiler::h8f8d47f1d258a8a6
  28:     0x7fb011a277db - std::panicking::try::do_call::h206b9daee04f4ea2
  29:     0x7fb01175d8da - __rust_maybe_catch_panic
                        at /checkout/src/libpanic_unwind/lib.rs:98
  30:     0x7fb011a4fb92 - <F as alloc::boxed::FnBox<A>>::call_box::h5d196fbb3229f499
  31:     0x7fb011753404 - std::sys::imp::thread::Thread::new::thread_start::h2c901daa88f3cb32
                        at /checkout/src/liballoc/boxed.rs:648
                        at /checkout/src/libstd/sys_common/thread.rs:21
                        at /checkout/src/libstd/sys/unix/thread.rs:84
  32:     0x7fb0094ff6b9 - start_thread
  33:     0x7fb01140682c - clone
  34:                0x0 - <unknown>

@malbarbo
Copy link
Contributor

malbarbo commented Mar 1, 2017

Another example

#[derive(Default)]
pub struct S<A>(pub A);

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

Removing derive avoids the ICE

arielb1 added a commit to arielb1/rust that referenced this issue Mar 1, 2017
This removes the Cell from AdtDef. Also, moving destructor validity
checking to on-demand (forced during item-type checking) ensures that
invalid destructors can't cause ICEs.

Fixes rust-lang#38868.
Fixes rust-lang#40132.
bors added a commit that referenced this issue Mar 3, 2017
convert AdtDef::destructor to on-demand

This removes the `Cell` from `AdtDef`. Also, moving destructor validity
checking to on-demand (forced during item-type checking) ensures that
invalid destructors can't cause ICEs.

Fixes #38868.
Fixes #40132.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants