Skip to content

ICE: failed to get layout #111176

Closed
Closed
@matthiaskrgr

Description

@matthiaskrgr

Code

use std::mem;

pub struct S<T: Tr> {
    pub f: <T as Tr>::I,
}

pub trait Tr {
   type I: Tr;
}

impl<T: Tr> Tr for S<T> {
    type I = S<S<T>>;
}

impl Tr for () {
    type I = ();
}

fn foo<T: Tr>() -> usize {
    mem::size_of::<S<T>>()
}

fn main() {
    println!("{}", foo::<S<()>>());
}

Meta

rustc --version --verbose:

<version>

Error output

<output>
Backtrace

error[E0391]: cycle detected when computing layout of `S<S<()>>`
  |
  = note: ...which requires computing layout of `<S<()> as Tr>::I`...
  = note: ...which again requires computing layout of `S<S<()>>`, completing the cycle

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:974:13: failed to get layout for `S<S<()>>`: a cycle occurred during layout computation

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/compiler/rustc_errors/src/lib.rs:994:33
stack backtrace:
   0:     0x7f4c65369441 - std::backtrace_rs::backtrace::libunwind::trace::hb9be772067563b53
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f4c65369441 - std::backtrace_rs::backtrace::trace_unsynchronized::h031da30dc183647f
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f4c65369441 - std::sys_common::backtrace::_print_fmt::h71eced90df8827aa
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f4c65369441 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hae72971f9b1c0375
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f4c653ca0df - core::fmt::rt::Argument::fmt::h8155c503d36c9b86
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/core/src/fmt/rt.rs:138:9
   5:     0x7f4c653ca0df - core::fmt::write::hbbb4251c2513c3ef
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f4c6535c591 - std::io::Write::write_fmt::hdcff7ff4dad8c59b
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/io/mod.rs:1712:15
   7:     0x7f4c65369255 - std::sys_common::backtrace::_print::hb8bd80d5dffe8016
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f4c65369255 - std::sys_common::backtrace::print::hd57b6e007b7d9859
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f4c6536bee7 - std::panicking::default_hook::{{closure}}::h92b5b1db37900f49
  10:     0x7f4c6536bcd4 - std::panicking::default_hook::h33b32947a165ebfe
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/panicking.rs:288:9
  11:     0x7f4c685707b5 - <rustc_driver_impl[2c3cd2b22615ac74]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[65ac48eb02ee08bd]::ops::function::FnOnce<(&core[65ac48eb02ee08bd]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f4c6536c607 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h65038aad28115701
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/alloc/src/boxed.rs:1999:9
  13:     0x7f4c6536c607 - std::panicking::rust_panic_with_hook::h6818a1a7c65e9cdd
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/panicking.rs:695:13
  14:     0x7f4c68402f91 - std[7223d5cfbaf62610]::panicking::begin_panic::<rustc_errors[eb6afbb30a1cd2c3]::ExplicitBug>::{closure#0}
  15:     0x7f4c68401c26 - std[7223d5cfbaf62610]::sys_common::backtrace::__rust_end_short_backtrace::<std[7223d5cfbaf62610]::panicking::begin_panic<rustc_errors[eb6afbb30a1cd2c3]::ExplicitBug>::{closure#0}, !>
  16:     0x7f4c68401ac6 - std[7223d5cfbaf62610]::panicking::begin_panic::<rustc_errors[eb6afbb30a1cd2c3]::ExplicitBug>
  17:     0x7f4c683f6802 - <rustc_errors[eb6afbb30a1cd2c3]::HandlerInner>::span_bug::<rustc_span[418048bff763fbc6]::span_encoding::Span, alloc[1303c5f908d1c3f4]::string::String>
  18:     0x7f4c683f5f46 - <rustc_errors[eb6afbb30a1cd2c3]::Handler>::span_bug::<rustc_span[418048bff763fbc6]::span_encoding::Span, alloc[1303c5f908d1c3f4]::string::String>
  19:     0x7f4c683faedd - rustc_middle[faa0e51d0d5710e5]::util::bug::opt_span_bug_fmt::<rustc_span[418048bff763fbc6]::span_encoding::Span>::{closure#0}
  20:     0x7f4c683faf0a - rustc_middle[faa0e51d0d5710e5]::ty::context::tls::with_opt::<rustc_middle[faa0e51d0d5710e5]::util::bug::opt_span_bug_fmt<rustc_span[418048bff763fbc6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f4c683faaba - rustc_middle[faa0e51d0d5710e5]::ty::context::tls::with_context_opt::<rustc_middle[faa0e51d0d5710e5]::ty::context::tls::with_opt<rustc_middle[faa0e51d0d5710e5]::util::bug::opt_span_bug_fmt<rustc_span[418048bff763fbc6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f4c66d96d44 - rustc_middle[faa0e51d0d5710e5]::util::bug::span_bug_fmt::<rustc_span[418048bff763fbc6]::span_encoding::Span>
  23:     0x7f4c6840d400 - <rustc_codegen_llvm[f6e646cf3297fbe4]::context::CodegenCx as rustc_middle[faa0e51d0d5710e5]::ty::layout::LayoutOfHelpers>::handle_layout_err
  24:     0x7f4c6840d312 - <rustc_codegen_llvm[f6e646cf3297fbe4]::context::CodegenCx as rustc_middle[faa0e51d0d5710e5]::ty::layout::LayoutOf>::spanned_layout_of::{closure#0}
  25:     0x7f4c66db0a4e - <rustc_codegen_llvm[f6e646cf3297fbe4]::context::CodegenCx as rustc_middle[faa0e51d0d5710e5]::ty::layout::LayoutOf>::spanned_layout_of
  26:     0x7f4c66da905f - <rustc_codegen_ssa[ec866eaa3e7fa1d8]::mir::FunctionCx<rustc_codegen_llvm[f6e646cf3297fbe4]::builder::Builder>>::codegen_rvalue_operand
  27:     0x7f4c66d756bc - rustc_codegen_ssa[ec866eaa3e7fa1d8]::mir::codegen_mir::<rustc_codegen_llvm[f6e646cf3297fbe4]::builder::Builder>
  28:     0x7f4c67a12312 - rustc_codegen_llvm[f6e646cf3297fbe4]::base::compile_codegen_unit::module_codegen
  29:     0x7f4c67a11160 - rustc_codegen_llvm[f6e646cf3297fbe4]::base::compile_codegen_unit
  30:     0x7f4c67c55486 - rustc_codegen_ssa[ec866eaa3e7fa1d8]::base::codegen_crate::<rustc_codegen_llvm[f6e646cf3297fbe4]::LlvmCodegenBackend>
  31:     0x7f4c67c54d52 - <rustc_codegen_llvm[f6e646cf3297fbe4]::LlvmCodegenBackend as rustc_codegen_ssa[ec866eaa3e7fa1d8]::traits::backend::CodegenBackend>::codegen_crate
  32:     0x7f4c67803e90 - rustc_interface[145311d2418df64f]::passes::start_codegen
  33:     0x7f4c677fef07 - <rustc_middle[faa0e51d0d5710e5]::ty::context::GlobalCtxt>::enter::<<rustc_interface[145311d2418df64f]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[65ac48eb02ee08bd]::result::Result<alloc[1303c5f908d1c3f4]::boxed::Box<dyn core[65ac48eb02ee08bd]::any::Any>, rustc_span[418048bff763fbc6]::ErrorGuaranteed>>
  34:     0x7f4c677fe4e8 - <rustc_interface[145311d2418df64f]::queries::Queries>::ongoing_codegen
  35:     0x7f4c677fdc23 - <rustc_interface[145311d2418df64f]::interface::Compiler>::enter::<rustc_driver_impl[2c3cd2b22615ac74]::run_compiler::{closure#1}::{closure#2}, core[65ac48eb02ee08bd]::result::Result<core[65ac48eb02ee08bd]::option::Option<rustc_interface[145311d2418df64f]::queries::Linker>, rustc_span[418048bff763fbc6]::ErrorGuaranteed>>
  36:     0x7f4c677fb38f - std[7223d5cfbaf62610]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[145311d2418df64f]::util::run_in_thread_pool_with_globals<rustc_interface[145311d2418df64f]::interface::run_compiler<core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>, rustc_driver_impl[2c3cd2b22615ac74]::run_compiler::{closure#1}>::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>
  37:     0x7f4c67e59e9e - <<std[7223d5cfbaf62610]::thread::Builder>::spawn_unchecked_<rustc_interface[145311d2418df64f]::util::run_in_thread_pool_with_globals<rustc_interface[145311d2418df64f]::interface::run_compiler<core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>, rustc_driver_impl[2c3cd2b22615ac74]::run_compiler::{closure#1}>::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>::{closure#1} as core[65ac48eb02ee08bd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7f4c65376ad5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haa143886c5139467
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/alloc/src/boxed.rs:1985:9
  39:     0x7f4c65376ad5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha0b7575cc93abe25
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/alloc/src/boxed.rs:1985:9
  40:     0x7f4c65376ad5 - std::sys::unix::thread::Thread::new::thread_start::ha9600bcb75fadfd8
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys/unix/thread.rs:108:17
  41:     0x7f4c65112bb5 - <unknown>
  42:     0x7f4c65194d90 - <unknown>
  43:                0x0 - <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: rustc 1.71.0-nightly (129195f57 2023-05-04) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions