Skip to content

Returning Result<T, Box<dyn std::error::Error>> from asynchronous task causes panic in the compiler #73029

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

Closed
aodhneine opened this issue Jun 5, 2020 · 2 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

@aodhneine
Copy link

Code

# Cargo.toml
[package]
name = "issue_test_return_async_std"
version = "0.1.0"
authors = ["aodhneine <aodhneine@protonmail.ch>"]
edition = "2018"

# See more keys and their definitions at
# https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies.tokio]
version = "0.2.21"
features = ["full"]
/* src/main.rs */
type NewResult<T> = Result<T, Box<dyn std::error::Error>>;

#[tokio::main]
async fn main() -> NewResult<()> {
    let handle = tokio::spawn(async move {
	return NewResult::<i32>::Ok(1);
    });
    handle.await?;

    return Ok(());
}

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (f93bb2a50 2020-05-25)
binary: rustc
commit-hash: f93bb2a50b37bc8bafe4d960e2afd839eaa854ed
commit-date: 2020-05-25
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 10.0

Error output

:: cargo build -j16 --verbose
       Fresh unicode-xid v0.2.0
       Fresh cfg-if v0.1.10
       Fresh slab v0.4.2
       Fresh arc-swap v0.4.6
       Fresh lazy_static v1.4.0
       Fresh fnv v1.0.7
       Fresh pin-project-lite v0.1.7
       Fresh bytes v0.5.4
       Fresh futures-core v0.3.5
       Fresh libc v0.2.71
       Fresh proc-macro2 v1.0.18
       Fresh log v0.4.8
       Fresh iovec v0.1.4
       Fresh net2 v0.2.34
       Fresh quote v1.0.6
       Fresh signal-hook-registry v1.2.0
       Fresh num_cpus v1.13.0
       Fresh memchr v2.3.3
       Fresh mio v0.6.22
       Fresh syn v1.0.30
       Fresh mio-uds v0.6.8
       Fresh tokio-macros v0.2.5
       Fresh tokio v0.2.21
   Compiling issue_test_return_async_std v0.1.0 (/home/julia/tmp/issue_test_return_async_std)
     Running `rustc --crate-name issue_test_return_async_std --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -Cembed-bitcode=no -C debuginfo=2 -C metadata=d603f945a98e8f13 -C extra-filename=-d603f945a98e8f13 --out-dir /home/julia/tmp/issue_test_return_async_std/target/debug/deps -C incremental=/home/julia/tmp/issue_test_return_async_std/target/debug/incremental -L dependency=/home/julia/tmp/issue_test_return_async_std/target/debug/deps --extern tokio=/home/julia/tmp/issue_test_return_async_std/target/debug/deps/libtokio-010447985c854926.rlib`
error: internal compiler error: src/librustc_middle/ich/impls_ty.rs:94: StableHasher: unexpected region '_#13r

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.0-nightly (f93bb2a50 2020-05-25) running on x86_64-unknown-linux-gnu

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

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

error: aborting due to previous error

error: could not compile `issue_test_return_async_std`.

Caused by:
  process didn't exit successfully: `rustc --crate-name issue_test_return_async_std --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -Cembed-bitcode=no -C debuginfo=2 -C metadata=d603f945a98e8f13 -C extra-filename=-d603f945a98e8f13 --out-dir /home/julia/tmp/issue_test_return_async_std/target/debug/deps -C incremental=/home/julia/tmp/issue_test_return_async_std/target/debug/incremental -L dependency=/home/julia/tmp/issue_test_return_async_std/target/debug/deps --extern tokio=/home/julia/tmp/issue_test_return_async_std/target/debug/deps/libtokio-010447985c854926.rlib` (exit code: 101)
::
Backtrace

   Compiling issue_test_return_async_std v0.1.0 (/home/julia/tmp/issue_test_return_async_std)
error: internal compiler error: src/librustc_middle/ich/impls_ty.rs:94: StableHasher: unexpected region '_#13r

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:907:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1076
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /home/julia/db/store/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/boxed.rs:1071
  12: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}
             at /home/julia/db/store/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libproc_macro/bridge/client.rs:318
  13: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:490
  14: std::panicking::begin_panic
  15: rustc_errors::HandlerInner::bug
  16: rustc_errors::Handler::bug
  17: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  18: rustc_middle::ty::context::tls::with_opt::{{closure}}
  19: rustc_middle::ty::context::tls::with_opt
  20: rustc_middle::util::bug::opt_span_bug_fmt
  21: rustc_middle::util::bug::bug_fmt
  22: rustc_middle::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext> for rustc_middle::ty::sty::RegionKind>::hash_stable
  23: <T as rustc_query_system::dep_graph::dep_node::DepNodeParams<Ctxt>>::to_fingerprint
  24: rustc_query_system::query::plumbing::get_query_impl
  25: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt>::suggest_await_before_try
  26: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
  27: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  28: rustc_typeck::check::FnCtxt::check_argument_types
  29: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  30: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  31: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  32: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  33: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_coercable_to_type
  34: rustc_typeck::check::FnCtxt::check_decl_local
  35: rustc_typeck::check::FnCtxt::check_stmt
  36: rustc_typeck::check::FnCtxt::check_block_with_expected
  37: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  38: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  39: rustc_typeck::check::FnCtxt::check_block_with_expected
  40: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  41: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  42: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  43: rustc_typeck::check::check_fn
  44: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
  45: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  46: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  47: rustc_typeck::check::FnCtxt::check_argument_types
  48: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::confirm_builtin_call
  49: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  50: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  51: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  52: rustc_typeck::check::FnCtxt::check_argument_types
  53: rustc_typeck::check::FnCtxt::check_method_argument_types
  54: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  55: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  56: rustc_typeck::check::FnCtxt::check_block_with_expected
  57: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  58: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  59: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  60: rustc_typeck::check::check_fn
  61: rustc_middle::ty::context::GlobalCtxt::enter_local
  62: rustc_typeck::check::typeck_tables_of
  63: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_tables_of>::compute
  64: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  65: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  66: rustc_query_system::query::plumbing::get_query_impl
  67: rustc_typeck::check::typeck_tables_of
  68: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_tables_of>::compute
  69: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  70: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  71: rustc_query_system::query::plumbing::get_query_impl
  72: rustc_query_system::query::plumbing::ensure_query_impl
  73: rustc_typeck::check::typeck_item_bodies
  74: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  75: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  76: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  77: rustc_query_system::query::plumbing::get_query_impl
  78: rustc_typeck::check_crate
  79: rustc_interface::passes::analysis
  80: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  81: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  82: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  83: rustc_query_system::query::plumbing::get_query_impl
  84: rustc_middle::ty::context::tls::enter_global
  85: rustc_interface::interface::run_compiler_in_existing_thread_pool
  86: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.0-nightly (f93bb2a50 2020-05-25) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -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] type-checking `main`
#1 [typeck_tables_of] type-checking `main::{{closure}}#0`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `issue_test_return_async_std`.

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

@aodhneine aodhneine added 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. labels Jun 5, 2020
@aodhneine
Copy link
Author

Related: tokio-rs/tokio#2588, async-rs/async-std#810.

@jonas-schievink
Copy link
Contributor

Duplicate of #72766, this should be fixed in the current nightly.

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

2 participants