rust-lang / rust-lang/rust

delayed bug: Missing value for constant, but no error reported?

Open
#128,512 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-generic_const_exprs I-ICE P-low T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![feature(generic_const_exprs)]

trait NodeIndex: Copy {}

struct Interface<'a, T: NodeIndex> {
    borrow: &'a (),
    _phantom: std::marker::PhantomData<fn() -> T>,
}

trait Component: 'static {
    type NodeIndex: NodeIndex;
    fn exec(&mut self, nodes: Interface<'_, Self::NodeIndex>);
}

trait SimpleComponent: 'static {
    const NODES: usize;
    fn exec(&mut self, input: [f32; Self::NODES]) -> [f32; Self::NODES];
}

#[derive(Copy, Clone)]
struct Node<const NODES: usize>(u8);
impl<const NODES: usize> NodeIndex for Node<NODES> {}

impl<T: SimpleComponent> Component for T 
where
    [(); T::NODES]:, // This where bound causes the ICE
{
    type NodeIndex = Node<{T::NODES}>;
    fn exec(&mut self, nodes: Interface<'_, Self::NodeIndex>) { /* ICEs even if the function is empty */ }
}

The above code doesn't reproduce the error, but has a similar structure to what causes the ICE in a larger codebase. Even in the codebase where it ICEs, creating a trait with the exact same definition (call it ComponentCopy), and then replacing the impl Component for T with:

- impl<T: SimpleComponent> Component for T where [(); T::NODES]: { ... }
+ impl<T: SimpleComponent> ComponentCopy for T where [(); T::NODES]: { /* same as above */ }
+ impl<T: ComponentCopy> Component for T { /* forward the assoc. type and method */ }

doesn't cause the ICE anymore.

There isn't even a span attached to the delayed error.

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (28a58f2fa 2024-07-31)
binary: rustc
commit-hash: 28a58f2fa7f0c46b8fab8237c02471a915924fe5
commit-date: 2024-07-31
host: x86_64-pc-windows-msvc
release: 1.82.0-nightly
LLVM version: 19.1.0
Error output
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: Missing value for constant, but no error reported?
  |
  = note: delayed at compiler\rustc_trait_selection\src\traits\const_evaluatable.rs:74:68
Backtrace

delayed bug: Missing value for constant, but no error reported?
   0: std::backtrace_rs::backtrace::dbghelp64::trace
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2: std::backtrace::Backtrace::create
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\std\src\backtrace.rs:331
   3: std::backtrace::Backtrace::capture
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\std\src\backtrace.rs:296
   4: <rustc_errors::DiagCtxtHandle>::steal_fulfilled_expectation_ids
   5: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
   6: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   7: <rustc_const_eval::errors::WriteThroughImmutablePointer as rustc_errors::diagnostic::LintDiagnostic<()>>::decorate_lint
   8: rustc_trait_selection::traits::const_evaluatable::is_const_evaluatable
   9: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation
  10: rustc_traits::evaluate_obligation::evaluate_obligation
  11: rustc_query_impl::plumbing::query_key_hash_verify_all
  12: rustc_ty_utils::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  13: rustc_query_impl::plumbing::query_key_hash_verify_all
  14: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  15: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_may_hold
  16: <rustc_codegen_llvm::builder::Builder as rustc_codegen_ssa::traits::builder::BuilderMethods>::load_operand
  17: rustc_hir_typeck::method::probe::method_autoderef_steps
  18: rustc_hir_typeck::method::probe::method_autoderef_steps
  19: rustc_hir_typeck::typeck
  20: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  21: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  22: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  23: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  24: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  25: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  26: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  27: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  28: rustc_hir_typeck::typeck
  29: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  30: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  31: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  32: rustc_hir_typeck::typeck
  33: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  34: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  35: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  36: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  37: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  38: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  39: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  40: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  41: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  42: <<rustc_hir_typeck::fn_ctxt::FnCtxt>::deduce_closure_signature_from_predicates::MentionsTy as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  43: rustc_hir_typeck::typeck
  44: rustc_hir_typeck::typeck
  45: rustc_query_impl::plumbing::query_key_hash_verify_all
  46: rustc_ty_utils::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  47: rustc_query_impl::plumbing::query_key_hash_verify_all
  48: <rustc_hir_typeck::upvar::InferBorrowKind as rustc_hir_typeck::expr_use_visitor::Delegate>::borrow
  49: rustc_hir_analysis::check_crate
  50: rustc_interface::passes::analysis
  51: <dyn std::io::Write as nu_ansi_term::write::AnyWrite>::write_str
  52: rustc_ty_utils::ty::adt_sized_constraint
  53: rustc_query_impl::query_system
  54: _wpgmptr
  55: _wpgmptr
  56: _wpgmptr
  57: alloc::boxed::impl$48::call_once
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\alloc\src\boxed.rs:2148
  58: alloc::boxed::impl$48::call_once
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\alloc\src\boxed.rs:2148
  59: std::sys::pal::windows::thread::impl$0::new::thread_start
             at /rustc/28a58f2fa7f0c46b8fab8237c02471a915924fe5/library\std\src\sys\pal\windows\thread.rs:55
  60: BaseThreadInitThunk
  61: RtlUserThreadStart



rustc version: 1.82.0-nightly (28a58f2fa 2024-07-31)
platform: x86_64-pc-windows-msvc

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reducing the larger codebase case, since the standalone example does not reproduce the ICE, and compare the direct Component impl with the ComponentCopy forwarding version. Inspect rustc_trait_selection/src/traits/const_evaluatable.rs at the reported line and const_evaluatable::is_const_evaluatable. Done means the reproducer no longer emits a delayed “Missing value for constant” ICE without a span.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.