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

ICE: compiler/rustc_typeck/src/check/closure.rs:608:18: async fn generator return type not an inference variable #78654

Closed
chengniansun opened this issue Nov 2, 2020 · 4 comments · Fixed by #78739
Assignees
Labels
A-async-await Area: Async & Await A-coroutines Area: Coroutines AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. 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

@chengniansun
Copy link

chengniansun commented Nov 2, 2020

Code

impl<const H: feature> Foo {
    async fn biz() {}
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (4f7612ac1 2020-10-31)
binary: rustc
commit-hash: 4f7612ac1499258025077f1fd05d2f429f9accfb
commit-date: 2020-10-31
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Error output

error[E0670]: `async fn` is not permitted in the 2015 edition
 --> reduced_mutant.rs:2:5
  |
2 |     async fn biz() {}
  |     ^^^^^ to use `async fn`, switch to Rust 2018
  |
  = help: set `edition = "2018"` in `Cargo.toml`
  = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error[E0412]: cannot find type `Foo` in this scope
 --> reduced_mutant.rs:1:24
  |
1 | impl<const H: feature> Foo {
  |                        ^^^ not found in this scope

error[E0573]: expected type, found built-in attribute `feature`
 --> reduced_mutant.rs:1:15
  |
1 | impl<const H: feature> Foo {
  |               ^^^^^^^ not a type

error[E0658]: const generics are unstable
 --> reduced_mutant.rs:1:12
  |
1 | impl<const H: feature> Foo {
  |            ^
  |
  = note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information
  = help: add `#![feature(min_const_generics)]` to the crate attributes to enable

error[E0601]: `main` function not found in crate `reduced_mutant`
 --> reduced_mutant.rs:1:1
  |
1 | / impl<const H: feature> Foo {
2 | |     async fn biz() {}
3 | | }
  | |_^ consider adding a `main` function to `reduced_mutant.rs`

error: internal compiler error: compiler/rustc_typeck/src/check/closure.rs:608:18: async fn generator return type not an inference variable
 --> reduced_mutant.rs:2:20
  |
2 |     async fn biz() {}
  |                    ^^

thread 'rustc' panicked at 'Box<Any>', /rustc/4f7612ac1499258025077f1fd05d2f429f9accfb/compiler/rustc_errors/src/lib.rs:888: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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.49.0-nightly (4f7612ac1 2020-10-31) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl [type error]>::biz`
#1 [mir_built] building MIR for `<impl [type error]>::biz`
end of query stack
error: aborting due to 6 previous errors

Some errors have detailed explanations: E0412, E0573, E0601, E0658, E0670.
For more information about an error, try `rustc --explain E0412`.
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/4f7612ac1499258025077f1fd05d2f429f9accfb/compiler/rustc_errors/src/lib.rs:888:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::span_bug
   2: rustc_errors::Handler::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::span_bug_fmt
   8: rustc_typeck::check::closure::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::supplied_sig_of_closure
   9: rustc_typeck::check::closure::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_closure
  10: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  11: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  12: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_argument_types
  13: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  14: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  15: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  18: rustc_typeck::check::check::check_fn
  19: rustc_infer::infer::InferCtxtBuilder::enter
  20: rustc_typeck::check::typeck
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  22: rustc_data_structures::stack::ensure_sufficient_stack
  23: rustc_query_system::query::plumbing::get_query_impl
  24: rustc_middle::ty::context::TyCtxt::typeck_opt_const_arg
  25: rustc_mir_build::thir::cx::Cx::new
  26: rustc_infer::infer::InferCtxtBuilder::enter
  27: rustc_mir_build::build::mir_built
  28: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_built>::compute
  29: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  30: rustc_data_structures::stack::ensure_sufficient_stack
  31: rustc_query_system::query::plumbing::get_query_impl
  32: rustc_mir::transform::check_unsafety::unsafety_check_result
  33: core::ops::function::FnOnce::call_once
  34: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::unsafety_check_result>::compute
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::get_query_impl
  38: rustc_query_system::query::plumbing::ensure_query_impl
  39: rustc_mir::transform::mir_const
  40: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_const>::compute
  41: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  42: rustc_data_structures::stack::ensure_sufficient_stack
  43: rustc_query_system::query::plumbing::get_query_impl
  44: rustc_mir::transform::mir_promoted
  45: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_promoted>::compute
  46: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  47: rustc_data_structures::stack::ensure_sufficient_stack
  48: rustc_query_system::query::plumbing::get_query_impl
  49: rustc_mir::borrow_check::mir_borrowck
  50: core::ops::function::FnOnce::call_once
  51: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  52: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  53: rustc_data_structures::stack::ensure_sufficient_stack
  54: rustc_query_system::query::plumbing::get_query_impl
  55: rustc_typeck::collect::type_of::type_of
  56: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::type_of>::compute
  57: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  58: rustc_data_structures::stack::ensure_sufficient_stack
  59: rustc_query_system::query::plumbing::get_query_impl
  60: rustc_typeck::check::check::check_item_type
  61: rustc_middle::hir::map::Map::visit_item_likes_in_module
  62: rustc_typeck::check::check::check_mod_item_types
  63: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_item_types>::compute
  64: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  65: rustc_data_structures::stack::ensure_sufficient_stack
  66: rustc_query_system::query::plumbing::get_query_impl
  67: rustc_query_system::query::plumbing::ensure_query_impl
  68: rustc_session::utils::<impl rustc_session::session::Session>::time
  69: rustc_typeck::check_crate
  70: rustc_interface::passes::analysis
  71: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  72: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  73: rustc_data_structures::stack::ensure_sufficient_stack
  74: rustc_query_system::query::plumbing::get_query_impl
  75: rustc_interface::passes::QueryContext::enter
  76: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  77: rustc_span::with_source_map
  78: scoped_tls::ScopedKey<T>::set

NOTE: The bug is found by our work-in-progress compiler testing tool Kira, and the test program is reduced/minimized by Perses

@chengniansun chengniansun 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 Nov 2, 2020
@JohnTitor
Copy link
Member

Related to #64999.

@JohnTitor JohnTitor added A-async-await Area: Async & Await A-coroutines Area: Coroutines labels Nov 2, 2020
@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Nov 3, 2020
@nikomatsakis
Copy link
Contributor

My hunch is that this code:

let ret_vid = match *ret_ty.kind() {
ty::Infer(ty::TyVar(ret_vid)) => ret_vid,
_ => span_bug!(
self.tcx.def_span(expr_def_id),
"async fn generator return type not an inference variable"
),
};

needs to be generalized to also accept a Error type. The function could just return Some(err) (or maybe None) in that case and I expect the ICE would go away.

@nikomatsakis nikomatsakis added the E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. label Nov 3, 2020
@nikomatsakis
Copy link
Contributor

I'm tagging this as E-mentor because of the above instructions ☝️ (feel free to also ping me on Zulip)

@hameerabbasi
Copy link
Contributor

@rustbot claim

m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 5, 2020
…sakis

Fix ICE on type error in async function

Fixes rust-lang#78654
@bors bors closed this as completed in 171d29c Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-coroutines Area: Coroutines AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. 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
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants