Skip to content

ICE: Layout::compute: unexpected type '_' #126942

Closed
@Naserume

Description

Code

pub trait A {}
pub trait B: A {}

pub trait Mirror {
    type Assoc: ?Sized;
}
impl<T: ?Sized> Mirror for A {
    type Assoc = T;
}

pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
    static
}

static I: <dyn A + 'static as Mirror>::Assoc = 3;
pub fn main() {}

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (bcf94dec5 2024-06-23)
binary: rustc
commit-hash: bcf94dec5ba6838e435902120c0384c360126a26
commit-date: 2024-06-23
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error: expected identifier, found `}`
  --> ./6EC19.rs:13:1
   |
13 | }
   | ^ expected identifier

warning: trait objects without an explicit `dyn` are deprecated
 --> ./6EC19.rs:7:28
  |
7 | impl<T: ?Sized> Mirror for A {
  |                            ^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
  |
7 | impl<T: ?Sized> Mirror for dyn A {
  |                            +++
help: alternatively use a blanket implementation to implement `Mirror` for all types that also implement `A`
  |
7 | impl<T: ?Sized, U: A> Mirror for U {
  |               ++++++             ~

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> ./6EC19.rs:7:6
  |
7 | impl<T: ?Sized> Mirror for A {
  |      ^ unconstrained type parameter

error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
  --> ./6EC19.rs:11:62
   |
11 | pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
   |                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
   |
   = help: the trait `Mirror` is implemented for `(dyn A + 'static)`

error[E0283]: type annotations needed
  --> ./6EC19.rs:15:11
   |
15 | static I: <dyn A + 'static as Mirror>::Assoc = 3;
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
   |
   = note: cannot satisfy `_: Sync`
   = note: shared static variables must have a type that implements `Sync`
Backtrace

error: internal compiler error: compiler/rustc_ty_utils/src/layout.rs:674:13: Layout::compute: unexpected type `_`

thread 'rustc' panicked at compiler/rustc_ty_utils/src/layout.rs:674:13:
Box<dyn Any>
stack backtrace:
   0:        0x10cae6b43 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he71f7af0ddafc64d
   1:        0x10cb3225b - core::fmt::write::h30d0e266faff29b6
   2:        0x10cadcace - std::io::Write::write_fmt::he666ca78eb4b8406
   3:        0x10cae6931 - std::sys::backtrace::print::h22721f9ab9a2749a
   4:        0x10cae9709 - std::panicking::default_hook::{{closure}}::h145e29ed875d8021
   5:        0x10cae948a - std::panicking::default_hook::h5d437c7e6bf0e3b5
   6:        0x115d8147c - std[8efa578c02603ef9]::panicking::update_hook::<alloc[135510a28be92df]::boxed::Box<rustc_driver_impl[63f2171535a6fe49]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x10caea326 - std::panicking::rust_panic_with_hook::h6889093a56e48d04
   8:        0x115df0337 - std[8efa578c02603ef9]::panicking::begin_panic::<rustc_errors[8995f93e9c4bcc9a]::ExplicitBug>::{closure#0}
   9:        0x115ddc949 - std[8efa578c02603ef9]::sys::backtrace::__rust_end_short_backtrace::<std[8efa578c02603ef9]::panicking::begin_panic<rustc_errors[8995f93e9c4bcc9a]::ExplicitBug>::{closure#0}, !>
  10:        0x11a7e2f09 - std[8efa578c02603ef9]::panicking::begin_panic::<rustc_errors[8995f93e9c4bcc9a]::ExplicitBug>
  11:        0x115e02276 - <rustc_errors[8995f93e9c4bcc9a]::diagnostic::BugAbort as rustc_errors[8995f93e9c4bcc9a]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x116a9c95e - rustc_middle[4384e439927f71dd]::util::bug::opt_span_bug_fmt::<rustc_span[aed5394308446158]::span_encoding::Span>::{closure#0}
  13:        0x116a522b7 - rustc_middle[4384e439927f71dd]::ty::context::tls::with_opt::<rustc_middle[4384e439927f71dd]::util::bug::opt_span_bug_fmt<rustc_span[aed5394308446158]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:        0x116a51d75 - rustc_middle[4384e439927f71dd]::ty::context::tls::with_context_opt::<rustc_middle[4384e439927f71dd]::ty::context::tls::with_opt<rustc_middle[4384e439927f71dd]::util::bug::opt_span_bug_fmt<rustc_span[aed5394308446158]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:        0x11a8a57eb - rustc_middle[4384e439927f71dd]::util::bug::bug_fmt
  16:        0x117bc12e7 - rustc_ty_utils[a4413d16294df763]::layout::layout_of_uncached
  17:        0x117bd4076 - rustc_ty_utils[a4413d16294df763]::layout::layout_of
  18:        0x117423276 - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 16usize]>>
  19:        0x1173f2f4e - <rustc_query_impl[a24e9023943e74ab]::query_impl::layout_of::dynamic_query::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<(rustc_middle[4384e439927f71dd]::ty::context::TyCtxt, rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::ty::Ty>)>>::call_once
  20:        0x11720a655 - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::ty::Ty>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  21:        0x1174613f4 - rustc_query_impl[a24e9023943e74ab]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  22:        0x117b59d59 - rustc_middle[4384e439927f71dd]::query::plumbing::query_get_at::<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::ty::Ty>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 16usize]>>>
  23:        0x117bd4051 - rustc_ty_utils[a4413d16294df763]::layout::layout_of
  24:        0x117423276 - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 16usize]>>
  25:        0x1173f2f4e - <rustc_query_impl[a24e9023943e74ab]::query_impl::layout_of::dynamic_query::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<(rustc_middle[4384e439927f71dd]::ty::context::TyCtxt, rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::ty::Ty>)>>::call_once
  26:        0x11720a655 - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::ty::Ty>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  27:        0x1174613f4 - rustc_query_impl[a24e9023943e74ab]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  28:        0x115fac0a6 - rustc_middle[4384e439927f71dd]::query::plumbing::query_get_at::<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_middle[4384e439927f71dd]::ty::ParamEnvAnd<rustc_middle[4384e439927f71dd]::ty::Ty>, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 16usize]>>>
  29:        0x11607bd51 - rustc_hir_analysis[8e62bc6471a04889]::check::check::check_static_inhabited
  30:        0x11607f85d - rustc_hir_analysis[8e62bc6471a04889]::check::check::check_item_type
  31:        0x1160b64ae - rustc_hir_analysis[8e62bc6471a04889]::check::wfcheck::check_well_formed
  32:        0x11741e86c - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  33:        0x11729701f - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::VecCache<rustc_hir[ae2456c39d7f6170]::hir_id::OwnerId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  34:        0x117468280 - rustc_query_impl[a24e9023943e74ab]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  35:        0x115facba2 - rustc_middle[4384e439927f71dd]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[30bd0146b5104221]::query::caches::VecCache<rustc_hir[ae2456c39d7f6170]::hir_id::OwnerId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, ()>
  36:        0x1160c4de1 - rustc_hir_analysis[8e62bc6471a04889]::check::wfcheck::check_mod_type_wf
  37:        0x11741e83c - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  38:        0x11724db79 - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_span[aed5394308446158]::def_id::LocalModDefId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  39:        0x117444ed0 - rustc_query_impl[a24e9023943e74ab]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  40:        0x11614024c - rustc_hir_analysis[8e62bc6471a04889]::check_crate
  41:        0x1166da6cb - rustc_interface[73216d77aad0c3a5]::passes::run_required_analyses
  42:        0x1166dccb3 - rustc_interface[73216d77aad0c3a5]::passes::analysis
  43:        0x117422dec - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  44:        0x11720249e - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::SingleCache<rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  45:        0x11742d307 - rustc_query_impl[a24e9023943e74ab]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:        0x115d258d7 - <rustc_interface[73216d77aad0c3a5]::queries::QueryResult<&rustc_middle[4384e439927f71dd]::ty::context::GlobalCtxt>>::enter::<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  47:        0x115d7fc94 - rustc_interface[73216d77aad0c3a5]::interface::run_compiler::<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}
  48:        0x115d6ec91 - std[8efa578c02603ef9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_with_globals<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_pool_with_globals<rustc_interface[73216d77aad0c3a5]::interface::run_compiler<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>
  49:        0x115d8a3a6 - <<std[8efa578c02603ef9]::thread::Builder>::spawn_unchecked_<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_with_globals<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_pool_with_globals<rustc_interface[73216d77aad0c3a5]::interface::run_compiler<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:        0x10caf352b - std::sys::pal::unix::thread::Thread::new::thread_start::h68d49fa26efc1659
  51:     0x7ff801f5318b - __pthread_start

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/Documents/240624-56257.txt` to your bug report

query stack during panic:
panicked at /rustc/bcf94dec5ba6838e435902120c0384c360126a26/compiler/rustc_type_ir/src/ty_kind.rs:889:17:

thread panicked while processing panic. aborting.
zsh: abort      rustc ./6EC19.rs

Similar Issue

Issue #124207 has same ice message with similar backtrace, but this require #![feature(transmutability)] and #![feature(type_alias_impl_trait)] because it uses BikeshedIntrinsicsFrom so I decided to report mine.

Metadata

Labels

A-layoutArea: Memory layout of typesC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.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