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 expect Adt for unnamed field #121263

Open
matthiaskrgr opened this issue Feb 18, 2024 · 5 comments · May be fixed by #121270
Open

ICE expect Adt for unnamed field #121263

matthiaskrgr opened this issue Feb 18, 2024 · 5 comments · May be fixed by #121270
Assignees
Labels
C-bug Category: This is a bug. F-unnamed_fields `#![feature(unnamed_fields)]` 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 18, 2024

auto-reduced (treereduce-rust):

#[repr(C)]
#[repr(C)]
#[derive(Debug)]
struct L {
    _: i32,
    _: MyI32,
    _: BadEnum,
}
original code

original:

//@ aux-build:dep.rs

// test for #121151

#![allow(incomplete_features)]
#![feature(unnamed_fields)]

extern crate dep;

#[repr(C)]
struct A {
    a: u8,
}

enum BadEnum {
    A,
    B,
}

#[repr(C)]
enum BadEnum2 {
    A,
    B,
}

type MyStruct = A;
type MyI32 = i32;

#[derive(Debug)]
struct L {
    _: i32, //~ ERROR unnamed fields can only have struct or union types
    _: MyI32, //~ ERROR unnamed fields can only have struct or union types
    _: BadEnum, //~ ERROR unnamed fields can only have struct or union types
    _: BadEnum2, //~ ERROR unnamed fields can only have struct or union types
    _: MyStruct,
    _: dep::BadStruct, //~ ERROR named type of unnamed field must have `#[repr(C)]` representation
    _: dep::BadEnum, //~ ERROR unnamed fields can only have struct or union types
    _: dep::BadEnum2, //~ ERROR unnamed fields can only have struct or union types
    _: dep::BadAlias, //~ ERROR unnamed fields can only have struct or union types
    _: dep::GoodAlias,
    _: dep::GoodStruct,
}

fn main() {}

Version information

rustc 1.78.0-nightly (23a3d777c 2024-02-18)
binary: rustc
commit-hash: 23a3d777c8a95715977608c827de63e7738fa228
commit-date: 2024-02-18
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0412]: cannot find type `MyI32` in this scope
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:6:8
  |
6 |     _: MyI32,
  |        ^^^^^ not found in this scope

error[E0412]: cannot find type `BadEnum` in this scope
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:7:8
  |
7 |     _: BadEnum,
  |        ^^^^^^^ not found in this scope

error[E0658]: unnamed fields are not yet fully implemented
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:5:5
  |
5 |     _: i32,
  |     ^
  |
  = note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
  = help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
  = note: this compiler was built on 2024-02-18; consider upgrading it if it is out of date

error[E0658]: unnamed fields are not yet fully implemented
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:6:5
  |
6 |     _: MyI32,
  |     ^
  |
  = note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
  = help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
  = note: this compiler was built on 2024-02-18; consider upgrading it if it is out of date

error[E0658]: unnamed fields are not yet fully implemented
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:7:5
  |
7 |     _: BadEnum,
  |     ^
  |
  = note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information
  = help: add `#![feature(unnamed_fields)]` to the crate attributes to enable
  = note: this compiler was built on 2024-02-18; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:8:2
  |
8 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs`

error: unnamed fields can only have struct or union types
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:5:5
  |
5 |     _: i32,
  |     ^^^^^^

error: unnamed fields can only have struct or union types
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:6:5
  |
6 |     _: MyI32,
  |     ^^^^^^^^

error: unnamed fields can only have struct or union types
 --> /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:7:5
  |
7 |     _: BadEnum,
  |     ^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect.rs:797:49:
expect Adt for unnamed field
stack backtrace:
   0:     0x7fee0be69c66 - std::backtrace_rs::backtrace::libunwind::trace::h4068c8c17ac2de87
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fee0be69c66 - std::backtrace_rs::backtrace::trace_unsynchronized::h4580377505c55c9d
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fee0be69c66 - std::sys_common::backtrace::_print_fmt::hee20b5c666b58216
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fee0be69c66 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha4ad425535c00d08
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fee0beba28c - core::fmt::rt::Argument::fmt::h0839985d975a9d4b
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/core/src/fmt/rt.rs:142:9
   5:     0x7fee0beba28c - core::fmt::write::h90514da5b3f483e8
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fee0be5d60f - std::io::Write::write_fmt::h203f53b20388cfaa
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/io/mod.rs:1846:15
   7:     0x7fee0be69a14 - std::sys_common::backtrace::_print::h2f913a97733fa87b
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fee0be69a14 - std::sys_common::backtrace::print::h99f997f501c28480
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fee0be6c75b - std::panicking::default_hook::{{closure}}::he40fc06be54c384c
  10:     0x7fee0be6c4a9 - std::panicking::default_hook::h3571ea97747a580b
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/panicking.rs:292:9
  11:     0x7fee08c1e53c - std[215f9b68e873486f]::panicking::update_hook::<alloc[be5ff64dafe89243]::boxed::Box<rustc_driver_impl[ff846aa700ca0662]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fee0be6cec0 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h1e7c347d2e3bb2ce
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/alloc/src/boxed.rs:2030:9
  13:     0x7fee0be6cec0 - std::panicking::rust_panic_with_hook::haa768baff731dd68
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/panicking.rs:785:13
  14:     0x7fee0be6cc02 - std::panicking::begin_panic_handler::{{closure}}::hd076226a093426e6
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/panicking.rs:659:13
  15:     0x7fee0be6a146 - std::sys_common::backtrace::__rust_end_short_backtrace::h5f6128247f895926
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7fee0be6c934 - rust_begin_unwind
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/panicking.rs:647:5
  17:     0x7fee0beb6795 - core::panicking::panic_fmt::ha3b35be81f6e71fb
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/core/src/panicking.rs:72:14
  18:     0x7fee0beb6961 - core::panicking::panic_display::h0bc330b58b3ed652
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/core/src/panicking.rs:196:5
  19:     0x7fee0beb654b - core::panicking::panic_str::hb3484e129df4bb42
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/core/src/panicking.rs:171:5
  20:     0x7fee0beb654b - core::option::expect_failed::h7f457612ea919a01
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/core/src/option.rs:1993:5
  21:     0x7fee0a6363f2 - rustc_hir_analysis[6e9724bb0c265329]::collect::find_field
  22:     0x7fee0a63619f - rustc_query_impl[40f1c38ec7f0fe8b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::find_field::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1a787087d433af5e]::query::erase::Erased<[u8; 4usize]>>
  23:     0x7fee0a636161 - <rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::find_field::dynamic_query::{closure#2} as core[694f794f8b0567e]::ops::function::FnOnce<(rustc_middle[1a787087d433af5e]::ty::context::TyCtxt, (rustc_span[e2cb3716bc025bf2]::def_id::DefId, rustc_span[e2cb3716bc025bf2]::symbol::Ident))>>::call_once
  24:     0x7fee0a635550 - rustc_query_system[7a228a9eb6f8b90e]::query::plumbing::try_execute_query::<rustc_query_impl[40f1c38ec7f0fe8b]::DynamicConfig<rustc_query_system[7a228a9eb6f8b90e]::query::caches::DefaultCache<(rustc_span[e2cb3716bc025bf2]::def_id::DefId, rustc_span[e2cb3716bc025bf2]::symbol::Ident), rustc_middle[1a787087d433af5e]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[40f1c38ec7f0fe8b]::plumbing::QueryCtxt, false>
  25:     0x7fee0a6352a2 - rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::find_field::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7fee0a1275ae - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_field
  27:     0x7fee0a87bbbc - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7fee0a87b9b0 - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7fee0a927394 - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_argument_types
  30:     0x7fee0a7315af - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_call
  31:     0x7fee0a87ad6c - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7fee0a36d609 - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_block_with_expected
  33:     0x7fee0a87b2c2 - <rustc_hir_typeck[7e2a8938242ae40f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  34:     0x7fee0a868ac8 - rustc_hir_typeck[7e2a8938242ae40f]::check::check_fn
  35:     0x7fee09f89ef0 - rustc_hir_typeck[7e2a8938242ae40f]::typeck
  36:     0x7fee09f89199 - rustc_query_impl[40f1c38ec7f0fe8b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1a787087d433af5e]::query::erase::Erased<[u8; 8usize]>>
  37:     0x7fee09fe81f0 - rustc_query_system[7a228a9eb6f8b90e]::query::plumbing::try_execute_query::<rustc_query_impl[40f1c38ec7f0fe8b]::DynamicConfig<rustc_query_system[7a228a9eb6f8b90e]::query::caches::VecCache<rustc_span[e2cb3716bc025bf2]::def_id::LocalDefId, rustc_middle[1a787087d433af5e]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[40f1c38ec7f0fe8b]::plumbing::QueryCtxt, false>
  38:     0x7fee09fe7dcc - rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7fee09fe7562 - <rustc_middle[1a787087d433af5e]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[6e9724bb0c265329]::check_crate::{closure#5}>::{closure#0}
  40:     0x7fee09fe60a3 - rustc_hir_analysis[6e9724bb0c265329]::check_crate
  41:     0x7fee0a8aadd3 - rustc_interface[ae2941ea76b15824]::passes::analysis
  42:     0x7fee0a8aaa29 - rustc_query_impl[40f1c38ec7f0fe8b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1a787087d433af5e]::query::erase::Erased<[u8; 1usize]>>
  43:     0x7fee0ab7b8a5 - rustc_query_system[7a228a9eb6f8b90e]::query::plumbing::try_execute_query::<rustc_query_impl[40f1c38ec7f0fe8b]::DynamicConfig<rustc_query_system[7a228a9eb6f8b90e]::query::caches::SingleCache<rustc_middle[1a787087d433af5e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[40f1c38ec7f0fe8b]::plumbing::QueryCtxt, false>
  44:     0x7fee0ab7b609 - rustc_query_impl[40f1c38ec7f0fe8b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7fee0ab8ec56 - rustc_interface[ae2941ea76b15824]::interface::run_compiler::<core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>, rustc_driver_impl[ff846aa700ca0662]::run_compiler::{closure#0}>::{closure#0}
  46:     0x7fee0adbef06 - std[215f9b68e873486f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ae2941ea76b15824]::util::run_in_thread_with_globals<rustc_interface[ae2941ea76b15824]::util::run_in_thread_pool_with_globals<rustc_interface[ae2941ea76b15824]::interface::run_compiler<core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>, rustc_driver_impl[ff846aa700ca0662]::run_compiler::{closure#0}>::{closure#0}, core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>>::{closure#0}, core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>>
  47:     0x7fee0adbed32 - <<std[215f9b68e873486f]::thread::Builder>::spawn_unchecked_<rustc_interface[ae2941ea76b15824]::util::run_in_thread_with_globals<rustc_interface[ae2941ea76b15824]::util::run_in_thread_pool_with_globals<rustc_interface[ae2941ea76b15824]::interface::run_compiler<core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>, rustc_driver_impl[ff846aa700ca0662]::run_compiler::{closure#0}>::{closure#0}, core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>>::{closure#0}, core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[694f794f8b0567e]::result::Result<(), rustc_span[e2cb3716bc025bf2]::ErrorGuaranteed>>::{closure#1} as core[694f794f8b0567e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x7fee0be76005 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8bfba6e4cba56ce0
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/alloc/src/boxed.rs:2016:9
  49:     0x7fee0be76005 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf738f5a32d063c18
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/alloc/src/boxed.rs:2016:9
  50:     0x7fee0be76005 - std::sys::pal::unix::thread::Thread::new::thread_start::h97194e05728842d4
                               at /rustc/23a3d777c8a95715977608c827de63e7738fa228/library/std/src/sys/pal/unix/thread.rs:108:17
  51:     0x7fee05caa9eb - <unknown>
  52:     0x7fee05d2e7cc - <unknown>
  53:                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.78.0-nightly (23a3d777c 2024-02-18) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [find_field] find the index of maybe nested field `_` in `L`
#1 [typeck] type-checking `<impl at /tmp/icemaker_global_tempdir.ARGn7VxzHBhS/rustc_testrunner_tmpdir_reporting.hJYasVkFeKoS/mvce.rs:3:10: 3:15>::fmt`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 9 previous errors

Some errors have detailed explanations: E0412, E0601, E0658.
For more information about an error, try `rustc --explain E0412`.

@matthiaskrgr matthiaskrgr 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. C-bug Category: This is a bug. labels Feb 18, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 18, 2024
@matthiaskrgr matthiaskrgr reopened this Feb 18, 2024
@matthiaskrgr
Copy link
Member Author

smaller:

#[repr(C)]
#[derive(Debug)]
struct L {
    _: MyI32,
}

@matthiaskrgr
Copy link
Member Author

Seems also to be the 1000th bug found since I started fuzzing 🎉 :)

@clubby789
Copy link
Contributor

@rustbot claim

@jieyouxu jieyouxu added F-unnamed_fields `#![feature(unnamed_fields)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 18, 2024
@clubby789
Copy link
Contributor

clubby789 commented Feb 18, 2024

While looking into this, it looks like deriveing on a structure with unnamed fields doesn't really work, as it tries to access the field _, resulting in this weird error

error[E0609]: no field `_` on type `&L`
  --> ../poc.rs:13:5
   |
13 |     _: A,
   |     ^ unknown field
   |
help: one of the expressions' fields has a field of the same name
   |
13 |     _: A,
   |

(which crashes with debug assertions due to an empty span).

cc @frank-king

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 19, 2024
…, r=<try>

Check for accessing unnamed field in `find_field`

Fixes rust-lang#121263
I'm not entirely sure this is the right solution, but it seems to work 😓
@frank-king
Copy link
Contributor

Disallowing can be a temporary solution. After structural expression for unnamed fields are fully implementated, we can revisit this issue and improve the deriving strategy for types with unnamed fields (but it only works for anonymous ADTs).

Anyway, types with unnamed fields of named ADT can never be derived, since the proc macro is not able to fetch the nested fields info from another ADT defined elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-unnamed_fields `#![feature(unnamed_fields)]` 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. 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.

5 participants