Skip to content

[ICE]: encountered unexpected unsized field in layout of  #163356

Description

@matthiaskrgr

snippet:

type Opaque2<'a> = dyn Sync + 'static;

fn test2() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque2<'a>, Box<[u8]>) {
    move |_| loop {}
}

fn main() {}

Version information

rustc 1.100.0-nightly (5ceaf6608 2026-09-25)
binary: rustc
commit-hash: 5ceaf6608eb354c2f5bbb3b8d974caa367dac81c
commit-date: 2026-09-25
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.1

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: type alias `Opaque2` is never used
 --> /tmp/icemaker_global_tempdir.O1Kui7qc4fFZ/rustc_testrunner_tmpdir_reporting.I4KJqBrTyhgY/mvce.rs:1:6
  |
1 | type Opaque2<'a> = dyn Sync + 'static;
  |      ^^^^^^^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: function `test2` is never used
 --> /tmp/icemaker_global_tempdir.O1Kui7qc4fFZ/rustc_testrunner_tmpdir_reporting.I4KJqBrTyhgY/mvce.rs:3:4
  |
3 | fn test2() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque...
  |    ^^^^^

warning: 2 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: encountered unexpected unsized field in layout of (dyn [Binder { value: AutoTrait(DefId(2:4558 ~ core[df69]::marker::Sync)), bound_vars: [] }] + '{erased}, std::boxed::Box<[u8], std::alloc::Global>): TyAndLayout {
                                    ty: dyn Sync,
                                    layout: Layout {
                                        size: Size(0 bytes),
                                        align: AbiAlign {
                                            abi: Align(1 bytes),
                                        },
                                        backend_repr: Memory {
                                            sized: false,
                                        },
                                        fields: Arbitrary {
                                            offsets: [],
                                            in_memory_order: [],
                                        },
                                        largest_niche: None,
                                        uninhabited: false,
                                        variants: Single {
                                            index: 0,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(1 bytes),
                                        randomization_seed: 0,
                                    },
                                }
  |
  = note: delayed at /rustc-dev/5ceaf6608eb354c2f5bbb3b8d974caa367dac81c/compiler/rustc_ty_utils/src/layout.rs:133:32
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
             1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
             2: <rustc_errors::diagnostic::Diag>::emit_err
             3: <rustc_errors::DiagCtxtHandle>::delayed_bug::<alloc::string::String>
             4: rustc_ty_utils::layout::map_error
             5: rustc_ty_utils::layout::layout_of_uncached::{closure#3}
             6: rustc_ty_utils::layout::layout_of_uncached
             7: rustc_ty_utils::layout::layout_of
             8: rustc_query_impl::query_vtables::layout_of::invoke_provider_fn::__rust_begin_short_backtrace
             9: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::ErasedData<[u8; 16]>>, false>
            10: rustc_query_impl::query_vtables::layout_of::execute_query_non_incr::__rust_end_short_backtrace
            11: <rustc_mir_transform::known_panics_lint::KnownPanicsLint as rustc_mir_transform::pass_manager::MirLint>::run_lint
            12: rustc_mir_transform::run_analysis_to_runtime_passes
            13: rustc_mir_transform::mir_drops_elaborated_and_const_checked
            14: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
            15: rustc_query_impl::query_vtables::mir_drops_elaborated_and_const_checked::execute_query_non_incr::__rust_end_short_backtrace
            16: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
            17: rustc_interface::passes::analysis
            18: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
            19: rustc_query_impl::query_vtables::analysis::execute_query_non_incr::__rust_end_short_backtrace
            20: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
            21: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
            22: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            23: <std::sys::thread::unix::Thread>::new::thread_start
            24: <unknown>
            25: <unknown>
          

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: rustc 1.100.0-nightly (5ceaf6608 2026-09-25) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions