rust-lang / rust-lang/rust

ICE: `Add != BinOp::Eq | BinOp::Ne | BinOp::Le | BinOp::Lt | BinOp::Ge | BinOp::Gt | BinOp::Offset`

Open
#137,187 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

use std::ops::Add;

pub trait TimesTwo
where
    *const Self: Add,
{
    const unsafe fn t2_ptr(slf: *const Self) -> <*const Self as Add>::Output {
        slf + slf
    }
}

original:

use std::ops::Add;

pub trait TimesTwo
   where *const Self: Add<*const Self>,
{
   const unsafe extern "C-unwind" fn t2_ptr(slf: *const Self)
   -> <*const Self as Add<*const Self>>::Output {
       slf + slf
   }
}

fn main(){}

Version information

rustc 1.87.0-nightly (ce36a966c 2025-02-17)
binary: rustc
commit-hash: ce36a966c79e109dabeef7a47fe68e5294c6d71e
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/ce36a966c79e109dabeef7a47fe68e5294c6d71e/compiler/rustc_const_eval/src/check_consts/check.rs#L708-L720

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2 -Clink-dead-code=true -Zvalidate-mir --edition=2024

Program output

error[E0379]: functions in traits cannot be declared const
 --> /tmp/icemaker_global_tempdir.UMhzAAeJ1wJN/rustc_testrunner_tmpdir_reporting.nEQdJywdRhWw/mvce.rs:7:5
  |
7 |     const unsafe fn t2_ptr(slf: *const Self) -> <*const Self as Add>::Output {
  |     ^^^^^-
  |     |
  |     functions in traits cannot be const
  |     help: remove the `const`

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.UMhzAAeJ1wJN/rustc_testrunner_tmpdir_reporting.nEQdJywdRhWw/mvce.rs:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.UMhzAAeJ1wJN/rustc_testrunner_tmpdir_reporting.nEQdJywdRhWw/mvce.rs`


thread 'rustc' panicked at compiler/rustc_const_eval/src/check_consts/check.rs:714:21:
assertion `left matches right` failed
  left: Add
 right: BinOp::Eq | BinOp::Ne | BinOp::Le | BinOp::Lt | BinOp::Ge | BinOp::Gt |
BinOp::Offset
stack backtrace:
   0:     0x780f52799e40 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3841cd57ff2ecd73
   1:     0x780f530148ac - core::fmt::write::h1e3520bf56740af3
   2:     0x780f540318d1 - std::io::Write::write_fmt::hba9e4167b3001b26
   3:     0x780f52799ca2 - std::sys::backtrace::BacktraceLock::print::h4cef63a231b9b903
   4:     0x780f5279c4a6 - std::panicking::default_hook::{{closure}}::h42a071c1742d1486
   5:     0x780f5279c084 - std::panicking::default_hook::hb623603f8ca8d5a9
   6:     0x780f518e571b - std[3b75b760e1909bee]::panicking::update_hook::<alloc[fee51eceb6acdb2a]::boxed::Box<rustc_driver_impl[345723d7f8fea549]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x780f5279cd53 - std::panicking::rust_panic_with_hook::h4a78a56a08a0281e
   8:     0x780f5279ca4a - std::panicking::begin_panic_handler::{{closure}}::h003b3348edc396e0
   9:     0x780f5279a309 - std::sys::backtrace::__rust_end_short_backtrace::h40301e4d631caaec
  10:     0x780f5279c70d - rust_begin_unwind
  11:     0x780f4f4459e0 - core::panicking::panic_fmt::hf9c35d88d19a7b20
  12:     0x780f5130ad7b - core::panicking::assert_failed_inner::h948e8514cfb7919e
  13:     0x780f5183285b - core[22e5dcc507c1ce60]::panicking::assert_matches_failed::<&rustc_middle[8f0bb18145f914db]::mir::syntax::BinOp>
  14:     0x780f53b57332 - <rustc_const_eval[24ba1ca4ddcda3d4]::check_consts::check::Checker as rustc_middle[8f0bb18145f914db]::mir::visit::Visitor>::visit_basic_block_data
  15:     0x780f53b55a92 - <rustc_const_eval[24ba1ca4ddcda3d4]::check_consts::check::Checker>::check_body
  16:     0x780f53b59e43 - rustc_mir_transform[f79e9594970959e5]::mir_const_qualif
  17:     0x780f53b59d2f - rustc_query_impl[1dc7e25d3505b9db]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1dc7e25d3505b9db]::query_impl::mir_const_qualif::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 4usize]>>
  18:     0x780f53b57cd1 - rustc_query_system[923c01520de53f9e]::query::plumbing::try_execute_query::<rustc_query_impl[1dc7e25d3505b9db]::DynamicConfig<rustc_query_system[923c01520de53f9e]::query::caches::DefIdCache<rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[1dc7e25d3505b9db]::plumbing::QueryCtxt, true>
  19:     0x780f53b5768a - rustc_query_impl[1dc7e25d3505b9db]::query_impl::mir_const_qualif::get_query_incr::__rust_end_short_backtrace
  20:     0x780f53b58e05 - rustc_middle[8f0bb18145f914db]::query::plumbing::query_get_at::<rustc_query_system[923c01520de53f9e]::query::caches::DefIdCache<rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 4usize]>>>
  21:     0x780f505762d6 - rustc_mir_transform[f79e9594970959e5]::mir_promoted
  22:     0x780f535369d2 - rustc_query_impl[1dc7e25d3505b9db]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1dc7e25d3505b9db]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 16usize]>>
  23:     0x780f535358ec - rustc_query_system[923c01520de53f9e]::query::plumbing::try_execute_query::<rustc_query_impl[1dc7e25d3505b9db]::DynamicConfig<rustc_data_structures[f62cbf444a619353]::vec_cache::VecCache<rustc_span[75e5c439b5acee8]::def_id::LocalDefId, rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 16usize]>, rustc_query_system[923c01520de53f9e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[1dc7e25d3505b9db]::plumbing::QueryCtxt, true>
  24:     0x780f53534f53 - rustc_query_impl[1dc7e25d3505b9db]::query_impl::mir_promoted::get_query_incr::__rust_end_short_backtrace
  25:     0x780f54159d6e - rustc_query_impl[1dc7e25d3505b9db]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1dc7e25d3505b9db]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 8usize]>>
  26:     0x780f533afed3 - rustc_query_system[923c01520de53f9e]::query::plumbing::try_execute_query::<rustc_query_impl[1dc7e25d3505b9db]::DynamicConfig<rustc_data_structures[f62cbf444a619353]::vec_cache::VecCache<rustc_span[75e5c439b5acee8]::def_id::LocalDefId, rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[923c01520de53f9e]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[1dc7e25d3505b9db]::plumbing::QueryCtxt, true>
  27:     0x780f53371e33 - rustc_query_impl[1dc7e25d3505b9db]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  28:     0x780f5335fefa - rustc_interface[d53afbea1eb411d7]::passes::run_required_analyses
  29:     0x780f5402d95e - rustc_interface[d53afbea1eb411d7]::passes::analysis
  30:     0x780f5402d92f - rustc_query_impl[1dc7e25d3505b9db]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1dc7e25d3505b9db]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 0usize]>>
  31:     0x780f54029345 - rustc_query_system[923c01520de53f9e]::query::plumbing::try_execute_query::<rustc_query_impl[1dc7e25d3505b9db]::DynamicConfig<rustc_query_system[923c01520de53f9e]::query::caches::SingleCache<rustc_middle[8f0bb18145f914db]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[1dc7e25d3505b9db]::plumbing::QueryCtxt, true>
  32:     0x780f54028cbd - rustc_query_impl[1dc7e25d3505b9db]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  33:     0x780f540daf3c - rustc_interface[d53afbea1eb411d7]::passes::create_and_enter_global_ctxt::<core[22e5dcc507c1ce60]::option::Option<rustc_interface[d53afbea1eb411d7]::queries::Linker>, rustc_driver_impl[345723d7f8fea549]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  34:     0x780f540557e2 - rustc_interface[d53afbea1eb411d7]::interface::run_compiler::<(), rustc_driver_impl[345723d7f8fea549]::run_compiler::{closure#0}>::{closure#1}
  35:     0x780f53fd5898 - std[3b75b760e1909bee]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[d53afbea1eb411d7]::util::run_in_thread_with_globals<rustc_interface[d53afbea1eb411d7]::util::run_in_thread_pool_with_globals<rustc_interface[d53afbea1eb411d7]::interface::run_compiler<(), rustc_driver_impl[345723d7f8fea549]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  36:     0x780f53fd5574 - <<std[3b75b760e1909bee]::thread::Builder>::spawn_unchecked_<rustc_interface[d53afbea1eb411d7]::util::run_in_thread_with_globals<rustc_interface[d53afbea1eb411d7]::util::run_in_thread_pool_with_globals<rustc_interface[d53afbea1eb411d7]::interface::run_compiler<(), rustc_driver_impl[345723d7f8fea549]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[22e5dcc507c1ce60]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x780f53fd4d2b - std::sys::pal::unix::thread::Thread::new::thread_start::h9b930113dc9df217
  38:     0x780f4e0a339d - <unknown>
  39:     0x780f4e12849c - <unknown>
  40:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.87.0-nightly (ce36a966c 2025-02-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 -C link-dead-code=true -Z validate-mir

query stack during panic:
#0 [mir_const_qualif] const checking `TimesTwo::t2_ptr`
#1 [mir_promoted] promoting constants in MIR for `TimesTwo::t2_ptr`
#2 [mir_borrowck] borrow-checking `TimesTwo::t2_ptr`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0379, E0601.
For more information about an error, try `rustc --explain E0379`.

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 reproducing the ICE with the reduced program in /tmp/im/a.rs and the listed rustc flags. Inspect compiler/rustc_const_eval/src/check_consts/check.rs around lines 708-720 and the mir_const_qualif query path. Done means the program reports its existing diagnostics without panicking at the BinOp assertion.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.