rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.58k stars 12.48k forks source link

ICE on wrong generator yield/return type when using type_alias_impl_trait #94429

Closed henryksloan closed 2 years ago

henryksloan commented 2 years ago

Possibly related to #87142 as both ICEs arise from Box<dyn Any>, but this ICE occurs on a different line.

Code

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

trait Runnable {
    type Gen: Generator<Yield = (), Return = ()>;

    fn run(&mut self) -> Self::Gen;
}

struct Implementor {}

impl Runnable for Implementor {
    type Gen = impl Generator<Yield = (), Return = ()>;

    fn run(&mut self) -> Self::Gen {
        move || {
            // This line causes the ICE;
            // the same error occurs if the return type is wrong (e.g. `return 1`)
            yield 1;
        }
    }
}

Playground link

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (10cc7a6d0 2022-02-26)
binary: rustc
commit-hash: 10cc7a6d031fd607f594f4c7af113bfaa9a879e9
commit-date: 2022-02-26
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0

Error output

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:547:26: expected defining type for `DefId(0:14 ~ generator_existential_types[3c81]::{impl#0}::run::{closure#0})`: `[type error]`
Backtrace

``` thread 'rustc' panicked at 'Box', /rustc/10cc7a6d031fd607f594f4c7af113bfaa9a879e9/compiler/rustc_errors/src/lib.rs:1102:9 stack backtrace: 0: std::panicking::begin_panic:: 1: std::panic::panic_any:: 2: ::span_bug:: 3: ::span_bug:: 4: rustc_middle::ty::context::tls::with_opt::::{closure#0}, ()> 5: rustc_middle::util::bug::opt_span_bug_fmt:: 6: rustc_middle::util::bug::span_bug_fmt:: 7: ::new 8: rustc_borrowck::do_mir_borrowck 9: >::call_once 10: >::with_task:: 11: rustc_query_system::query::plumbing::try_execute_query::> 12: ::mir_borrowck 13: ::check 14: ::visit_expr 15: ::visit_nested_body 16: rustc_hir::intravisit::walk_impl_item:: 17: ::visit_nested_impl_item 18: rustc_hir::intravisit::walk_item:: 19: rustc_typeck::collect::type_of::find_opaque_ty_constraints 20: rustc_typeck::collect::type_of::type_of 21: >::with_task:: 22: rustc_query_system::query::plumbing::get_query:: 23: rustc_typeck::check::check::check_item_type 24: ::visit_item_likes_in_module:: 25: rustc_typeck::check::check::check_mod_item_types 26: >::with_task:: 27: rustc_query_system::query::plumbing::try_execute_query::> 28: rustc_query_system::query::plumbing::get_query:: 29: ::for_each_module:: 30: rustc_typeck::check_crate 31: rustc_interface::passes::analysis 32: >::with_task::> 33: rustc_query_system::query::plumbing::try_execute_query::>> 34: rustc_query_system::query::plumbing::get_query:: 35: ::enter::> 36: ::enter::, rustc_errors::ErrorReported>> 37: rustc_span::with_source_map::, rustc_interface::interface::create_compiler_and_run, rustc_driver::run_compiler::{closure#1}>::{closure#1}> 38: >::set::, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>> ```

Alexendoo commented 2 years ago

No longer ICEs since #94081