Repository navigation
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Description
I've defined a trait CompletionQueue<'a>, which wraps various FFI *mut xxx pointers. All of these pointers can be freed by the same FFI function, so to reduce code duplication, I defined a pointer() method on my CompletionQueue<'a> trait, and tried to define a generic implementation of Drop that is basically unsafe { ff_drop_function(self.pointer()) }. This causes the compiler to panic...
Running `rustc --crate-name rdma_core src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=7b223b004c70695f -C extra-filename=-7b223b004c70695f --out-dir /Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps -L dependency=/Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps --extern rust_extra=/Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps/librust_extra-c243164c893672bb.rlib --extern errno=/Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps/liberrno-e26062265f10ba2f.rlib --extern syscall_alt=/Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps/libsyscall_alt-e072c8ee531427e2.rlib --extern libc=/Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps/liblibc-b057f0656f58b4ca.rlib --extern rdma_core_sys=/Volumes/Source/GitHub/lemonrock/rdma-core/.cargo/target/debug/deps/librdma_core_sys-9e84b480a6be2488.rlib`
error[E0119]: conflicting implementations of trait `std::ops::Drop` for type `std::boxed::Box<_>`:
--> src/CompletionQueue.rs:5:1
|
5 | / impl<'a, T: Sized + CompletionQueue<'a>> Drop for T
6 | | {
7 | | #[inline(always)]
8 | | fn drop(&mut self)
... |
11 | | }
12 | | }
| |_^
|
= note: conflicting implementation in crate `alloc`
error[E0120]: the Drop trait may only be implemented on structures
--> src/CompletionQueue.rs:5:51
|
5 | impl<'a, T: Sized + CompletionQueue<'a>> Drop for T
| ^ implementing Drop requires a struct
error: internal compiler error: src/librustc_typeck/check/dropck.rs:64: should have been rejected by coherence check: T
--> src/CompletionQueue.rs:5:1
|
5 | / impl<'a, T: Sized + CompletionQueue<'a>> Drop for T
6 | | {
7 | | #[inline(always)]
8 | | fn drop(&mut self)
... |
11 | | }
12 | | }
| |_^
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/librustc_errors/lib.rs:375
stack backtrace:
0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
1: std::panicking::default_hook::{{closure}}
2: std::panicking::default_hook
3: std::panicking::rust_panic_with_hook
4: std::panicking::begin_panic
5: rustc_errors::Handler::span_bug
6: rustc::session::opt_span_bug_fmt::{{closure}}
7: rustc::session::span_bug_fmt
8: rustc_typeck::check::dropck::check_drop_impl
9: core::ops::FnMut::call_mut
10: rustc::ty::util::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::calculate_dtor::{{closure}}
11: rustc::ty::util::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::calculate_dtor
12: rustc_typeck::check::adt_destructor
13: rustc::ty::maps::<impl rustc::ty::maps::queries::adt_destructor<'tcx>>::try_get
14: rustc::ty::util::<impl rustc::ty::ParameterEnvironment<'tcx>>::can_type_implement_copy
15: rustc_typeck::coherence::coherent_trait
16: rustc::ty::maps::<impl rustc::ty::maps::queries::coherent_trait<'tcx>>::try_get
17: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::coherent_trait
18: rustc_typeck::coherence::check_coherence
19: rustc_typeck::check_crate
20: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
21: rustc_driver::driver::phase_3_run_analysis_passes
22: rustc_driver::driver::compile_input
23: rustc_driver::run_compiler
24: std::panicking::try::do_call
25: __rust_maybe_catch_panic
26: <F as alloc::boxed::FnBox<A>>::call_box
27: std::sys::imp::thread::Thread::new::thread_start
28: _pthread_body
29: _pthread_startMetadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Activity
raphaelcohn commentedon May 13, 2017
Background: rust-nightly, version
rustc 1.19.0-nightly (777ee2079 2017-05-01), running on Mac OS X (Darwin Kernel Version 15.6.0) on a x86_64 bit Mac Pro cylinder. Native target.raphaelcohn commentedon May 13, 2017
Also present in
rustc 1.19.0-nightly (e17a1227a 2017-05-12)djzin commentedon May 13, 2017
Implementing
Drop(or any trait you do not control) generically in this way is not possible because it violates the coherence rules. (What if someone implementedCompletionQueueandDropseperately?) You probably want to wrap your types in a newtype with a forwarding implementation of theCompletionQueuetrait.With that said, the compiler probably shouldn't ICE on this!
raphaelcohn commentedon May 15, 2017
Thank you. I was trying to avoid writing and maintaining a lot of tedious, duplicated boilerplate...
Mark-Simulacrum commentedon Jun 22, 2017
Can you provide a code example (preferably minimal?)
raphaelcohn commentedon Jul 12, 2017
Nope; it was a long time ago.
tmccombs commentedon Nov 4, 2017
I encountered this same issue on rustc 1.21 (with a very similar use case).
Unfortunately, while I can reproduce it in my project, I can't come up with a minimal example that reproduces the ICE.
The full otuput look like
tmccombs commentedon Nov 4, 2017
Actually, I was able to get a minimal reproduction: https://play.rust-lang.org/?gist=3c42e05707afa39f805997dc2f2f4f08&version=undefined
sinkuu commentedon Nov 4, 2017
Further reduced (playground):
Rollup merge of rust-lang#47104 - matthewjasper:dont-panic-on-generic…