Skip to content
New issue

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

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

Already on GitHub? # to your account

ICE with dyn Pointee #112737

Closed
lukas-code opened this issue Jun 17, 2023 · 5 comments · Fixed by #113020
Closed

ICE with dyn Pointee #112737

lukas-code opened this issue Jun 17, 2023 · 5 comments · Fixed by #113020
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

@lukas-code
Copy link
Member

lukas-code commented Jun 17, 2023

Code

playground

#![feature(ptr_metadata)]
use core::ptr::Pointee;

fn bar(_: &dyn Pointee<Metadata = ()>) {}

fn main() {
    bar(&42)
}

Needs cargo build to reproduce, cargo check is not enough.

Meta

rustc --version --verbose:

1.72.0-nightly (2023-06-15 114fb86ca08cfa6a9908)

Error output

thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/compiler/rustc_middle/src/ty/layout.rs:792:21
Backtrace

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'assertion failed: i < this.fields.count()', /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/compiler/rustc_middle/src/ty/layout.rs:792:21
stack backtrace:
   0:     0x7f499b517c81 - std::backtrace_rs::backtrace::libunwind::trace::h82daf1b810610fdf
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f499b517c81 - std::backtrace_rs::backtrace::trace_unsynchronized::hdec42d25d2cbf75d
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f499b517c81 - std::sys_common::backtrace::_print_fmt::h56f88285da269ff2
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f499b517c81 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8331b72d831dbd9a
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f499b5786af - core::fmt::rt::Argument::fmt::h97ea199a440cce89
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/core/src/fmt/rt.rs:138:9
   5:     0x7f499b5786af - core::fmt::write::h654cffb485c72165
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f499b50af21 - std::io::Write::write_fmt::h9e865f2a74328539
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/io/mod.rs:1713:15
   7:     0x7f499b517a95 - std::sys_common::backtrace::_print::hed54e7a9861e5ec4
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f499b517a95 - std::sys_common::backtrace::print::hfc6c46dc154fda20
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f499b51a777 - std::panicking::default_hook::{{closure}}::h8bffa685abb660fb
  10:     0x7f499b51a564 - std::panicking::default_hook::hf865d86cb04ccd82
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/panicking.rs:288:9
  11:     0x7f499e74cfcb - <rustc_driver_impl[4d437c7ed2d29c60]::install_ice_hook::{closure#0} as core[3efadbf7a762e3bc]::ops::function::FnOnce<(&core[3efadbf7a762e3bc]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f499b51aebd - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he7ea672ae0d74d90
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/alloc/src/boxed.rs:1999:9
  13:     0x7f499b51aebd - std::panicking::rust_panic_with_hook::h9fb086b9aa0459a7
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/panicking.rs:709:13
  14:     0x7f499b51ac11 - std::panicking::begin_panic_handler::{{closure}}::h4ead90f8cc45e817
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/panicking.rs:595:13
  15:     0x7f499b5180b6 - std::sys_common::backtrace::__rust_end_short_backtrace::hadf4d699adbfd869
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7f499b51a9a2 - rust_begin_unwind
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/panicking.rs:593:5
  17:     0x7f499b574933 - core::panicking::panic_fmt::h9261297c59c756d0
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/core/src/panicking.rs:67:14
  18:     0x7f499b5749c3 - core::panicking::panic::hfa1ba9901b18a524
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/core/src/panicking.rs:117:5
  19:     0x7f499d10d843 - <rustc_middle[8f75f41b17d1d05e]::ty::Ty as rustc_target[1e542b4f8e0c12a0]::abi::TyAbiInterface<_>>::ty_and_layout_field::field_ty_or_layout::<rustc_codegen_llvm[b68db3b4a85e26cf]::context::CodegenCx>
  20:     0x7f499d10b7a9 - <rustc_middle[8f75f41b17d1d05e]::ty::Ty as rustc_target[1e542b4f8e0c12a0]::abi::TyAbiInterface<rustc_codegen_llvm[b68db3b4a85e26cf]::context::CodegenCx>>::ty_and_layout_field
  21:     0x7f499ce294c2 - rustc_codegen_llvm[b68db3b4a85e26cf]::debuginfo::metadata::type_map::build_type_with_children::<rustc_codegen_llvm[b68db3b4a85e26cf]::debuginfo::metadata::build_pointer_or_reference_di_node::{closure#0}, for<'a, 'b, 'c> fn(&'a rustc_codegen_llvm[b68db3b4a85e26cf]::context::CodegenCx<'b, 'c>) -> smallvec[7664e1a0fad746fd]::SmallVec<[&'b rustc_codegen_llvm[b68db3b4a85e26cf]::llvm_::ffi::Metadata; 16usize]>>
  22:     0x7f499ce13433 - rustc_codegen_llvm[b68db3b4a85e26cf]::debuginfo::metadata::type_di_node
  23:     0x7f499ce0d110 - <rustc_codegen_llvm[b68db3b4a85e26cf]::context::CodegenCx as rustc_codegen_ssa[355403ed8d7af1a4]::traits::debuginfo::DebugInfoMethods>::dbg_scope_fn
  24:     0x7f499d0b87e3 - rustc_codegen_ssa[355403ed8d7af1a4]::mir::codegen_mir::<rustc_codegen_llvm[b68db3b4a85e26cf]::builder::Builder>
  25:     0x7f499dd4719a - rustc_codegen_llvm[b68db3b4a85e26cf]::base::compile_codegen_unit::module_codegen
  26:     0x7f499dd45155 - rustc_codegen_llvm[b68db3b4a85e26cf]::base::compile_codegen_unit
  27:     0x7f499dde80a3 - rustc_codegen_ssa[355403ed8d7af1a4]::base::codegen_crate::<rustc_codegen_llvm[b68db3b4a85e26cf]::LlvmCodegenBackend>
  28:     0x7f499dde799f - <rustc_codegen_llvm[b68db3b4a85e26cf]::LlvmCodegenBackend as rustc_codegen_ssa[355403ed8d7af1a4]::traits::backend::CodegenBackend>::codegen_crate
  29:     0x7f499d9f1282 - <rustc_session[1c7162010f2e4154]::session::Session>::time::<alloc[8fbf08a1b9e0d7e]::boxed::Box<dyn core[3efadbf7a762e3bc]::any::Any>, rustc_interface[f58d22d8c6052dc9]::passes::start_codegen::{closure#0}>
  30:     0x7f499d9f0dfb - rustc_interface[f58d22d8c6052dc9]::passes::start_codegen
  31:     0x7f499d9ebd4d - <rustc_middle[8f75f41b17d1d05e]::ty::context::GlobalCtxt>::enter::<<rustc_interface[f58d22d8c6052dc9]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[3efadbf7a762e3bc]::result::Result<alloc[8fbf08a1b9e0d7e]::boxed::Box<dyn core[3efadbf7a762e3bc]::any::Any>, rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>
  32:     0x7f499d9eb1bd - <rustc_interface[f58d22d8c6052dc9]::queries::Queries>::ongoing_codegen
  33:     0x7f499d9ea74f - <rustc_interface[f58d22d8c6052dc9]::interface::Compiler>::enter::<rustc_driver_impl[4d437c7ed2d29c60]::run_compiler::{closure#1}::{closure#2}, core[3efadbf7a762e3bc]::result::Result<core[3efadbf7a762e3bc]::option::Option<rustc_interface[f58d22d8c6052dc9]::queries::Linker>, rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>
  34:     0x7f499d9e8674 - rustc_span[e7e5e19cf1bf3814]::set_source_map::<core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>, rustc_interface[f58d22d8c6052dc9]::interface::run_compiler<core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>, rustc_driver_impl[4d437c7ed2d29c60]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  35:     0x7f499d9e8259 - <scoped_tls[ebdb442d5c38bfc1]::ScopedKey<rustc_span[e7e5e19cf1bf3814]::SessionGlobals>>::set::<rustc_interface[f58d22d8c6052dc9]::interface::run_compiler<core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>, rustc_driver_impl[4d437c7ed2d29c60]::run_compiler::{closure#1}>::{closure#0}, core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>
  36:     0x7f499d9e7856 - std[7b0343ef0fef68d6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f58d22d8c6052dc9]::util::run_in_thread_pool_with_globals<rustc_interface[f58d22d8c6052dc9]::interface::run_compiler<core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>, rustc_driver_impl[4d437c7ed2d29c60]::run_compiler::{closure#1}>::{closure#0}, core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>
  37:     0x7f499d9e7605 - <<std[7b0343ef0fef68d6]::thread::Builder>::spawn_unchecked_<rustc_interface[f58d22d8c6052dc9]::util::run_in_thread_pool_with_globals<rustc_interface[f58d22d8c6052dc9]::interface::run_compiler<core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>, rustc_driver_impl[4d437c7ed2d29c60]::run_compiler::{closure#1}>::{closure#0}, core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3efadbf7a762e3bc]::result::Result<(), rustc_span[e7e5e19cf1bf3814]::ErrorGuaranteed>>::{closure#1} as core[3efadbf7a762e3bc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7f499b5253b5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h43f429f25133bc4e
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/alloc/src/boxed.rs:1985:9
  39:     0x7f499b5253b5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h14864620f22f4260
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/alloc/src/boxed.rs:1985:9
  40:     0x7f499b5253b5 - std::sys::unix::thread::Thread::new::thread_start::h5ddaad0e16dc53a2
                               at /rustc/114fb86ca08cfa6a99087e0f0bc264d03590dc37/library/std/src/sys/unix/thread.rs:108:17
  41:     0x7f499b3f2609 - start_thread
  42:     0x7f499b315133 - clone
  43:                0x0 - <unknown>

error: 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.72.0-nightly (114fb86ca 2023-06-15) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `playground` (bin "playground")

@lukas-code lukas-code 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 Jun 17, 2023
@lukas-code
Copy link
Member Author

related: This shouldn't compile, but it does:

#![feature(ptr_metadata)]
use core::ptr::Pointee;

fn foo(_: &(impl Pointee<Metadata = ()> + ?Sized)) {}

fn bar(x: &dyn Pointee<Metadata = ()>) {
    foo(x)
}

@compiler-errors
Copy link
Member

compiler-errors commented Jun 17, 2023

This is definitely fixed by #112320, I'll add some tests and link this one.

@compiler-errors compiler-errors self-assigned this Jun 17, 2023
@compiler-errors compiler-errors added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Jun 22, 2023
@compiler-errors compiler-errors removed their assignment Jun 22, 2023
@compiler-errors
Copy link
Member

whoops, forgot to add tests. marking as E-needs-test

@AnbyKatz
Copy link
Contributor

I wouldn't mind giving this one a try if I'm understanding it correctly. Just add tests for the changes made in #112320, should the original code at the top of this issue compile now and the code in the next comment, shouldn't compile?

@compiler-errors
Copy link
Member

@AnthonyKalaitzis: correct. Please put some care into which subdirectory in tests/ui these tests are placed, and make sure they're given at least somewhat descriptive names (i.e. not issue-112737.rs or anything like that).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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
Development

Successfully merging a pull request may close this issue.

3 participants