Skip to content

Broken MIR with immovable generators #49232

Closed
@Nemo157

Description

@Nemo157
#![feature(conservative_impl_trait)]
#![feature(generators)]
#![feature(generator_trait)]

use std::ops::Generator;

#[derive(Debug)]
pub struct Beacon;

fn listen() -> impl Iterator<Item=Beacon> {
    Some(Beacon).into_iter()
}

pub fn main() -> impl Generator<Yield=(), Return=Result<(), ()>> {
    #[allow(unused_unsafe)]
    unsafe {
        static move || {
            let mut stream = listen();

            loop {
                let beacon = {
                    match stream.next() {
                        Some(e) => e,
                        None => break,
                    }
                };
                println!("Saw beacon {:?}", beacon);
            }

            loop {
                yield ();
            }
        }
    }
}

when compiled with rustc src/lib.rs --crate-type lib gives error:

error: internal compiler error: librustc_mir/transform/generator.rs:495: Broken MIR: generator contains type Beacon in MIR, but typeck only knows about {impl std::iter::Iterator, ()}
  --> src/lib.rs:17:9
   |
17 | /         static move || {
18 | |             let mut stream = listen();
19 | |
20 | |             loop {
...  |
32 | |             }
33 | |         }
   | |_________^

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:488:9
note: Run with `RUST_BACKTRACE=1` for 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.26.0-nightly (a04b88d19 2018-03-19) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib

Metadata

Metadata

Assignees

No one assigned

    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