Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout sanity failed check: "size mismatch between ABI and layout in TyAndLayout". Zero size array in union. #103634

Closed
jruderman opened this issue Oct 27, 2022 · 3 comments · Fixed by #104872
Labels
A-array Area: `[T; N]` A-layout Area: Memory layout of types C-bug Category: This is a bug. F-transmutability `#![feature(transmutability)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

Code

#![crate_type = "lib"]
#![feature(transmutability)]
#![allow(dead_code)]

mod assert {
    use std::mem::{Assume, BikeshedIntrinsicFrom};
    pub struct Context;
    pub fn is_maybe_transmutable<Src, Dst>()
    where
        Dst: BikeshedIntrinsicFrom<Src, Context, {
            Assume {
                alignment: false,
                lifetimes: false,
                safety: false,
                validity: false,
            }
        }>
    {}
}

fn test() {
    pub union U {
        a: [u16; 0],
        b: u8,
    }

    #[repr(C)]
    struct S(
        U, 
        u8,
    );

    assert::is_maybe_transmutable::<S, u128>();
}

Found with a modified fuzz-rustc

About this testcase

Origin:

Elements that seem necessary:

  • In the union, the zero-length array seems necessary
  • In the union, a and b mentioning different size things (u16 vs u8) seems necessary
  • The union's lack of #[repr(C)] seems necessary

ICE output

In a compiler with debug assertions enabled, this trips: "size mismatch between ABI and layout in TyAndLayout".

Output including layouts, backtraces, and query stack

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Size(2 bytes)`,
 right: `Size(1 bytes)`: size mismatch between ABI and layout in TyAndLayout {
    ty: test::U,
    layout: Layout {
        size: Size(2 bytes),
        align: AbiAndPrefAlign {
            abi: Align(2 bytes),
            pref: Align(8 bytes),
        },
        abi: Scalar(
            Union {
                value: Int(
                    I8,
                    false,
                ),
            },
        ),
        fields: Union(
            2,
        ),
        largest_niche: None,
        variants: Single {
            index: 0,
        },
    },
}', compiler/rustc_ty_utils/src/layout_sanity_check.rs:72:21
stack backtrace:
   0:        0x1106b5291 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha861de675ede8b0c
   1:        0x110739448 - core::fmt::write::hda6b0e10b55724fb
   2:        0x1106c3f28 - std::io::Write::write_fmt::hdf206c4f52d49905
   3:        0x1106b5082 - std::sys_common::backtrace::print::h34f569a9c7a99a9f
   4:        0x1106ba405 - std::panicking::default_hook::{{closure}}::hda4eceb51b014a4b
   5:        0x1106ba1e7 - std::panicking::default_hook::he3b91b4302671d36
   6:        0x11fee8fa8 - rustc_driver[800c97195df9dd7a]::DEFAULT_HOOK::{closure#0}::{closure#0}
   7:        0x1106baac6 - std::panicking::rust_panic_with_hook::he8e29b5de756633a
   8:        0x1106c6dc3 - std::panicking::begin_panic_handler::{{closure}}::hdf4593bcdd333004
   9:        0x1106c6cf8 - std::sys_common::backtrace::__rust_end_short_backtrace::h574e2faa7e4a189e
  10:        0x1106ba4d8 - _rust_begin_unwind
  11:        0x110756ca3 - core::panicking::panic_fmt::h852bdf3f14372e73
  12:        0x110738325 - core::panicking::assert_failed_inner::h6aa04f268f2607ae
  13:        0x124f7363e - core[63810368375d8c35]::panicking::assert_failed::<rustc_target[44d477e4461259e2]::abi::Size, rustc_target[44d477e4461259e2]::abi::Size>
  14:        0x122730731 - rustc_ty_utils[335bf625919b7879]::layout_sanity_check::sanity_check_layout
  15:        0x1226e6341 - rustc_ty_utils[335bf625919b7879]::layout::layout_of
  16:        0x123b77537 - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::get_query::<rustc_query_impl[e3f63d70ae94933f]::queries::layout_of, rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt>
  17:        0x123e5c721 - <rustc_query_impl[e3f63d70ae94933f]::Queries as rustc_middle[8a1cca0694b55532]::ty::query::QueryEngine>::layout_of
  18:        0x122702dfb - <rustc_middle[8a1cca0694b55532]::ty::layout::LayoutCx<rustc_middle[8a1cca0694b55532]::ty::context::TyCtxt> as rustc_middle[8a1cca0694b55532]::ty::layout::LayoutOf>::layout_of
  19:        0x122701c71 - <core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::FieldDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}::{closure#0}> as core[63810368375d8c35]::iter::traits::iterator::Iterator>::try_fold::<(), <core[63810368375d8c35]::iter::adapters::GenericShunt<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::FieldDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}::{closure#0}>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>> as core[63810368375d8c35]::iter::traits::iterator::Iterator>::try_fold<(), core[63810368375d8c35]::iter::traits::iterator::Iterator::try_for_each::call<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>, core[63810368375d8c35]::ops::control_flow::ControlFlow<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>, core[63810368375d8c35]::ops::control_flow::ControlFlow<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>::Break>::{closure#0}, core[63810368375d8c35]::ops::control_flow::ControlFlow<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>::{closure#0}, core[63810368375d8c35]::ops::control_flow::ControlFlow<core[63810368375d8c35]::ops::control_flow::ControlFlow<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>>
  20:        0x1226cea5c - <core[63810368375d8c35]::iter::adapters::GenericShunt<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::FieldDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}::{closure#0}>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>> as core[63810368375d8c35]::iter::traits::iterator::Iterator>::next
  21:        0x12273929e - <alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>> as alloc[9c4954bf8315fe26]::vec::spec_from_iter::SpecFromIter<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>, core[63810368375d8c35]::iter::adapters::GenericShunt<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::FieldDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}::{closure#0}>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>>>>::from_iter
  22:        0x1226ce089 - core[63810368375d8c35]::iter::adapters::try_process::<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::FieldDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}::{closure#0}>, rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>, <core[63810368375d8c35]::result::Result<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError> as core[63810368375d8c35]::iter::traits::collect::FromIterator<core[63810368375d8c35]::result::Result<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>>>::from_iter<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::FieldDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}::{closure#0}>>::{closure#0}, alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>
  23:        0x122701b61 - <core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::VariantDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}> as core[63810368375d8c35]::iter::traits::iterator::Iterator>::try_fold::<(), <core[63810368375d8c35]::iter::adapters::GenericShunt<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::VariantDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>> as core[63810368375d8c35]::iter::traits::iterator::Iterator>::try_fold<(), core[63810368375d8c35]::iter::traits::iterator::Iterator::try_for_each::call<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>, core[63810368375d8c35]::ops::control_flow::ControlFlow<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>, core[63810368375d8c35]::ops::control_flow::ControlFlow<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>::Break>::{closure#0}, core[63810368375d8c35]::ops::control_flow::ControlFlow<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>>::{closure#0}, core[63810368375d8c35]::ops::control_flow::ControlFlow<core[63810368375d8c35]::ops::control_flow::ControlFlow<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>>>
  24:        0x1226ce9bd - <core[63810368375d8c35]::iter::adapters::GenericShunt<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::VariantDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>> as core[63810368375d8c35]::iter::traits::iterator::Iterator>::next
  25:        0x1227387a8 - <alloc[9c4954bf8315fe26]::vec::Vec<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>> as alloc[9c4954bf8315fe26]::vec::spec_from_iter::SpecFromIter<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>, core[63810368375d8c35]::iter::adapters::GenericShunt<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::VariantDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>>>>::from_iter
  26:        0x1226cdfb9 - core[63810368375d8c35]::iter::adapters::try_process::<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::VariantDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}>, alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::convert::Infallible, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>, <core[63810368375d8c35]::result::Result<rustc_index[79a26d8f822ca42d]::vec::IndexVec<rustc_target[44d477e4461259e2]::abi::VariantIdx, alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError> as core[63810368375d8c35]::iter::traits::collect::FromIterator<core[63810368375d8c35]::result::Result<alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>, rustc_middle[8a1cca0694b55532]::ty::layout::LayoutError>>>::from_iter<core[63810368375d8c35]::iter::adapters::map::Map<core[63810368375d8c35]::slice::iter::Iter<rustc_middle[8a1cca0694b55532]::ty::VariantDef>, rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached::{closure#5}>>::{closure#0}, rustc_index[79a26d8f822ca42d]::vec::IndexVec<rustc_target[44d477e4461259e2]::abi::VariantIdx, alloc[9c4954bf8315fe26]::vec::Vec<rustc_target[44d477e4461259e2]::abi::TyAndLayout<rustc_middle[8a1cca0694b55532]::ty::Ty>>>>
  27:        0x1226dc9cb - rustc_ty_utils[335bf625919b7879]::layout::layout_of_uncached
  28:        0x1226e6290 - rustc_ty_utils[335bf625919b7879]::layout::layout_of
  29:        0x123b77537 - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::get_query::<rustc_query_impl[e3f63d70ae94933f]::queries::layout_of, rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt>
  30:        0x123e5c721 - <rustc_query_impl[e3f63d70ae94933f]::Queries as rustc_middle[8a1cca0694b55532]::ty::query::QueryEngine>::layout_of
  31:        0x124854b58 - <rustc_transmute[32bd9b76539f9694]::layout::tree::rustc::LayoutSummary>::from_ty
  32:        0x124860ccd - <rustc_transmute[32bd9b76539f9694]::layout::tree::Tree<rustc_transmute[32bd9b76539f9694]::layout::rustc::Def, rustc_transmute[32bd9b76539f9694]::layout::rustc::Ref>>::from_ty
  33:        0x12486f9ae - <rustc_transmute[32bd9b76539f9694]::maybe_transmutable::MaybeTransmutableQuery<rustc_middle[8a1cca0694b55532]::ty::Ty, rustc_middle[8a1cca0694b55532]::ty::context::TyCtxt>>::map_layouts::<<rustc_transmute[32bd9b76539f9694]::maybe_transmutable::MaybeTransmutableQuery<rustc_middle[8a1cca0694b55532]::ty::Ty, rustc_middle[8a1cca0694b55532]::ty::context::TyCtxt>>::answer::{closure#0}, rustc_transmute[32bd9b76539f9694]::layout::tree::Tree<rustc_transmute[32bd9b76539f9694]::layout::rustc::Def, rustc_transmute[32bd9b76539f9694]::layout::rustc::Ref>>
  34:        0x124867f15 - <rustc_transmute[32bd9b76539f9694]::maybe_transmutable::MaybeTransmutableQuery<rustc_middle[8a1cca0694b55532]::ty::Ty, rustc_middle[8a1cca0694b55532]::ty::context::TyCtxt>>::answer
  35:        0x124864f01 - <rustc_transmute[32bd9b76539f9694]::rustc::TransmuteTypeEnv>::is_transmutable
  36:        0x1246a3416 - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::confirm_candidate
  37:        0x1246674d5 - <rustc_infer[8f07edc99fd14f09]::infer::InferCtxt>::probe::<core[63810368375d8c35]::result::Result<rustc_middle[8a1cca0694b55532]::traits::select::EvaluationResult, rustc_middle[8a1cca0694b55532]::traits::select::OverflowError>, <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluation_probe<<rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}>::{closure#0}>
  38:        0x1247faed3 - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluation_probe::<<rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_candidate::{closure#0}::{closure#0}>
  39:        0x1246b438b - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_candidate
  40:        0x124699810 - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_stack
  41:        0x1247ad3a4 - <rustc_query_system[9c2b8b59a29958f0]::dep_graph::graph::DepGraph<rustc_middle[8a1cca0694b55532]::dep_graph::dep_node::DepKind>>::with_anon_task::<rustc_middle[8a1cca0694b55532]::ty::context::TyCtxt, <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::in_task<<rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}::{closure#2}, core[63810368375d8c35]::result::Result<rustc_middle[8a1cca0694b55532]::traits::select::EvaluationResult, rustc_middle[8a1cca0694b55532]::traits::select::OverflowError>>::{closure#0}, core[63810368375d8c35]::result::Result<rustc_middle[8a1cca0694b55532]::traits::select::EvaluationResult, rustc_middle[8a1cca0694b55532]::traits::select::OverflowError>>
  42:        0x1247fb0cb - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::in_task::<<rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively::{closure#0}::{closure#2}, core[63810368375d8c35]::result::Result<rustc_middle[8a1cca0694b55532]::traits::select::EvaluationResult, rustc_middle[8a1cca0694b55532]::traits::select::OverflowError>>
  43:        0x1246b210b - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
  44:        0x1246af940 - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_predicate_recursively
  45:        0x124667f49 - <rustc_infer[8f07edc99fd14f09]::infer::InferCtxt>::probe::<core[63810368375d8c35]::result::Result<rustc_middle[8a1cca0694b55532]::traits::select::EvaluationResult, rustc_middle[8a1cca0694b55532]::traits::select::OverflowError>, <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluation_probe<<rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_root_obligation::{closure#0}>::{closure#0}>
  46:        0x12469945f - <rustc_trait_selection[96165f1221266323]::traits::select::SelectionContext>::evaluate_root_obligation
  47:        0x1235a16ce - rustc_traits[16c39305a736ba01]::evaluate_obligation::evaluate_obligation
  48:        0x123ea5ae6 - <rustc_query_system[9c2b8b59a29958f0]::query::config::QueryVTable<rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt, rustc_middle[8a1cca0694b55532]::infer::canonical::Canonical<rustc_middle[8a1cca0694b55532]::ty::ParamEnvAnd<rustc_middle[8a1cca0694b55532]::ty::Predicate>>, core[63810368375d8c35]::result::Result<rustc_middle[8a1cca0694b55532]::traits::select::EvaluationResult, rustc_middle[8a1cca0694b55532]::traits::select::OverflowError>>>::compute
  49:        0x123b3c971 - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::get_query::<rustc_query_impl[e3f63d70ae94933f]::queries::evaluate_obligation, rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt>
  50:        0x123e7f1a4 - <rustc_query_impl[e3f63d70ae94933f]::Queries as rustc_middle[8a1cca0694b55532]::ty::query::QueryEngine>::evaluate_obligation
  51:        0x124805917 - <rustc_infer[8f07edc99fd14f09]::infer::InferCtxt as rustc_trait_selection[96165f1221266323]::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  52:        0x124805a6f - <rustc_infer[8f07edc99fd14f09]::infer::InferCtxt as rustc_trait_selection[96165f1221266323]::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  53:        0x1247f64e8 - <rustc_trait_selection[96165f1221266323]::traits::fulfill::FulfillProcessor>::process_trait_obligation
  54:        0x1247f4e0f - <rustc_trait_selection[96165f1221266323]::traits::fulfill::FulfillProcessor as rustc_data_structures[8a51262431e07920]::obligation_forest::ObligationProcessor>::process_obligation
  55:        0x1246e69ed - <rustc_data_structures[8a51262431e07920]::obligation_forest::ObligationForest<rustc_trait_selection[96165f1221266323]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[96165f1221266323]::traits::fulfill::FulfillProcessor>
  56:        0x1247f2e42 - <rustc_trait_selection[96165f1221266323]::traits::fulfill::FulfillmentContext as rustc_infer[8f07edc99fd14f09]::traits::engine::TraitEngine>::select_where_possible
  57:        0x1227b4e73 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::select_obligations_where_possible::<rustc_hir_typeck[5ebbf62125a398cb]::typeck_with_fallback<rustc_hir_typeck[5ebbf62125a398cb]::typeck_const_arg::{closure#0}>::{closure#1}::{closure#2}>
  58:        0x1228289ff - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_argument_types
  59:        0x122807e58 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::confirm_builtin_call
  60:        0x1228058ad - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_call
  61:        0x12286c65f - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_expr_kind
  62:        0x12281564f - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  63:        0x12286b6e4 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  64:        0x12282ef02 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_stmt
  65:        0x1227b53df - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::with_breakable_ctxt::<<rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_block_with_expected::{closure#0}, ()>
  66:        0x12282f1e0 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_block_with_expected
  67:        0x12286ca41 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_expr_kind
  68:        0x12281564f - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  69:        0x12286b6e4 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  70:        0x122816997 - <rustc_hir_typeck[5ebbf62125a398cb]::fn_ctxt::FnCtxt>::check_return_expr
  71:        0x122777c47 - rustc_hir_typeck[5ebbf62125a398cb]::check::check_fn
  72:        0x1227c3710 - <rustc_hir_typeck[5ebbf62125a398cb]::inherited::InheritedBuilder>::enter::<rustc_hir_typeck[5ebbf62125a398cb]::typeck_with_fallback<rustc_hir_typeck[5ebbf62125a398cb]::typeck::{closure#0}>::{closure#1}, &rustc_middle[8a1cca0694b55532]::ty::context::TypeckResults>
  73:        0x1227c66c2 - rustc_hir_typeck[5ebbf62125a398cb]::typeck_with_fallback::<rustc_hir_typeck[5ebbf62125a398cb]::typeck::{closure#0}>
  74:        0x12292d3f9 - rustc_hir_typeck[5ebbf62125a398cb]::typeck
  75:        0x123a49bca - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::try_execute_query::<rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt, rustc_query_system[9c2b8b59a29958f0]::query::caches::DefaultCache<rustc_span[2af9326393a24b2a]::def_id::LocalDefId, &rustc_middle[8a1cca0694b55532]::ty::context::TypeckResults>>
  76:        0x123b75c7a - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::get_query::<rustc_query_impl[e3f63d70ae94933f]::queries::typeck, rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt>
  77:        0x123e4047f - <rustc_query_impl[e3f63d70ae94933f]::Queries as rustc_middle[8a1cca0694b55532]::ty::query::QueryEngine>::typeck
  78:        0x1228dd7df - <core[63810368375d8c35]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[8a51262431e07920]::sync::par_for_each_in<&[rustc_span[2af9326393a24b2a]::def_id::LocalDefId], <rustc_middle[8a1cca0694b55532]::hir::map::Map>::par_body_owners<rustc_hir_typeck[5ebbf62125a398cb]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}> as core[63810368375d8c35]::ops::function::FnOnce<()>>::call_once
  79:        0x1227717e9 - std[6a7b9961a507fa09]::panicking::try::<(), core[63810368375d8c35]::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures[8a51262431e07920]::sync::par_for_each_in<&[rustc_span[2af9326393a24b2a]::def_id::LocalDefId], <rustc_middle[8a1cca0694b55532]::hir::map::Map>::par_body_owners<rustc_hir_typeck[5ebbf62125a398cb]::typeck_item_bodies::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}>>
  80:        0x12292e713 - rustc_data_structures[8a51262431e07920]::sync::par_for_each_in::<&[rustc_span[2af9326393a24b2a]::def_id::LocalDefId], <rustc_middle[8a1cca0694b55532]::hir::map::Map>::par_body_owners<rustc_hir_typeck[5ebbf62125a398cb]::typeck_item_bodies::{closure#0}>::{closure#0}>
  81:        0x12292d22f - rustc_hir_typeck[5ebbf62125a398cb]::typeck_item_bodies
  82:        0x123a9efe3 - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::try_execute_query::<rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt, rustc_query_system[9c2b8b59a29958f0]::query::caches::DefaultCache<(), ()>>
  83:        0x123b3b779 - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::get_query::<rustc_query_impl[e3f63d70ae94933f]::queries::typeck_item_bodies, rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt>
  84:        0x123e3fe17 - <rustc_query_impl[e3f63d70ae94933f]::Queries as rustc_middle[8a1cca0694b55532]::ty::query::QueryEngine>::typeck_item_bodies
  85:        0x122aa37a8 - <rustc_session[3422556dcb6df88d]::session::Session>::time::<(), rustc_hir_analysis[e4fb2be97854ccf3]::check_crate::{closure#7}>
  86:        0x122a53f7e - rustc_hir_analysis[e4fb2be97854ccf3]::check_crate
  87:        0x120093e6a - rustc_interface[2b9f011c4a1d6882]::passes::analysis
  88:        0x123a935cd - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::try_execute_query::<rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt, rustc_query_system[9c2b8b59a29958f0]::query::caches::DefaultCache<(), core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>>
  89:        0x123b76029 - rustc_query_system[9c2b8b59a29958f0]::query::plumbing::get_query::<rustc_query_impl[e3f63d70ae94933f]::queries::analysis, rustc_query_impl[e3f63d70ae94933f]::plumbing::QueryCtxt>
  90:        0x123e1be17 - <rustc_query_impl[e3f63d70ae94933f]::Queries as rustc_middle[8a1cca0694b55532]::ty::query::QueryEngine>::analysis
  91:        0x11ff5f658 - <rustc_interface[2b9f011c4a1d6882]::passes::QueryContext>::enter::<rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>
  92:        0x11ff52ff8 - <rustc_interface[2b9f011c4a1d6882]::interface::Compiler>::enter::<rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}::{closure#2}, core[63810368375d8c35]::result::Result<core[63810368375d8c35]::option::Option<rustc_interface[2b9f011c4a1d6882]::queries::Linker>, rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>
  93:        0x11ff4a7db - rustc_span[2af9326393a24b2a]::with_source_map::<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, rustc_interface[2b9f011c4a1d6882]::interface::run_compiler<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  94:        0x11ff5109a - <scoped_tls[a4e3500caacc884c]::ScopedKey<rustc_span[2af9326393a24b2a]::SessionGlobals>>::set::<rustc_interface[2b9f011c4a1d6882]::interface::run_compiler<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}>::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>
  95:        0x11ff6b260 - std[6a7b9961a507fa09]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2b9f011c4a1d6882]::util::run_in_thread_pool_with_globals<rustc_interface[2b9f011c4a1d6882]::interface::run_compiler<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}>::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>
  96:        0x11ff4550d - std[6a7b9961a507fa09]::panicking::try::<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, core[63810368375d8c35]::panic::unwind_safe::AssertUnwindSafe<<std[6a7b9961a507fa09]::thread::Builder>::spawn_unchecked_<rustc_interface[2b9f011c4a1d6882]::util::run_in_thread_pool_with_globals<rustc_interface[2b9f011c4a1d6882]::interface::run_compiler<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}>::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  97:        0x11ff6cd90 - <<std[6a7b9961a507fa09]::thread::Builder>::spawn_unchecked_<rustc_interface[2b9f011c4a1d6882]::util::run_in_thread_pool_with_globals<rustc_interface[2b9f011c4a1d6882]::interface::run_compiler<core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>, rustc_driver[800c97195df9dd7a]::run_compiler::{closure#1}>::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[63810368375d8c35]::result::Result<(), rustc_errors[8c17e79fb1f0a5e4]::ErrorGuaranteed>>::{closure#1} as core[63810368375d8c35]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  98:        0x110692adb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdf7bfd1e0a7b9c83
  99:        0x1106a7d5f - std::sys::unix::thread::Thread::new::thread_start::h5ad5524ac09352ab
 100:     0x7ff81000f4e1 - __pthread_start

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.66.0-dev running on x86_64-apple-darwin

query stack during panic:
#0 [layout_of] computing layout of `test::U`
#1 [layout_of] computing layout of `test::S`
#2 [evaluate_obligation] evaluating trait selection obligation `u128: core::mem::transmutability::BikeshedIntrinsicFrom<test::S, assert::Context, core::mem::transmutability::Assume { alignment: false, lifetimes: false, safety: false, validity: false }>`
#3 [typeck] type-checking `test`
#4 [typeck_item_bodies] type-checking all item bodies
#5 [analysis] running analysis passes on this crate
end of query stack

Version

Built from 44fcfb0 (master some time yesterday, 2022-10-26)

config.toml

# Includes one of the default files in src/bootstrap/defaults
profile = "compiler"
changelog-seen = 2

[llvm]
download-ci-llvm = true     # Download a pre-built LLVM?
assertions = true           # LLVM assertions on?

[rust]
incremental = true          # Build rustc with incremental compilation?
debug-assertions = true

CC @jswrenn, who might understand the BikeshedIntrinsicFrom parts of the testcase

CC @RalfJung, who added the assertion

@jruderman jruderman added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 27, 2022
@RalfJung
Copy link
Member

RalfJung commented Oct 27, 2022

Yeah that's definitely an incorrect layout -- Scalar ABI types may not have padding.

This is unrelated to BikeshedIntrinsicFrom, the following already shows a bad layout:

#![feature(rustc_attrs)]

#[rustc_layout(debug)]
pub union U {
    a: [u16; 0],
    b: u8,
}

Cc @eddyb @oli-obk

@jruderman
Copy link
Contributor Author

Indeed, the assertion trips with that smaller input as well.

@oli-obk oli-obk added the A-layout Area: Memory layout of types label Oct 28, 2022
@eddyb
Copy link
Member

eddyb commented Nov 1, 2022

Yeah this is bad, basically another misuse of is_zst...

// If all non-ZST fields have the same ABI, forward this ABI
if optimize && !field.is_zst() {
// Discard valid range information and allow undef
let field_abi = match field.abi {
Abi::Scalar(x) => Abi::Scalar(x.to_union()),

(it should either be size=0 align=1 or check that the ZSTs being ignored don't raise the alignment beyond the single-non-ZST-field, but that's harder to get right)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-array Area: `[T; N]` A-layout Area: Memory layout of types C-bug Category: This is a bug. F-transmutability `#![feature(transmutability)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants