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

rustc panics compiling async_trait with an associated type #65500

Closed
hirrolot opened this issue Oct 17, 2019 · 6 comments
Closed

rustc panics compiling async_trait with an associated type #65500

hirrolot opened this issue Oct 17, 2019 · 6 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-closures Area: Closures (`|…| { … }`) A-typesystem Area: The type system C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hirrolot
Copy link
Contributor

hirrolot commented Oct 17, 2019

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"
authors = ["Temirkhan Myrzamadi <gymmasssorla@gmail.com>"]
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/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-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)

@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-closures Area: Closures (`|…| { … }`) A-typesystem Area: The type system C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Oct 17, 2019
@hirrolot
Copy link
Contributor Author

Why E-needs-mcve?

@jonas-schievink
Copy link
Contributor

@Gymmasssorla Your code still depends on async_trait, which does rather heavy code generation. You might be able to minimize the example further by running cargo expand.

@hirrolot
Copy link
Contributor Author

hirrolot commented Oct 17, 2019

@jonas-schievink

I have executed cargo expand and fixed some compilation errors, but now the compiler doesn't panic at all. Is it a bug raised by async-trait?

trait MyTrait {
    type MyType;
    fn call_boxed<'life0, 'async_trait>(
        &'life0 self,
    ) -> ::core::pin::Pin<
        Box<
            dyn ::core::future::Future<Output = Self::MyType> + ::core::marker::Send + 'async_trait,
        >,
    >
    where
        'life0: 'async_trait,
        Self: 'async_trait;
}
struct MyStruct;
impl MyTrait for MyStruct {
    type MyType = i32;
    fn call_boxed<'life0, 'async_trait>(
        &'life0 self,
    ) -> ::core::pin::Pin<
        Box<
            dyn ::core::future::Future<Output = Self::MyType> + ::core::marker::Send + 'async_trait,
        >,
    >
    where
        'life0: 'async_trait,
        Self: 'async_trait,
    {
        #[allow(clippy::used_underscore_binding)]
        async fn __call_boxed(_self: &MyStruct) -> <MyStruct as MyTrait>::MyType {
            _self.call().await
        }
        Box::pin(__call_boxed(self))
    }
}
impl MyStruct {
    async fn call(&self) -> Self::Output {
        5
    }
}
fn main() {}

The playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f0658bacf89df3cd99dfa092c82ffd9a.

@bbigras
Copy link

bbigras commented Oct 17, 2019

I might have a minimal case:

rustc 1.40.0-nightly (e413dc3 2019-10-14)

[dependencies]
tiberius = "0.3.2"
use tiberius::transaction::Transaction;

async fn suivi_log(
    conn: Transaction<std::boxed::Box<dyn tiberius::BoxableIo>>,
) -> Transaction<std::boxed::Box<dyn tiberius::BoxableIo>> {
    conn
}

fn main() {}
error[E0603]: module `transaction` is private
 --> src/main.rs:1:15
  |
1 | use tiberius::transaction::Transaction;
  |               ^^^^^^^^^^^

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/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-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_item
  46: <rustc_typeck::collect::CollectItemTypesVisitor as rustc::hir::intravisit::Visitor>::visit_item
  47: rustc::hir::map::Map::visit_item_likes_in_module
  48: rustc_typeck::collect::collect_mod_item_types
  49: rustc::ty::query::__query_compute::collect_mod_item_types
  50: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_mod_item_types>::compute
  51: rustc::dep_graph::graph::DepGraph::with_task_impl
  52: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  53: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  54: rustc_typeck::check_crate::{{closure}}::{{closure}}
  55: rustc::util::common::time
  56: rustc_typeck::check_crate
  57: rustc_interface::passes::analysis
  58: rustc::ty::query::__query_compute::analysis
  59: rustc::dep_graph::graph::DepGraph::with_task_impl
  60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  61: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  62: rustc_interface::passes::create_global_ctxt::{{closure}}
  63: rustc_interface::passes::BoxedGlobalCtxt::enter
  64: rustc_interface::interface::run_compiler_in_existing_thread_pool
  65: std::thread::local::LocalKey<T>::with
  66: scoped_tls::ScopedKey<T>::set
  67: 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 (e413dc36a 2019-10-14) 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 `suivi_log`
#1 [typeck_tables_of] processing `suivi_log::{{closure}}#0`
#2 [type_of] processing `suivi_log::{{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 E0603`.
error: could not compile `rs-suivi`.

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

@estebank
Copy link
Contributor

estebank commented Oct 17, 2019

I can no longer reproduce this with a fresh master build and I believe this was fixed by https://github.com/rust-lang/rust/pull/65235/files#diff-35fad773654cfed45bea0a2abcbe12a6L691-L692

cc @nikomatsakis

@hirrolot
Copy link
Contributor Author

I am too, closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-closures Area: Closures (`|…| { … }`) A-typesystem Area: The type system C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants