ICE: `Invalid ConstKind for const_to_pat: {const error}`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
https://github.com/rust-lang/rust/blob/01867557cd7dbe256a031a7b8e28d05daecd75ab/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L47-L53
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the ICE with the supplied snippet using the noted nightly compiler, then inspect compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs around line 52. Trace the THIR pattern-lowering path shown in the backtrace, especially const_to_pat and lower_pattern_range_endpoint. Done means the example no longer triggers an internal compiler error while preserving the reported diagnostics.
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
- Mostly clear
- Newbie friendliness
- 38/100