Skip to content

ICE: Invalid ConstKind for const_to_pat: {const error} #148890

Closed

Description

@cushionbadak

Code

impl std::ops::Neg for u128 {}

fn foo(-128..=127: u128) {}

fn main() {}

A mutant of tests/ui/feature-gates/feature-gate-negate-unsigned.rs

Weird. Why both impl and function both needed to ICE reproduction? Maybe u128 makes a bridge between two of them.

Meta

rustc --version --verbose:

rustc 1.93.0-nightly (01867557c 2025-11-12)
binary: rustc
commit-hash: 01867557cd7dbe256a031a7b8e28d05daecd75ab
commit-date: 2025-11-12
host: x86_64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.5

Error output

Command: rustc

error[E0117]: only traits defined in the current crate can be implemented for primitive types
 --> 03.rs:1:1
  |
1 | impl std::ops::Neg for u128 {}
  | ^^^^^^^^^^^^^^^^^^^^^^^----
  |                        |
  |                        `u128` is not defined in the current crate
  |
  = note: impl doesn't have any local type before any uncovered type parameters
  = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
  = note: define and implement a trait or new type instead

error: internal compiler error: compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:52:18: Invalid `ConstKind` for `const_to_pat`: {const error}
 --> 03.rs:3:8
  |
3 | fn foo(-128..=127: u128) {}
  |        ^^^^


thread 'rustc' (278250) panicked at compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:52:18:
Box<dyn Any>
Backtrace

thread 'rustc' (278250) panicked at compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:52:18:
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_build::thir::pattern::PatCtxt>::const_to_pat
   8: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pat_expr
   9: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pattern_range_endpoint
  10: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pattern_range
  11: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pattern
  12: <rustc_mir_build::thir::cx::ThirBuildCx>::pattern_from_hir
  13: rustc_mir_build::thir::cx::thir_body
      [... omitted 2 frames ...]
  14: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  15: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  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/jb/Library/CloudStorage/Dropbox/Desk/2503_rustc_ice/251109 ice 보고용/rustc-ice-2025-11-13T04_32_09-68741.txt` to your bug report

query stack during panic:
#0 [thir_body] building THIR for `foo`
#1 [check_unsafety] unsafety-checking `foo`
#2 [analysis] running analysis passes on crate `03`
end of query stack
error: aborting due to 2 previous errors

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

Notes

  • ICE location: compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs Line-52
    let mut convert = ConstToPat::new(self, id, span, c);
    match c.kind() {
    ty::ConstKind::Unevaluated(uv) => convert.unevaluated_to_pat(uv, ty),
    ty::ConstKind::Value(cv) => convert.valtree_to_pat(cv.valtree, cv.ty),
    _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c),
    }

Duplication Check

  • I searched "compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs" ICE (Github issue page with query), and there are no identical ICE issue there.
  • Closed issue-148542 points to identical ICE location. It's fixed last week.

Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on Nov 13, 2025
  2. added
    needs-triage
    on Nov 13, 2025
  3. added
    S-has-mcve
    and removed
    needs-triage
    on Dec 4, 2025
  4. added
    S-bug-has-test
    on Jun 27, 2026
  5. added
    S-found-by-fuzzing
    on Nov 10, 2026
  6. 0xNaezo commented on Nov 21, 2026

    @0xNaezo
    Contributor

    @rustbot claim

  7. added a commit that references this issue on Nov 23, 2026
    bfa4a8a
  8. added a commit that references this issue on Nov 23, 2026
    d4be668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugI-ICES-bug-has-testS-found-by-fuzzingS-has-mcveT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions