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

Compiler error on #[async_trait] when async-trait is not in Cargo.toml #76753

Closed
scull7 opened this issue Sep 15, 2020 · 5 comments
Closed

Compiler error on #[async_trait] when async-trait is not in Cargo.toml #76753

scull7 opened this issue Sep 15, 2020 · 5 comments
Labels
C-bug Category: This is a bug. 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

@scull7
Copy link

scull7 commented Sep 15, 2020

I tried this code:

#[async_trait]
pub trait Thing {
    type Item;
    
    fn not_async(&self) -> String

    async fn get_thing(&self) -> anyhow::Result<Self::Item>;
}

I expected to see this happen:

I would expect the compiler to complain about the missing crate

Instead, this happened:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/d3fb005a39e62501b8b0b356166e515ae24e2e54/src/librustc_hir/definitions.rs:358:9
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.45.2 (d3fb005a3 2020-07-31) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C linker=clang --crate-type lib

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

Meta

rustc --version --verbose:

rustc 1.45.2 (d3fb005a3 2020-07-31)
binary: rustc
commit-hash: d3fb005a39e62501b8b0b356166e515ae24e2e54
commit-date: 2020-07-31
host: x86_64-apple-darwin
release: 1.45.2
LLVM version: 10.0
<version>
Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', /rustc/d3fb005a39e62501b8b0b356166e515ae24e2e54/src/librustc_hir/definitions.rs:358:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: rustc_middle::hir::map::Map::def_kind
  11: core::ops::function::FnOnce::call_once
  12: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  13: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  14: rustc_data_structures::stack::ensure_sufficient_stack
  15: rustc_query_system::query::plumbing::get_query_impl
  16: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::closure_base_def_id
  17: rustc_typeck::collect::generics_of
  18: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::generics_of>::compute
  19: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_query_system::query::plumbing::ensure_query_impl
  23: rustc_hir::intravisit::walk_expr
  24: rustc_hir::intravisit::walk_expr
  25: rustc_hir::intravisit::walk_body
  26: rustc_hir::intravisit::walk_trait_item
  27: <rustc_typeck::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_trait_item
  28: rustc_middle::hir::map::Map::visit_item_likes_in_module
  29: rustc_typeck::collect::collect_mod_item_types
  30: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_mod_item_types>::compute
  31: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_query_system::query::plumbing::get_query_impl
  34: rustc_query_system::query::plumbing::ensure_query_impl
  35: rustc_typeck::check_crate
  36: rustc_interface::passes::analysis
  37: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  38: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  40: rustc_query_system::query::plumbing::get_query_impl
  41: rustc_middle::ty::context::tls::enter_global
  42: rustc_interface::interface::run_compiler_in_existing_thread_pool
  43: rustc_ast::attr::with_globals
<backtrace>

@scull7 scull7 added the C-bug Category: This is a bug. label Sep 15, 2020
@jonas-schievink
Copy link
Contributor

Please try this on the newest nightly

@scull7
Copy link
Author

scull7 commented Sep 15, 2020

I attempted to compile on nightly using with cargo +nightly build, received the following error:

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_middle/src/hir/map/mod.rs:178:30
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.48.0-nightly (9b4154193 2020-09-14) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C linker=clang --crate-type lib

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

@jyn514 jyn514 added 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. labels Sep 15, 2020
@jyn514
Copy link
Member

jyn514 commented Sep 15, 2020

Possibly related to #71104.

@fanninpm
Copy link

Playground link, for reference.

Have you tried it with the latest nightly this time around? I can't get it to ICE with rustc 1.48.0-nightly (fb1dc34a8 2020-09-21) (on both Mac and the playground).

@Dylan-DPC
Copy link
Member

This no longer ICEs and the current output is:

error: cannot find attribute `async_trait` in this scope
 --> src/lib.rs:1:3
  |
1 | #[async_trait]
  |   ^^^^^^^^^^^
  |
  = help: consider importing this attribute macro:
          async_trait::async_trait
  = note: `async_trait` is in scope, but it is a crate, not an attribute

error[[E0706]](https://doc.rust-lang.org/nightly/error_codes/E0706.html): functions in traits cannot be declared `async`
 --> src/lib.rs:7:5
  |
7 |     async fn get_thing(&self) -> anyhow::Result<Self::Item>;
  |     -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |     |
  |     `async` because of this
  |
  = note: `async` trait functions are not currently supported
  = note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
  = note: [see issue #91611 <https://github.com/rust-lang/rust/issues/91611>](https://github.com/rust-lang/rust/issues/91611) for more information
  = help: [add `#![feature(async_fn_in_trait)]`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c4034bf4f00df0a1b23a57ad19bbd30e#) to the crate attributes to enable

For more information about this error, try `rustc --explain E0706`.
error: could not compile `playground` (lib) due to 2 previous errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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

5 participants