rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.57k stars 12.74k forks source link

internal compiler error: failed to get layout #114324

Closed iamanonymouscs closed 1 year ago

iamanonymouscs commented 1 year ago

Code

use std::mem;

pub struct MyStruct<T: MyTrait> {
pub field: <T as MyTrait>::Inner,
}

pub trait MyTrait {
type Inner: MyTrait;
}

impl<T: MyTrait> MyTrait for MyStruct<T> {
type Inner = MyStruct<MyStruct<T>>;
}

impl MyTrait for () {
type Inner = ();
}

fn calculate_size<T: MyTrait>() -> usize {
mem::size_of::<MyStruct<T>>()
}

fn main() {
println!("{}", calculate_size::<MyStruct<()>>());
}

Meta

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.73.0-nightly (db7ff98a7 2023-07-31)
binary: rustc
commit-hash: db7ff98a72f3e742b641f9cb16d0e8c285e87e9b
commit-date: 2023-07-31
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

error[E0391]: cycle detected when computing layout of `MyStruct<MyStruct<()>>`
  |
  = note: ...which requires computing layout of `<MyStruct<()> as MyTrait>::Inner`...
  = note: ...which again requires computing layout of `MyStruct<MyStruct<()>>`, completing the cycle
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:1005:13: failed to get layout for `MyStruct<MyStruct<()>>`: Cycle
Backtrace

``` thread 'rustc' panicked at 'Box', /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/compiler/rustc_errors/src/lib.rs:989:33 stack backtrace: 0: 0x7f1375b674bc - std::backtrace_rs::backtrace::libunwind::trace::h00560e9152510f67 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f1375b674bc - std::backtrace_rs::backtrace::trace_unsynchronized::h0f27c3665dd0a867 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f1375b674bc - std::sys_common::backtrace::_print_fmt::h5dba0ff3e06fa698 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/sys_common/backtrace.rs:67:5 3: 0x7f1375b674bc - ::fmt::h4debeea1996f535b at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f1375bcdbac - core::fmt::rt::Argument::fmt::h1e53d9bbf5a265dd at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/core/src/fmt/rt.rs:138:9 5: 0x7f1375bcdbac - core::fmt::write::hcb86202702aeaf68 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/core/src/fmt/mod.rs:1094:21 6: 0x7f1375b59b1e - std::io::Write::write_fmt::h6b056feb2ab827f8 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/io/mod.rs:1714:15 7: 0x7f1375b672a5 - std::sys_common::backtrace::_print::h63c494f55c85c02e at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f1375b672a5 - std::sys_common::backtrace::print::h0d84953923cd4383 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f1375b6a3fa - std::panicking::panic_hook_with_disk_dump::{{closure}}::h0ded106e3e100970 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/panicking.rs:278:22 10: 0x7f1375b6a093 - std::panicking::panic_hook_with_disk_dump::h80545efc2b457190 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/panicking.rs:312:9 11: 0x7f1378e0e2e9 - rustc_driver_impl[953ac255d00f3c7f]::install_ice_hook::{closure#0} 12: 0x7f1375b6aca0 - as core::ops::function::Fn>::call::h005d394de554c94e at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/alloc/src/boxed.rs:2021:9 13: 0x7f1375b6aca0 - std::panicking::rust_panic_with_hook::ha35d072680b6716b at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/panicking.rs:733:13 14: 0x7f1378cb71c1 - std[cfe24ee53075a1e5]::panicking::begin_panic::::{closure#0} 15: 0x7f1378cb61a6 - std[cfe24ee53075a1e5]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7f1378c77676 - std[cfe24ee53075a1e5]::panicking::begin_panic:: 17: 0x7f1378cbb5be - ::span_bug:: 18: 0x7f1378cbb3cf - ::span_bug:: 19: 0x7f1378ca662d - rustc_middle[23eac342ec155d27]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f1378ca665a - rustc_middle[23eac342ec155d27]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f1378ca5f28 - rustc_middle[23eac342ec155d27]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f137779a464 - rustc_middle[23eac342ec155d27]::util::bug::span_bug_fmt:: 23: 0x7f1378cd7a3b - ::handle_layout_err 24: 0x7f1378cd754a - ::spanned_layout_of::{closure#0} 25: 0x7f13777b2355 - >::codegen_rvalue_operand 26: 0x7f137777e373 - rustc_codegen_ssa[1e93ac4b57e61c57]::mir::codegen_mir:: 27: 0x7f1377f66060 - rustc_codegen_llvm[fbffa82a3d5a30ab]::base::compile_codegen_unit::module_codegen 28: 0x7f1377f63c99 - rustc_codegen_llvm[fbffa82a3d5a30ab]::base::compile_codegen_unit 29: 0x7f1377f609d4 - rustc_codegen_ssa[1e93ac4b57e61c57]::base::codegen_crate:: 30: 0x7f1377f603cb - ::codegen_crate 31: 0x7f1378090f02 - ::time::, rustc_interface[22a5bdce7fd6e981]::passes::start_codegen::{closure#0}> 32: 0x7f1378090a4b - rustc_interface[22a5bdce7fd6e981]::passes::start_codegen 33: 0x7f137808affa - ::enter::<::ongoing_codegen::{closure#0}, core[24a2ba61524efef7]::result::Result, rustc_span[c85fb125fe1c027]::ErrorGuaranteed>> 34: 0x7f137808a033 - ::enter::, rustc_span[c85fb125fe1c027]::ErrorGuaranteed>> 35: 0x7f13780830a8 - std[cfe24ee53075a1e5]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[953ac255d00f3c7f]::run_compiler::{closure#1}>::{closure#0}, core[24a2ba61524efef7]::result::Result<(), rustc_span[c85fb125fe1c027]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[24a2ba61524efef7]::result::Result<(), rustc_span[c85fb125fe1c027]::ErrorGuaranteed>> 36: 0x7f137808282e - <::spawn_unchecked_, rustc_driver_impl[953ac255d00f3c7f]::run_compiler::{closure#1}>::{closure#0}, core[24a2ba61524efef7]::result::Result<(), rustc_span[c85fb125fe1c027]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[24a2ba61524efef7]::result::Result<(), rustc_span[c85fb125fe1c027]::ErrorGuaranteed>>::{closure#1} as core[24a2ba61524efef7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 37: 0x7f1375b75445 - as core::ops::function::FnOnce>::call_once::h021e65daf5fb4ee0 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/alloc/src/boxed.rs:2007:9 38: 0x7f1375b75445 - as core::ops::function::FnOnce>::call_once::h7dda744b120f2954 at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/alloc/src/boxed.rs:2007:9 39: 0x7f1375b75445 - std::sys::unix::thread::Thread::new::thread_start::hcffeb1067f9b6dfb at /rustc/db7ff98a72f3e742b641f9cb16d0e8c285e87e9b/library/std/src/sys/unix/thread.rs:108:17 40: 0x7f1375a35609 - start_thread 41: 0x7f137595a133 - clone 42: 0x0 - 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 attach the file at `/home/rustc-ice-2023-08-01T04:57:52.97289344Z-227.txt` to your bug report 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`. ```

matthiaskrgr commented 1 year ago

probably duplicate of https://github.com/rust-lang/rust/issues/111176

Luk-ESC commented 1 year ago

This got resolved with #111580. On nightly this doesn't cause an ICE anymore but an error, as intended.

lqd commented 1 year ago

great, closing.