Skip to content

ICE caused by trying to check if a reference is fat or not in consteval with an unsatisfied Sized bound #141734

Open
@theemathas

Description

@theemathas

Code

fn foo()
where
    for<'a> str: Sized,
{
    let _ = [0; const {
        let x = "abc";
        size_of_val(&x)
    }];
}

See also #141735

Meta

Reproducible on the playground with rust 1.87.0 and rust 1.89.0-nightly (2025-05-28 6f69710780d579b180ab).

Error output

error: internal compiler error: compiler/rustc_const_eval/src/interpret/operand.rs:157:17: invalid immediate for given destination place: value ScalarPair(alloc3<imm>, 0x0000000000000003) does not match ABI Scalar(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }))
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/operand.rs:157:17:
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_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: 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}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::write_immediate_to_mplace_no_validate
   7: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
   8: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 1 frame ...]
   9: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 1 frame ...]
  10: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  11: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::push_stack_frame_raw
  12: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
      [... omitted 1 frame ...]
  13: rustc_const_eval::const_eval::valtrees::eval_to_valtree
  14: <rustc_const_eval::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_middle::ty::PseudoCanonicalInput<rustc_middle::mir::interpret::GlobalId>)>>::call_once
      [... omitted 2 frames ...]
  15: <rustc_middle::ty::context::TyCtxt>::const_eval_global_id_for_typeck
  16: <rustc_middle::ty::context::TyCtxt>::const_eval_resolve_for_typeck
  17: rustc_trait_selection::traits::try_evaluate_const
  18: <rustc_trait_selection::traits::normalize::AssocTypeNormalizer as rustc_type_ir::fold::TypeFolder<rustc_middle::ty::context::TyCtxt>>::fold_const
  19: <rustc_hir_typeck::fn_ctxt::FnCtxt>::normalize::<rustc_middle::ty::consts::Const>
  20: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  21: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_decl
  22: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  23: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24: rustc_hir_typeck::check::check_fn
  25: rustc_hir_typeck::typeck_with_inspect::{closure#0}
      [... omitted 1 frame ...]
  26: rustc_hir_analysis::check_crate
  27: rustc_interface::passes::run_required_analyses
  28: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  29: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  30: 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 `/playground/rustc-ice-2025-05-29T12_32_58-51.txt` to your bug report

note: compiler flags: --crate-type lib -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:
#0 [eval_to_allocation_raw] const-evaluating + checking `foo::{constant#0}::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `foo::{constant#0}::{constant#0}`
#2 [eval_to_allocation_raw] const-evaluating + checking `foo::{constant#0}`
#3 [eval_to_valtree] evaluating type-level constant
#4 [typeck] type-checking `foo`
#5 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground` (lib)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impossible-boundsArea: Issues related to have impossible trait bounds in scope (impossible predicates)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