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 panicked when using yield keyword. #91477

Closed
SamMatzko opened this issue Dec 3, 2021 · 1 comment · Fixed by #91488
Closed

Compiler panicked when using yield keyword. #91477

SamMatzko opened this issue Dec 3, 2021 · 1 comment · Fixed by #91488
Assignees
Labels
A-coroutines Area: Coroutines 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

@SamMatzko
Copy link

SamMatzko commented Dec 3, 2021

Code

fn get_contents() -> impl Iterator {
    // A recursive function, returns a list of items
    yield "hello";
}

Meta

rustc --version --verbose:

rustc 1.55.0 (c8dfcfe04 2021-09-06)
binary: rustc
commit-hash: c8dfcfe046a7680554bf4eb612bad840e7631c4b
commit-date: 2021-09-06
host: x86_64-unknown-linux-gnu
release: 1.55.0
LLVM version: 12.0.1

Error output

error[E0658]: yield syntax is experimental
 --> src/main.rs:3:5
  |
3 |     yield "hello";
  |     ^^^^^^^^^^^^^
  |
  = note: see issue #43122 <https://github.com/rust-lang/rust/issues/43122> for more information

error[E0601]: `main` function not found in crate `problem`
 --> src/main.rs:1:1
  |
1 | / fn get_contents() -> impl Iterator {
2 | |     // A recursive function, returns a list of items
3 | |     yield "hello";
4 | | }
  | |_^ consider adding a `main` function to `src/main.rs`

error[E0627]: yield expression outside of generator literal
 --> src/main.rs:3:5
  |
3 |     yield "hello";
  |     ^^^^^^^^^^^^^

error[E0277]: `()` is not an iterator
 --> src/main.rs:1:22
  |
1 | fn get_contents() -> impl Iterator {
  |                      ^^^^^^^^^^^^^ `()` is not an iterator
2 |     // A recursive function, returns a list of items
3 |     yield "hello";
  |                  - consider removing this semicolon
  |
  = help: the trait `Iterator` is not implemented for `()`

thread 'rustc' panicked at 'assertion failed: body.yield_ty().is_some() == universal_regions.yield_ty.is_some()', compiler/rustc_mir/src/borrow_check/type_check/input_output.rs:112: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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.55.0 (c8dfcfe04 2021-09-06) 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 [mir_borrowck] borrow-checking `get_contents`
#1 [type_of] computing type of `get_contents::{opaque#0}`
end of query stack
Some errors have detailed explanations: E0277, E0601, E0627, E0658.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `problem` due to 4 previous errors
Backtrace

0: rust_begin_unwind
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/panicking.rs:50:5
   3: rustc_mir::borrow_check::type_check::type_check
   4: rustc_mir::borrow_check::nll::compute_regions
   5: rustc_mir::borrow_check::do_mir_borrowck
   6: rustc_infer::infer::InferCtxtBuilder::enter
   7: rustc_mir::borrow_check::mir_borrowck
   8: core::ops::function::FnOnce::call_once
   9: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  10: rustc_data_structures::stack::ensure_sufficient_stack
  11: rustc_query_system::query::plumbing::force_query_with_job
  12: rustc_query_system::query::plumbing::get_query_impl
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  14: rustc_typeck::collect::type_of::type_of
  15: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  16: rustc_data_structures::stack::ensure_sufficient_stack
  17: rustc_query_system::query::plumbing::force_query_with_job
  18: rustc_query_system::query::plumbing::get_query_impl
  19: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  20: rustc_typeck::check::check::check_item_type
  21: rustc_middle::hir::map::Map::visit_item_likes_in_module
  22: rustc_typeck::check::check::check_mod_item_types
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::force_query_with_job
  26: rustc_query_system::query::plumbing::get_query_impl
  27: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  28: rustc_session::utils::<impl rustc_session::session::Session>::time
  29: rustc_typeck::check_crate
  30: rustc_interface::passes::analysis
  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::dep_graph::graph::DepGraph<K>::with_eval_always_task
  34: rustc_data_structures::stack::ensure_sufficient_stack
  35: rustc_query_system::query::plumbing::force_query_with_job
  36: rustc_query_system::query::plumbing::get_query_impl
  37: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  38: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  39: rustc_span::with_source_map
  40: rustc_interface::interface::create_compiler_and_run
  41: scoped_tls::ScopedKey<T>::set

@SamMatzko SamMatzko 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 Dec 3, 2021
@inquisitivecrystal inquisitivecrystal added the A-coroutines Area: Coroutines label Dec 3, 2021
@compiler-errors
Copy link
Member

compiler-errors commented Dec 3, 2021

This happens when you try to yield in a function that returns an opaque impl Trait. This shouldn't ICE (even if it is a bug in the code 😉 ).

I've identified a quick fix.
@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines 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

Successfully merging a pull request may close this issue.

3 participants