Closed
Description
Code
#![feature(associated_type_bounds)]
use std::convert::Infallible;
pub trait SuperTrait {
type Error;
fn do_thing(&self, data: &[u8]) -> Result<(), Self::Error>;
}
pub trait Trait:
SuperTrait<Error: std::error::Error + Send + Sync + 'static>
+ Send
+ Sync
+ 'static
{
fn do_extended_thing(&self) -> Result<(), Self::Error> {
Ok(())
}
}
impl<T> Trait for T
where
T: SuperTrait + Send + Sync + Clone + 'static,
<T as SuperTrait>::Error: std::error::Error + Send + Sync + 'static,
{
}
#[derive(Clone)]
pub struct SomeTrait<S> {
pub member: S,
}
pub struct BoxedTrait {
pub the_trait: Box<dyn Trait<Error = BoxedError>>,
}
pub struct BoxedError {
error: Box<dyn std::error::Error + Send + Sync + 'static>,
}
impl std::fmt::Debug for BoxedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self.error)
}
}
impl std::fmt::Display for BoxedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.error)
}
}
impl std::error::Error for BoxedError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(self)
}
fn cause(&self) -> Option<&dyn std::error::Error> {
Some(self)
}
}
impl BoxedTrait {
pub fn new<S>(s: S) -> Self
where
S: Trait<Error = BoxedError>,
{
BoxedTrait {
the_trait: Box::new(s),
}
}
}
impl<S> From<SomeTrait<S>> for BoxedTrait
where
S: SuperTrait + Clone + Send + Sync + 'static,
S::Error: std::error::Error + Send + Sync + 'static,
{
fn from(other: SomeTrait<S>) -> Self {
// Compilation succeeds if you replace this line with an `unimplemented!()`
BoxedTrait::new(other)
}
}
impl<S> SuperTrait for SomeTrait<S>
where
S: SuperTrait + Clone + Send + Sync + 'static,
S::Error: std::error::Error + Send + Sync + 'static,
{
type Error = BoxedError;
fn do_thing(&self, _data: &[u8]) -> Result<(), Self::Error> {
Ok(())
}
}
#[derive(Clone)]
struct Concrete {}
impl SuperTrait for Concrete {
type Error = Infallible;
fn do_thing(&self, _data: &[u8]) -> Result<(), Self::Error> {
Ok(())
}
}
impl From<Concrete> for BoxedTrait {
fn from(c: Concrete) -> Self {
Self::from(SomeTrait { member: c })
}
}
Meta
rustc --version --verbose
:
rustc 1.58.0-nightly (4961b107f 2021-11-04)
binary: rustc
commit-hash: 4961b107f204e15b26961eab0685df6be3ab03c6
commit-date: 2021-11-04
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
Error output
thread 'rustc' panicked at 'resolution failed during building vtable representation', compiler/rustc_trait_selection/src/traits/mod.rs:716:22
stack backtrace:
0: rust_begin_unwind
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/panicking.rs:498:5
1: core::panicking::panic_fmt
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/core/src/panicking.rs:106:14
2: core::panicking::panic_display
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/core/src/panicking.rs:62:5
3: core::option::expect_failed
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/core/src/option.rs:1637:5
4: <core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_span::def_id::DefId>> as core::iter::traits::iterator::Iterator>::fold::<(), core::iter::adapters::map::map_fold<rustc_span::def_id::DefId, rustc_middle::ty::vtable::VtblEntry, (), rustc_trait_selection::traits::vtable_entries::{closure#0}::{closure#1}, core::iter::traits::iterator::Iterator::for_each::call<rustc_middle::ty::vtable::VtblEntry, <alloc::vec::Vec<rustc_middle::ty::vtable::VtblEntry> as alloc::vec::spec_extend::SpecExtend<rustc_middle::ty::vtable::VtblEntry, core::iter::adapters::map::Map<core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_span::def_id::DefId>>, rustc_trait_selection::traits::vtable_entries::{closure#0}::{closure#1}>>>::spec_extend::{closure#0}>::{closure#0}>::{closure#0}>
5: rustc_trait_selection::traits::vtable_entries::{closure#0}
6: rustc_trait_selection::traits::vtable_entries
7: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>, &[rustc_middle::ty::vtable::VtblEntry]>
8: rustc_data_structures::stack::ensure_sufficient_stack::<(&[rustc_middle::ty::vtable::VtblEntry], rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::TraitRef>, &[rustc_middle::ty::vtable::VtblEntry]>::{closure#3}>
9: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::vtable_entries, rustc_query_impl::plumbing::QueryCtxt>
10: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::vtable_entries
11: rustc_middle::ty::vtable::vtable_allocation_provider
12: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (&rustc_middle::ty::TyS, core::option::Option<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>>), rustc_middle::mir::interpret::AllocId>
13: rustc_data_structures::stack::ensure_sufficient_stack::<(rustc_middle::mir::interpret::AllocId, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (&rustc_middle::ty::TyS, core::option::Option<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>>), rustc_middle::mir::interpret::AllocId>::{closure#3}>
14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(&rustc_middle::ty::TyS, core::option::Option<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>>), rustc_middle::mir::interpret::AllocId>>
15: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::vtable_allocation, rustc_query_impl::plumbing::QueryCtxt>
16: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::vtable_allocation
17: rustc_middle::ty::vtable::vtable_allocation_provider
18: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (&rustc_middle::ty::TyS, core::option::Option<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>>), rustc_middle::mir::interpret::AllocId>
19: rustc_data_structures::stack::ensure_sufficient_stack::<(rustc_middle::mir::interpret::AllocId, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (&rustc_middle::ty::TyS, core::option::Option<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>>), rustc_middle::mir::interpret::AllocId>::{closure#3}>
20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(&rustc_middle::ty::TyS, core::option::Option<rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>>), rustc_middle::mir::interpret::AllocId>>
21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::vtable_allocation, rustc_query_impl::plumbing::QueryCtxt>
22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::vtable_allocation
23: rustc_codegen_ssa::meth::get_vtable::<rustc_codegen_llvm::context::CodegenCx>
24: rustc_codegen_ssa::base::unsize_ptr::<rustc_codegen_llvm::builder::Builder>
25: rustc_codegen_ssa::base::unsize_ptr::<rustc_codegen_llvm::builder::Builder>
26: rustc_codegen_ssa::base::unsize_ptr::<rustc_codegen_llvm::builder::Builder>
27: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::Builder>>::codegen_rvalue_operand
28: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
29: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
30: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::symbol::Symbol, rustc_codegen_ssa::ModuleCodegen<rustc_codegen_llvm::ModuleLlvm>>
31: rustc_codegen_llvm::base::compile_codegen_unit
32: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
33: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
34: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
35: <rustc_interface::passes::QueryContext>::enter::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core::result::Result<alloc::boxed::Box<dyn core::any::Any>, rustc_errors::ErrorReported>>
36: <rustc_interface::queries::Queries>::ongoing_codegen
37: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
38: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}>
39: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.58.0-nightly (4961b107f 2021-11-04) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C linker=/usr/bin/clang -C incremental -C link-arg=-fuse-ld=lld --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [vtable_entries] finding all vtable entries for trait core::fmt::Debug
#1 [vtable_allocation] vtable const allocation for <SomeTrait<Concrete> as core::fmt::Debug>
#2 [vtable_allocation] vtable const allocation for <SomeTrait<Concrete> as Trait>
end of query stack
error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<SomeTrait<Concrete> as std::fmt::Debug>, [])` during codegen
|
= note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:68:32
thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1166:13
stack backtrace:
0: 0x7f79394be80c - std::backtrace_rs::backtrace::libunwind::trace::h793e05efd273d0f4
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7f79394be80c - std::backtrace_rs::backtrace::trace_unsynchronized::h640b7b86ff610c77
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f79394be80c - std::sys_common::backtrace::_print_fmt::h362fa2a4f354f877
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/sys_common/backtrace.rs:67:5
3: 0x7f79394be80c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf439e5ed84c74abd
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/sys_common/backtrace.rs:46:22
4: 0x7f793951ba4c - core::fmt::write::h72801a82c94e6ff1
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/core/src/fmt/mod.rs:1149:17
5: 0x7f79394af035 - std::io::Write::write_fmt::h5562a8b6da0f0339
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/io/mod.rs:1697:15
6: 0x7f79394c1a60 - std::sys_common::backtrace::_print::hb29ddd998d02631c
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/sys_common/backtrace.rs:49:5
7: 0x7f79394c1a60 - std::sys_common::backtrace::print::h81965e3d7c90fbb6
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/sys_common/backtrace.rs:36:9
8: 0x7f79394c1a60 - std::panicking::default_hook::{{closure}}::h84db205ab6674b38
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/panicking.rs:211:50
9: 0x7f79394c160b - std::panicking::default_hook::h1bf8bb4159936bca
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/panicking.rs:228:9
10: 0x7f7939c56491 - rustc_driver[e620c7401644acc4]::DEFAULT_HOOK::{closure#0}::{closure#0}
11: 0x7f79394c2279 - std::panicking::rust_panic_with_hook::hf8e86850fbbd03b1
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/panicking.rs:610:17
12: 0x7f79394c1d30 - std::panicking::begin_panic_handler::{{closure}}::h590a0d6060ff866e
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/panicking.rs:502:13
13: 0x7f79394becc4 - std::sys_common::backtrace::__rust_end_short_backtrace::h260b8bd1c848a03c
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/sys_common/backtrace.rs:139:18
14: 0x7f79394c1c99 - rust_begin_unwind
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/panicking.rs:498:5
15: 0x7f79394871a1 - core::panicking::panic_fmt::h7b8580d81fcbbacd
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/core/src/panicking.rs:106:14
16: 0x7f793ad527bc - core[cc79c391059f8e46]::panicking::panic_display::<&str>
17: 0x7f793c3f3446 - <rustc_errors[c8a333c965fedc03]::HandlerInner>::flush_delayed
18: 0x7f793c3f1b5d - <rustc_errors[c8a333c965fedc03]::HandlerInner as core[cc79c391059f8e46]::ops::drop::Drop>::drop
19: 0x7f793bace5c6 - core[cc79c391059f8e46]::ptr::drop_in_place::<rustc_session[cec017cef00f19c9]::parse::ParseSess>
20: 0x7f793bad043a - <alloc[9a4bc13598ff604f]::rc::Rc<rustc_session[cec017cef00f19c9]::session::Session> as core[cc79c391059f8e46]::ops::drop::Drop>::drop
21: 0x7f793baac43d - core[cc79c391059f8e46]::ptr::drop_in_place::<rustc_interface[f89f8228a4e35bc7]::interface::Compiler>
22: 0x7f793baac3a5 - rustc_span[2d5555579096f1fe]::with_source_map::<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_interface[f89f8228a4e35bc7]::interface::create_compiler_and_run<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}>
23: 0x7f793babc810 - <scoped_tls[3fea4c3dcac147b1]::ScopedKey<rustc_span[2d5555579096f1fe]::SessionGlobals>>::set::<rustc_interface[f89f8228a4e35bc7]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[f89f8228a4e35bc7]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#0}::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>
24: 0x7f793baae795 - std[a5529df289459975]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f89f8228a4e35bc7]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[f89f8228a4e35bc7]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>
25: 0x7f793baaa902 - <<std[a5529df289459975]::thread::Builder>::spawn_unchecked<rustc_interface[f89f8228a4e35bc7]::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface[f89f8228a4e35bc7]::interface::run_compiler<core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>, rustc_driver[e620c7401644acc4]::run_compiler::{closure#1}>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#0}, core[cc79c391059f8e46]::result::Result<(), rustc_errors[c8a333c965fedc03]::ErrorReported>>::{closure#1} as core[cc79c391059f8e46]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
26: 0x7f79394cd563 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h771719d52c343434
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/alloc/src/boxed.rs:1691:9
27: 0x7f79394cd563 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf441746dfa4b0f57
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/alloc/src/boxed.rs:1691:9
28: 0x7f79394cd563 - std::sys::unix::thread::Thread::new::thread_start::hfd168f9d312b29ca
at /rustc/4961b107f204e15b26961eab0685df6be3ab03c6/library/std/src/sys/unix/thread.rs:106:17
29: 0x7f79393d4259 - start_thread
30: 0x7f79392e95e3 - __GI___clone
31: 0x0 - <unknown>
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.58.0-nightly (4961b107f 2021-11-04) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C linker=/usr/bin/clang -C incremental -C link-arg=-fuse-ld=lld --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
thread panicked while panicking. aborting.
error: could not compile `compiler-error`
Caused by:
process didn't exit successfully: `rustc --crate-name compiler_error --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=a7940e4ff600f0e3 -C extra-filename=-a7940e4ff600f0e3 --out-dir /home/alex/Projects/rust/compiler-error/target/debug/deps -C linker=/usr/bin/clang -C incremental=/home/alex/Projects/rust/compiler-error/target/debug/incremental -L dependency=/home/alex/Projects/rust/compiler-error/target/debug/deps --extern async_trait=/home/alex/Projects/rust/compiler-error/target/debug/deps/libasync_trait-4d187e561976744c.so -Clink-arg=-fuse-ld=lld` (signal: 4, SIGILL: illegal instruction)
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.