Skip to content

Compiler panicked when using yield keyword. #91477

Closed
@SamMatzko

Description

@SamMatzko

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

Metadata

Metadata

Labels

A-coroutinesArea: CoroutinesC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions