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: returning impl Generator #46504

Closed
ghost opened this issue Dec 4, 2017 · 2 comments
Closed

Compiler error: returning impl Generator #46504

ghost opened this issue Dec 4, 2017 · 2 comments
Labels
A-coroutines Area: Coroutines A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ghost
Copy link

ghost commented Dec 4, 2017

Moin Leute,
I'm experimenting with the features: conservative_impl_trait, generators, generator trait. rustc got an internal error.
See the code. First I tried to do Yield = T. The compiler complained: expected &&T, found type parameter. So I added &&. That produced the error below.

I tried this code:

#![feature(generators, generator_trait)]
#![feature(conservative_impl_trait)]
use std::ops::Generator;

fn gen<'a, T>(data: Vec<&'a T>)
    -> impl Generator<Yield = &&T, Return = ()> + 'a
{
    move || {
        for d in &data {
            yield d;
        }
    }
}

fn main() {
}

I expected to see this happen:
I don't really know what should have happened instead. I stopped experimenting.

Got this:

error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:671: escaping regions in predicate Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: Slice([_]), item_def_id: DefId(2/0:990 ~ core[fa91]::ops[0]::generator[0]::Generator[0]::Yield[0]) }, &'a &'a T)),depth=0)
 --> test.rs:6:8
  |
6 |     -> impl Generator<Yield = &&T, Return = ()> + 'a
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.24.0-nightly (0a2e9ade8 2017-11-29) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:448:8
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Meta

rustc --version --verbose:

rustc 1.24.0-nightly (0a2e9ade8 2017-11-29)
binary: rustc
commit-hash: 0a2e9ade83ff253bb489c63a95b1f499c5e0916f
commit-date: 2017-11-29
host: x86_64-unknown-linux-gnu
release: 1.24.0-nightly
LLVM version: 4.0

Full Backtrace:

error: internal compiler error: /checkout/src/librustc_typeck/check/mod.rs:671: escaping regions in predicate Obligation(predicate=Binder(ProjectionPredicate(ProjectionTy { substs: Slice([_]), item_def_id: DefId(2/0:990 ~ core[fa91]::ops[0]::generator[0]::Generator[0]::Yield[0]) }, &'a &'a T)),depth=0)
 --> test.rs:6:8
  |
6 |     -> impl Generator<Yield = &&T, Return = ()> + 'a
  |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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.24.0-nightly (0a2e9ade8 2017-11-29) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:448:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at /checkout/src/libstd/sys_common/backtrace.rs:68
             at /checkout/src/libstd/sys_common/backtrace.rs:57
   2: _ZN3std9panicking12default_hook28_$u7b$$u7b$closure$u7d$$u7d$17hef59f1d15185c20fE.llvm.272A3273
             at /checkout/src/libstd/panicking.rs:381
   3: _ZN3std9panicking12default_hook17h7cc618db9a2c6232E.llvm.272A3273
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: <std::thread::local::LocalKey<T>>::with
   8: rustc::ty::context::tls::with_opt
   9: rustc::session::span_bug_fmt
  10: rustc_typeck::check::Inherited::register_predicate
  11: <rustc::ty::fold::BottomUpFolder<'a, 'gcx, 'tcx, F> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  12: rustc_typeck::check::check_fn
  13: <std::thread::local::LocalKey<T>>::with
  14: rustc::ty::context::GlobalCtxt::enter_local
  15: _ZN12rustc_typeck5check16typeck_tables_of17h804aa91ac012df90E.llvm.DD951B87
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute_result
  17: _ZN5rustc9dep_graph5graph8DepGraph14with_task_impl17h97b0ecf2a35a8c3fE.llvm.51E2F59F
  18: rustc_errors::Handler::track_diagnostics
  19: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  22: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  23: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  24: _ZN12rustc_typeck5check16typeck_tables_of17h804aa91ac012df90E.llvm.DD951B87
  25: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute_result
  26: _ZN5rustc9dep_graph5graph8DepGraph14with_task_impl17h97b0ecf2a35a8c3fE.llvm.51E2F59F
  27: rustc_errors::Handler::track_diagnostics
  28: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  29: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  30: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  31: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  32: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  33: _ZN12rustc_typeck7collect7type_of17h5c750f6b9ff91204E.llvm.6582AFEA
  34: rustc::ty::maps::<impl rustc::ty::maps::queries::type_of<'tcx>>::compute_result
  35: _ZN5rustc9dep_graph5graph8DepGraph14with_task_impl17h26018eebf02eef13E.llvm.51E2F59F
  36: rustc_errors::Handler::track_diagnostics
  37: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  38: rustc::ty::maps::<impl rustc::ty::maps::queries::type_of<'tcx>>::force
  39: rustc::ty::maps::<impl rustc::ty::maps::queries::type_of<'tcx>>::try_get
  40: rustc::ty::maps::TyCtxtAt::type_of
  41: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::type_of
  42: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  43: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  44: rustc::hir::Crate::visit_all_item_likes
  45: rustc::util::common::time
  46: rustc_typeck::check_crate
  47: <std::thread::local::LocalKey<T>>::with
  48: <std::thread::local::LocalKey<T>>::with
  49: rustc::ty::context::TyCtxt::create_and_enter
  50: rustc_driver::driver::compile_input
  51: rustc_driver::run_compiler
@ghost ghost changed the title Compiler error returning impl Generator Compiler error: returning impl Generator Dec 4, 2017
@TimNN TimNN added A-coroutines Area: Coroutines A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Dec 5, 2017
@cramertj
Copy link
Member

cramertj commented Dec 5, 2017

impl Generator<Yield = &&T, Return = ()> won't work right now because elision in impl Trait isn't supported. This is a duplicate of #43396.

As an aside, the code above won't work because you can't yield while a borrow is active in a generator, so you'll need for d in data rather than for d in &data.

@cramertj
Copy link
Member

cramertj commented Dec 14, 2017

This was fixed in #46616. It now gives the appropriate error:

error[E0597]: `data` does not live long enough
  --> src/main.rs:9:19
   |
9  |         for d in &data {
   |                   ^^^^ does not live long enough
...
12 |     }
   |     - borrowed value only lives until here
   |
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 5:1...
  --> src/main.rs:5:1
   |
5  | / fn gen<'a, T>(data: Vec<&'a T>)
6  | |     -> impl Generator<Yield = &&T, Return = ()> + 'a
7  | | {
8  | |     move || {
...  |
12 | |     }
13 | | }
   | |_^

error: aborting due to previous error

error: Could not compile `playground`.

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

@Zoxc Zoxc closed this as completed Jan 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants