rust icon indicating copy to clipboard operation
rust copied to clipboard

ICE: `SizeSkeleton::compute` layout errored in `layout.rs`

Open cushionbadak opened this issue 1 year ago • 1 comments

Code

(hand-reduced)

#![feature(impl_trait_in_assoc_type)]

trait Trait: Sized {
    type Assoc2;
}

impl Trait for Bar {
    type Assoc2 = impl std::fmt::Debug;
}

struct Foo {
    field: <Bar as Trait>::Assoc2,
}

enum Bar {
    C = 42,
    D = 99,
}

static BAR: u8 = 42;

static FOO2: (&Foo, &<Bar as Trait>::Assoc2) =
    unsafe { (std::mem::transmute(&BAR), std::mem::transmute(&BAR)) };

fn main() {}
(original)

//! This test demonstrates a bug where we accidentally
//! detected opaque types in struct fields, but only if nested
//! in projections of another opaque type.

#![feature(impl_trait_in_assoc_type)]

struct Bar;

trait Trait: Sized {
    type Assoc2;
    type Assoc;
    fn foo() -> Self::Assoc;
}

impl Trait for Bar {
    type Assoc2 = impl std::fmt::Debug;
    type Assoc = impl Iterator<Item = Foo>;
    fn foo() -> Self::Assoc {
        vec![Foo { field: () }].into_iter()
        //~^ ERROR mismatched types
    }
}

struct Foo {
    field: <Bar as Trait>::Assoc2,
}

fn main() {}


//@ check-pass

enum Foo {
    A = 5,
    B = 42,
}
enum Bar {
    C = 42,
    D = 99,
}
#[repr(C)]
union Union {
    foo: &'static Foo,
    bar: &'static Bar,
    u8: &'static u8,
}
static BAR: u8 = 42;
static FOO: (&Foo, &Bar) = unsafe {(
    Union { u8: &BAR }.foo,
    Union { u8: &BAR }.bar,
)};

static FOO2: (&Foo, &<Bar as Trait>::Assoc2) = unsafe {(std::mem::transmute(&BAR), std::mem::transmute(&BAR))};

fn main() {}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (debd22da6 2024-05-29)
binary: rustc
commit-hash: debd22da66cfa97c74040ebf68e420672ac8560e
commit-date: 2024-05-29
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc

error: unconstrained opaque type
 --> r_layout_4A229A.rs:8:19
  |
8 |     type Assoc2 = impl std::fmt::Debug;
  |                   ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `Assoc2` must be used in combination with a concrete type within the same impl
Backtrace

error: internal compiler error: compiler/rustc_middle/src/ty/layout.rs:382:26: SizeSkeleton::compute(&Foo): layout errored (Unknown(Alias(Projection, AliasTy { args: [Foo], def_id: DefId(2:2141 ~ core[cbba]::ptr::metadata::Pointee::Metadata) }))), yet tail `<Bar as Trait>::Assoc2` is not a type parameter or a projection

thread 'rustc' panicked at compiler/rustc_middle/src/ty/layout.rs:382:26:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::layout::SizeSkeleton>::compute
   7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_transmutes
   8: rustc_hir_typeck::typeck
      [... omitted 1 frame ...]
   9: rustc_hir_analysis::check::check::check_item_type
  10: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
  11: rustc_middle::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
  12: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  13: rustc_hir_analysis::check_crate
  14: rustc_interface::passes::run_required_analyses
  15: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  16: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  17: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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 `/Volumes/T7/workspace/240529_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-30T06_54_29-96455.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `FOO2`
#1 [check_well_formed] checking that `FOO2` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Note

  • ICE location: compiler/rustc_middle/src/ty/layout.rs L382-L385 https://github.com/rust-lang/rust/blob/debd22da66cfa97c74040ebf68e420672ac8560e/compiler/rustc_middle/src/ty/layout.rs#L373-L385
  • Related ICE issues that points to identical ICE location:
    • #124031 (Fixed)
    • #109078 (Fixed)

cushionbadak avatar May 30 '24 07:05 cushionbadak

Regression in https://github.com/rust-lang-ci/rust/commit/069f6d7553b3ae77ee3af528020da952b05802ad The PR introducing the regression in this rollup is #123491: Fix ICE in eval_body_using_ecx

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30 regressed nightly: nightly-2024-04-17 searched commit range: https://github.com/rust-lang/rust/compare/ccfcd950b333fed046275dd8d54fe736ca498aa7...1cec373f65eb76e8e4b4d1847213cf3ec6c292b6 regressed commit: https://github.com/rust-lang/rust/commit/1dea922ea6e74f99a0e97de5cdb8174e4dea0444

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu Reproduce with:

cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 125758.rs

cushionbadak avatar Jun 12 '24 03:06 cushionbadak

Fixed by PR https://github.com/rust-lang/rust/pull/132090 which has sufficient test coverage.

fmease avatar May 22 '25 09:05 fmease