Skip to content

rustc panics compiling async_trait with an associated type #65500

Closed
@hirrolot

Description

@hirrolot

rustc panics if I define an associated type inside an #[async_trait] trait and implement it for a structure:

Inside src/main.rs:

#[macro_use]
extern crate async_trait;

#[async_trait]
trait MyTrait {
    type MyType;

    async fn call_boxed(&self) -> Self::MyType;
}

struct MyStruct;

#[async_trait]
impl MyTrait for MyStruct {
    type MyType = i32;

    async fn call_boxed(&self) -> Self::MyType {
        self.call().await
    }
}

impl MyStruct {
    async fn call(&self) -> Self::Output {
        5
    }
}

fn main() {}

Inside Cargo.toml:

[package]
name = "bug"
version = "0.1.0"
edition = "2018"

[dependencies]
async-trait = "0.1.15"

Meta


$ RUST_BACKTRACE=1 cargo check --verbose
       Fresh unicode-xid v0.2.0
       Fresh proc-macro2 v1.0.5
       Fresh quote v1.0.2
       Fresh syn v1.0.5
       Fresh async-trait v0.1.15
    Checking bug v0.1.0 (/home/gymmasssorla/bug)
     Running `rustc --edition=2018 --crate-name bug src/main.rs --color always --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=8e79409b6a7339ca -C extra-filename=-8e79409b6a7339ca --out-dir /home/gymmasssorla/bug/target/debug/deps -C incremental=/home/gymmasssorla/bug/target/debug/incremental -L dependency=/home/gymmasssorla/bug/target/debug/deps --extern async_trait=/home/gymmasssorla/bug/target/debug/deps/libasync_trait-447b246b76a3f45f.so`
error[E0223]: ambiguous associated type
  --> src/main.rs:23:29
   |
23 |     async fn call(&self) -> Self::Output {
   |                             ^^^^^^^^^^^^ help: use fully-qualified syntax: `<MyStruct as Trait>::Output`

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.colasdn.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.colasdn.top-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1028
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:189
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:206
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:473
  12: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:376
  13: rust_begin_unwind
             at src/libstd/panicking.rs:303
  14: core::panicking::panic_fmt
             at src/libcore/panicking.rs:84
  15: core::panicking::panic
             at src/libcore/panicking.rs:49
  16: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::supplied_sig_of_closure
  17: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
  18: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  19: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  20: rustc_typeck::check::FnCtxt::check_argument_types
  21: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  22: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  24: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  25: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  26: rustc_typeck::check::check_fn
  27: rustc::ty::context::GlobalCtxt::enter_local
  28: rustc_typeck::check::typeck_tables_of
  29: rustc::ty::query::__query_compute::typeck_tables_of
  30: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  33: rustc::ty::query::__query_compute::typeck_tables_of
  34: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  35: rustc::dep_graph::graph::DepGraph::with_task_impl
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  37: rustc_typeck::collect::checked_type_of
  38: rustc_typeck::collect::type_of
  39: rustc::ty::query::__query_compute::type_of
  40: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::type_of>::compute
  41: rustc::dep_graph::graph::DepGraph::with_task_impl
  42: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  43: rustc::hir::intravisit::walk_expr
  44: rustc::hir::intravisit::Visitor::visit_fn
  45: rustc::hir::intravisit::walk_impl_item
  46: rustc::hir::map::Map::visit_item_likes_in_module
  47: rustc_typeck::collect::collect_mod_item_types
  48: rustc::ty::query::__query_compute::collect_mod_item_types
  49: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_mod_item_types>::compute
  50: rustc::dep_graph::graph::DepGraph::with_task_impl
  51: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  52: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  53: rustc_typeck::check_crate::{{closure}}::{{closure}}
  54: rustc::util::common::time
  55: rustc_typeck::check_crate
  56: rustc_interface::passes::analysis
  57: rustc::ty::query::__query_compute::analysis
  58: rustc::dep_graph::graph::DepGraph::with_task_impl
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  60: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  61: rustc_interface::passes::create_global_ctxt::{{closure}}
  62: rustc_interface::passes::BoxedGlobalCtxt::enter
  63: rustc_interface::interface::run_compiler_in_existing_thread_pool
  64: std::thread::local::LocalKey<T>::with
  65: scoped_tls::ScopedKey<T>::set
  66: syntax::with_globals
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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.40.0-nightly (1721c9685 2019-10-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck_tables_of] processing `MyStruct::call`
#1 [typeck_tables_of] processing `MyStruct::call::{{closure}}#0`
#2 [type_of] processing `MyStruct::call::{{closure}}#0`
#3 [collect_mod_item_types] collecting item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

For more information about this error, try `rustc --explain E0223`.
error: could not compile `bug`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name bug src/main.rs --color always --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=8e79409b6a7339ca -C extra-filename=-8e79409b6a7339ca --out-dir /home/gymmasssorla/bug/target/debug/deps -C incremental=/home/gymmasssorla/bug/target/debug/incremental -L dependency=/home/gymmasssorla/bug/target/debug/deps --extern async_trait=/home/gymmasssorla/bug/target/debug/deps/libasync_trait-447b246b76a3f45f.so` (exit code: 101)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-closuresArea: Closures (`|…| { … }`)A-type-systemArea: Type systemC-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions