Skip to content

Computing <MyStruct as std::ptr::Pointee>::Metadata fails when trailing field has a projection #92577

Closed
@Zalathar

Description

@Zalathar

Code

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8e31db4a857f6bcdbf287b8d9745ca22

use std::collections::HashMap;

trait HasType {
    type Type;
}

impl HasType for () {
    type Type = ();
}

pub struct MyStruct {
    _field: <() as HasType>::Type,
}

pub fn do_insert(map: &mut HashMap<*const MyStruct, ()>, key: *const MyStruct) {
    map.insert(key, ());
}

Meta

(Build fails with an ICE on current stable/beta/nightly on the playground.)

Error output

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_monomorphize/src/collector.rs:894:93
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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
end of query stack
error: could not compile `playground`
Backtrace

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_monomorphize/src/collector.rs:894:93
stack backtrace:
   0: rust_begin_unwind
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:100:14
   2: core::panicking::panic
             at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/core/src/panicking.rs:50:5
   3: <rustc_monomorphize::collector::MirNeighborCollector as rustc_middle::mir::visit::Visitor>::visit_terminator
   4: rustc_monomorphize::collector::collect_neighbours
   5: rustc_monomorphize::collector::collect_items_rec
   6: rustc_monomorphize::collector::collect_items_rec
   7: rustc_monomorphize::collector::collect_items_rec
   8: rustc_monomorphize::collector::collect_items_rec
   9: rustc_monomorphize::collector::collect_items_rec
  10: rustc_session::utils::<impl rustc_session::session::Session>::time
  11: rustc_monomorphize::collector::collect_crate_mono_items
  12: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  13: rustc_query_system::query::plumbing::try_execute_query
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  15: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  16: rustc_query_system::query::plumbing::try_execute_query
  17: rustc_query_system::query::plumbing::get_query
  18: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
  19: rustc_metadata::rmeta::encoder::encode_metadata_impl
  20: rustc_data_structures::sync::join
  21: rustc_metadata::rmeta::encoder::encode_metadata
  22: rustc_interface::queries::Queries::ongoing_codegen
  23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  24: rustc_span::with_source_map
  25: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.57.0 (f1edd0429 2021-11-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
end of query stack
error: could not compile `playground`

Metadata

Metadata

Assignees

Labels

C-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.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions