Skip to content

ICE with anonymous field and a derive in 1.80.1 but also checked on Godbolt's nightly compiler #131041

@tialaramex

Description

@tialaramex
Contributor

Code

#[derive(Debug)]
pub struct Type
{
    _: u8,
}

Meta

rustc --version --verbose:

rustc 1.80.1 (3f5fd8dd4 2024-08-06) (Fedora 1.80.1-1.fc40)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.6

Error output

   Compiling ice20240929 v0.1.0 (/home/njl/src/ice20240929)
error[E0658]: unnamed fields are not yet fully implemented
 --> src/main.rs:4:5
  |
4 |     _: u8,
  |     ^
  |
  = note: see issue #49804 <https://github.com/rust-lang/rust/issues/49804> for more information

error[E0601]: `main` function not found in crate `ice20240929`
 --> src/main.rs:5:2
  |
5 | }
  |  ^ consider adding a `main` function to `src/main.rs`

error: struct with unnamed fields must have `#[repr(C)]` representation
 --> src/main.rs:2:1
  |
2 | pub struct Type
  | ^^^^^^^^^^^^^^^ struct `Type` defined here
  |
note: unnamed field defined here
 --> src/main.rs:4:5
  |
4 |     _: u8,
  |     ^^^^^
help: add `#[repr(C)]` to this struct
  |
2 + #[repr(C)]
3 | pub struct Type
  |

error: unnamed fields can only have struct or union types
 --> src/main.rs:4:5
  |
4 |     _: u8,
  |     ^^^^^

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect.rs:892:49:
expect Adt for unnamed field
stack backtrace:
   0:     0x7f8f73f4f135 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2a0cac5be5a8d820
   1:     0x7f8f73f9dafb - core::fmt::write::h17332d03f2f4f35b
   2:     0x7f8f73f4421f - <unknown>
   3:     0x7f8f73f4ef0e - <unknown>
   4:     0x7f8f73f51949 - <unknown>
   5:     0x7f8f73f516ea - std::panicking::default_hook::ha48f87b295834c46
   6:     0x7f8f74a5ec30 - <unknown>
   7:     0x7f8f73f5200b - std::panicking::rust_panic_with_hook::h4eeb081fd329f3e2
   8:     0x7f8f73f51d84 - <unknown>
   9:     0x7f8f73f4f5f9 - <unknown>
  10:     0x7f8f73f51ab7 - rust_begin_unwind
  11:     0x7f8f73f15a73 - core::panicking::panic_fmt::h755ac17b0b090cd9
  12:     0x7f8f73f15a3b - core::option::expect_failed::h27ffe2fb3bb55e8c
  13:     0x7f8f75f9d6c0 - rustc_hir_analysis[9a5fae5dc28e0e53]::collect::find_field
  14:     0x7f8f7710649f - <unknown>
  15:     0x7f8f771058b1 - <unknown>
  16:     0x7f8f754fc093 - <unknown>
  17:     0x7f8f7546323e - <unknown>
  18:     0x7f8f7544390f - <unknown>
  19:     0x7f8f7559f041 - <unknown>
  20:     0x7f8f760a1e57 - <unknown>
  21:     0x7f8f760603dc - <unknown>
  22:     0x7f8f7605d32d - <unknown>
  23:     0x7f8f7605fbc3 - <unknown>
  24:     0x7f8f7605d32d - <unknown>
  25:     0x7f8f7605fbc3 - <unknown>
  26:     0x7f8f760460fa - <unknown>
  27:     0x7f8f7605f589 - <unknown>
  28:     0x7f8f7605d32d - <unknown>
  29:     0x7f8f760d7b02 - <unknown>
  30:     0x7f8f7605d32d - <unknown>
  31:     0x7f8f7612c352 - <unknown>
  32:     0x7f8f76124081 - rustc_hir_typeck[30ee169b06768cb7]::typeck
  33:     0x7f8f768b6ad7 - <unknown>
  34:     0x7f8f75462850 - <unknown>
  35:     0x7f8f75450f11 - <unknown>
  36:     0x7f8f7556d828 - <unknown>
  37:     0x7f8f75fa8e3a - rustc_hir_analysis[9a5fae5dc28e0e53]::check_crate
  38:     0x7f8f76231b9e - rustc_interface[881e2d08a402e036]::passes::analysis
  39:     0x7f8f771081e7 - <unknown>
  40:     0x7f8f75461a4f - <unknown>
  41:     0x7f8f75417c08 - <unknown>
  42:     0x7f8f7555d394 - <unknown>
  43:     0x7f8f76e65fdc - <unknown>
  44:     0x7f8f76e63de7 - <unknown>
  45:     0x7f8f76e68a7a - <unknown>
  46:     0x7f8f73f5bfeb - <unknown>
  47:     0x7f8f73d796d7 - start_thread
  48:     0x7f8f73dfd60c - __clone3
  49:                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.80.1 (3f5fd8dd4 2024-08-06) (Fedora 1.80.1-1.fc40) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:
#0 [find_field] find the index of maybe nested field `_` in `Type`
#1 [typeck] type-checking `<impl at src/main.rs:1:10: 1:15>::fmt`
end of query stack
Some errors have detailed explanations: E0601, E0658.
For more information about an error, try `rustc --explain E0601`.
error: could not compile `ice20240929` (bin "ice20240929") due to 4 previous errors

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect.rs:892:49:
expect Adt for unnamed field

Backtrace

``` 0: 0x7f8f73f4f135 - ::fmt::h2a0cac5be5a8d820 1: 0x7f8f73f9dafb - core::fmt::write::h17332d03f2f4f35b 2: 0x7f8f73f4421f - 3: 0x7f8f73f4ef0e - 4: 0x7f8f73f51949 - 5: 0x7f8f73f516ea - std::panicking::default_hook::ha48f87b295834c46 6: 0x7f8f74a5ec30 - 7: 0x7f8f73f5200b - std::panicking::rust_panic_with_hook::h4eeb081fd329f3e2 8: 0x7f8f73f51d84 - 9: 0x7f8f73f4f5f9 - 10: 0x7f8f73f51ab7 - rust_begin_unwind 11: 0x7f8f73f15a73 - core::panicking::panic_fmt::h755ac17b0b090cd9 12: 0x7f8f73f15a3b - core::option::expect_failed::h27ffe2fb3bb55e8c 13: 0x7f8f75f9d6c0 - rustc_hir_analysis[9a5fae5dc28e0e53]::collect::find_field 14: 0x7f8f7710649f - 15: 0x7f8f771058b1 - 16: 0x7f8f754fc093 - 17: 0x7f8f7546323e - 18: 0x7f8f7544390f - 19: 0x7f8f7559f041 - 20: 0x7f8f760a1e57 - 21: 0x7f8f760603dc - 22: 0x7f8f7605d32d - 23: 0x7f8f7605fbc3 - 24: 0x7f8f7605d32d - 25: 0x7f8f7605fbc3 - 26: 0x7f8f760460fa - 27: 0x7f8f7605f589 - 28: 0x7f8f7605d32d - 29: 0x7f8f760d7b02 - 30: 0x7f8f7605d32d - 31: 0x7f8f7612c352 - 32: 0x7f8f76124081 - rustc_hir_typeck[30ee169b06768cb7]::typeck 33: 0x7f8f768b6ad7 - 34: 0x7f8f75462850 - 35: 0x7f8f75450f11 - 36: 0x7f8f7556d828 - 37: 0x7f8f75fa8e3a - rustc_hir_analysis[9a5fae5dc28e0e53]::check_crate 38: 0x7f8f76231b9e - rustc_interface[881e2d08a402e036]::passes::analysis 39: 0x7f8f771081e7 - 40: 0x7f8f75461a4f - 41: 0x7f8f75417c08 - 42: 0x7f8f7555d394 - 43: 0x7f8f76e65fdc - 44: 0x7f8f76e63de7 - 45: 0x7f8f76e68a7a - 46: 0x7f8f73f5bfeb - 47: 0x7f8f73d796d7 - start_thread 48: 0x7f8f73dfd60c - __clone3 49: 0x0 - ```

Activity

added
C-bugCategory: This is a bug.
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.
on Sep 29, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 29, 2024
tialaramex

tialaramex commented on Sep 29, 2024

@tialaramex
ContributorAuthor

The ICE does not happen if we don't use a derive, or if we give the field a real name

clubby789

clubby789 commented on Sep 29, 2024

@clubby789
Contributor

Closing since this is a duplicate of #121263 (and related to #121299 and #121161) - the feature is currently up for discussion.

removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Sep 30, 2024
added 2 commits that reference this issue on Oct 11, 2024
80325f2
f496659
added a commit that references this issue on Oct 18, 2024
f5cc292
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-unnamed_fields`#![feature(unnamed_fields)]`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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @tialaramex@saethlin@clubby789@rustbot

      Issue actions

        ICE with anonymous field and a derive in 1.80.1 but also checked on Godbolt's nightly compiler · Issue #131041 · rust-lang/rust