Skip to content

ICE: primitive read not possible for type #141804

Open
@cushionbadak

Description

@cushionbadak

Code

fn foo() {
    static symbol: [u32];
    symbol[0];
}

fn main() {}

In fact, existing test-case tests/ui/extern/issue-36122-accessing-externed-dst.rs shows ICE. Above is just a reduced version of that.

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (70b3f4666 2025-05-30)
binary: rustc
commit-hash: 70b3f4666e24ce22fc32f5e357dbcf85d3254e63
commit-date: 2025-05-30
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

command: rustc

error: free static item without body
 --> prim_read.rs:2:5
  |
2 |     static symbol: [u32];
  |     ^^^^^^^^^^^^^^^^^^^^-
  |                         |
  |                         help: provide a definition for the static: `= <expr>;`

error[E0277]: the size for values of type `[u32]` cannot be known at compilation time
 --> prim_read.rs:2:20
  |
2 |     static symbol: [u32];
  |                    ^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[u32]`
  = note: statics and constants must have a statically known size

error: internal compiler error: /rustc/70b3f4666e24ce22fc32f5e357dbcf85d3254e63/compiler/rustc_const_eval/src/interpret/operand.rs:661:13: primitive read not possible for type: ()
 --> prim_read.rs:1:1
  |
1 | fn foo() {
  | ^^^^^^^^


thread 'rustc' panicked at /rustc/70b3f4666e24ce22fc32f5e357dbcf85d3254e63/compiler/rustc_const_eval/src/interpret/operand.rs:661:13:
Box<dyn Any>
Backtrace

thread 'rustc' panicked at /rustc/70b3f4666e24ce22fc32f5e357dbcf85d3254e63/compiler/rustc_const_eval/src/interpret/operand.rs:661:13:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_assign
   8: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_basic_block_data
   9: <rustc_mir_transform::known_panics_lint::ConstPropagator as rustc_middle::mir::visit::Visitor>::visit_body
  10: <rustc_mir_transform::known_panics_lint::KnownPanicsLint as rustc_mir_transform::pass_manager::MirLint>::run_lint
  11: rustc_mir_transform::pass_manager::run_passes_inner
  12: rustc_mir_transform::run_analysis_to_runtime_passes
  13: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 1 frame ...]
  14: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  15: rustc_interface::passes::run_required_analyses
  16: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  17: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  18: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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 make sure that you have updated to the latest nightly

note: please attach the file at `/Users/jisukbyun/workspace/250203 scratch/rustc-ice-2025-05-31T03_18_02-55792.txt` to your bug report

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `foo`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

Bisects to

searched nightlies: from nightly-2024-01-01 to nightly-2025-05-30
regressed nightly: nightly-2025-01-29
searched commit range: 2f348cb...bf1b174
regressed commit: fdd1a3b

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --end=2025-05-30 --regress ice --preserve --script rustc -- 36112.rs
********************************************************************************
Regression in fdd1a3b02687817cea41f6bacae3d5fbed2b2cd0
********************************************************************************

Attempting to search unrolled perf builds
Found commits ["93c2c039", "a88bb5b0", "cfb91884", "b1ba7742", "28363945", "1f424b2f", "5fa0022a", "3b0743e7"]
installing 93c2c03916d98677da55d6befdebea7557c18c7a
testing...
RESULT: 93c2c03916d98677da55d6befdebea7557c18c7a, ===> Script did not ICE

installing a88bb5b0c4c03e32ba76f172bdf7152b029bf3b1
testing...
RESULT: a88bb5b0c4c03e32ba76f172bdf7152b029bf3b1, ===> Script did not ICE

installing cfb91884481dfe04e596629bb4754f3f50608a8a
testing...
RESULT: cfb91884481dfe04e596629bb4754f3f50608a8a, ===> Script did not ICE

installing b1ba7742813297d6f858eca03b84d41e6d67c6b4
testing...
RESULT: b1ba7742813297d6f858eca03b84d41e6d67c6b4, ===> Script found ICE

Regression in https://github.com/rust-lang-ci/rust/commit/b1ba7742813297d6f858eca03b84d41e6d67c6b4
The PR introducing the regression in this rollup is #135748: Lower index bounds checking to `PtrMetadata`, this time wit…

Notes

  • ICE location: compiler/rustc_const_eval/src/interpret/operand.rs Line-661
    pub fn read_immediate(
    &self,
    op: &impl Projectable<'tcx, M::Provenance>,
    ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
    if !matches!(
    op.layout().backend_repr,
    BackendRepr::Scalar(abi::Scalar::Initialized { .. })
    | BackendRepr::ScalarPair(
    abi::Scalar::Initialized { .. },
    abi::Scalar::Initialized { .. }
    )
    ) {
    span_bug!(self.cur_span(), "primitive read not possible for type: {}", op.layout().ty);
    }

Related Issues with the same ICE location

  • Issue-131347 and Issue-140332 requires rustc -Zvalidate-mir -Copt-level=3 option to ICE & they show different query stack
  • Issue-137974 needs repro & has different query stack
  • Issue-137656 requires features: generic_const_exprs and min_generic_const_args

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions