Skip to content

ICE using min_type_alias_impl_trait with generators #87142

@WorldSEnder

Description

@WorldSEnder

Code

#![feature(min_type_alias_impl_trait, generator_trait, generators)] use std::ops::{Generator}; pub trait GeneratorProviderAlt: Sized { type Gen: Generator<(), Return=(), Yield=()>; fn start(ctx: Context<Self>) -> Self::Gen; } pub struct Context<G: 'static + GeneratorProviderAlt> { // back-link to our generator state // In reality some other pointer type, but Box triggers the bug // Also in reality, points to a wrapper struct that only indirectly holds // the generator state. link: Box<G::Gen>, } impl GeneratorProviderAlt for () { type Gen = impl Generator<(), Return=(), Yield=()>; fn start(ctx: Context<Self>) -> Self::Gen { move || { match ctx { _ => () } // make sure to use the context yield (); } } }

playground link

I haven't gotten it to error without nightly features, so I believe it has to do with the generated enum for the Generator.

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (952fdf2a1 2021-07-05) binary: rustc commit-hash: 952fdf2a1119affa1b37bcacb0c49cf9f0168ac8 commit-date: 2021-07-05 host: x86_64-unknown-linux-gnu release: 1.55.0-nightly LLVM version: 12.0.1 

Error output

error: internal compiler error: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs:150:13: type metadata for unique ID '324a3be6bacbf95688e06d88c8981eb0' is already in the `TypeMap`! 
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1034:9 stack backtrace: 0: std::panicking::begin_panic 1: std::panic::panic_any 2: rustc_errors::HandlerInner::bug 3: rustc_errors::Handler::bug 4: rustc_middle::ty::context::tls::with_opt 5: rustc_middle::util::bug::opt_span_bug_fmt 6: rustc_middle::util::bug::bug_fmt 7: rustc_codegen_llvm::debuginfo::metadata::create_and_register_recursive_type_forward_declaration 8: rustc_codegen_llvm::debuginfo::metadata::prepare_enum_metadata 9: rustc_codegen_llvm::debuginfo::metadata::type_metadata 10: rustc_codegen_llvm::debuginfo::<impl rustc_codegen_ssa::traits::debuginfo::DebugInfoMethods for rustc_codegen_llvm::context::CodegenCx>::dbg_scope_fn::get_function_signature 11: rustc_codegen_llvm::debuginfo::<impl rustc_codegen_ssa::traits::debuginfo::DebugInfoMethods for rustc_codegen_llvm::context::CodegenCx>::dbg_scope_fn 12: rustc_codegen_ssa::mir::codegen_mir 13: rustc_codegen_ssa::base::codegen_instance 14: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define 15: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen 16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task 17: rustc_codegen_llvm::base::compile_codegen_unit 18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate 19: rustc_interface::passes::QueryContext::enter 20: rustc_interface::queries::Queries::ongoing_codegen 21: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter 22: rustc_span::with_source_map 23: rustc_interface::interface::create_compiler_and_run 24: scoped_tls::ScopedKey<T>::set 


As an aside, if one gets rid of the Box, this fails (kind of expected, though the error message could be improved) with

error[E0391]: cycle detected when computing layout of `[generator@src/lib.rs:21:9: 24:10]` | = note: ...which requires computing layout of `Context<()>`... = note: ...which again requires computing layout of `[generator@src/lib.rs:21:9: 24:10]`, completing the cycle note: cycle used when optimizing MIR for `<impl at src/lib.rs:18:1: 26:2>::start` --> src/lib.rs:20:5 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coroutinesArea: CoroutinesC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-coroutines`#![feature(coroutines)]`F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`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.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions