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

ICE: SizeSkeleton::compute layout errored in layout.rs #125758

Open
cushionbadak opened this issue May 30, 2024 · 1 comment
Open

ICE: SizeSkeleton::compute layout errored in layout.rs #125758

cushionbadak opened this issue May 30, 2024 · 1 comment
Assignees
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

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

@cushionbadak cushionbadak 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 May 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2024
@jieyouxu jieyouxu added A-layout Area: Memory layout of types S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 4, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 9, 2024
@cushionbadak
Copy link
Author

cushionbadak commented Jun 12, 2024

Regression in rust-lang-ci@069f6d7
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: ccfcd95...1cec373
regressed commit: 1dea922

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

@workingjubilee workingjubilee self-assigned this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. F-impl_trait_in_assoc_type `#![feature(impl_trait_in_assoc_type)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants