Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matthiaskrgr opened this issue Feb 17, 2025 · 7 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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:

let lhs_ty = lhs.ty(self.body, self.tcx);
let rhs_ty = rhs.ty(self.body, self.tcx);
if is_int_bool_float_or_char(lhs_ty) && is_int_bool_float_or_char(rhs_ty) {
// Int, bool, float, and char operations are fine.
} else if lhs_ty.is_fn_ptr() || lhs_ty.is_raw_ptr() {
assert_matches!(
op,
BinOp::Eq
| BinOp::Ne
| BinOp::Le
| BinOp::Lt
| BinOp::Ge

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`.

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 17, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 17, 2025
@matthiaskrgr
Copy link
Member Author

derivative of #134587

bisects to nightly-2024-02-09 , miiight be #120550 but may also not..

@matthiaskrgr
Copy link
Member Author

smaller

use std::ops::Add;
trait A where
    *const Self: Add,
{
    const fn b(c: *const Self) -> <*const Self as Add>::Output {
        c + c
    }
}

@workingjubilee
Copy link
Member

I feel like I should cc @scottmcm

@scottmcm
Copy link
Member

I don't think I've changed anything about this?

*const Self: Add is just something that doesn't exist, so it's making weird MIR I guess.

Is the MIR building code lowering that + to BinOp::add instead of to Add::add?

@cyrgani
Copy link
Contributor

cyrgani commented Feb 18, 2025

duplicate of #134587?

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 3, 2025
@matthiaskrgr matthiaskrgr reopened this Mar 4, 2025
@Noratrieb
Copy link
Member

@matthiaskrgr can you please not reopen an issue I closed as a duplicate without any justification for why it's not a duplicate?? It's definitely possible I was wrong, but please post a comment on why you think that!

@matthiaskrgr
Copy link
Member Author

Would be great to lead by example and give an explanation of why you think its a dupe?

When I compare this one with #134587 (comment) , I notice the following things

  1. the code is different
  2. the ice message is different
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:

vs

error: internal compiler error: broken MIR in DefId(0:5 ~ c[a1e0]::TimesTwo::t2_ptr) (_0 = Add(move _2, move _3)): bad assignment (Alias(Projection, AliasTy { args: [*const Self/#0, *const Self/#0], def_id: DefId(2:3586 ~ core[7509]::ops::arith::Add::Output), .. }) = *const Self/#0): NoSolution
 --> c.rs:8:8
  |
8 |        slf + slf
  |        ^^^^^^^^^
  |
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:934:21 - disabled backtrace
 --> c.rs:8:8
  |
8 |        slf + slf
  |        ^^^^^^^^^
  1. the backtrace is different
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_matches_failed::<&rustc_middle::mir::syntax::BinOp>
   4: <rustc_const_eval::check_consts::check::Checker as rustc_middle::mir::visit::Visitor>::visit_basic_block_data
   5: <rustc_const_eval::check_consts::check::Checker>::check_body
   6: rustc_mir_transform::mir_const_qualif
      [... omitted 1 frame ...]
   7: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 4]>>>
   8: rustc_mir_transform::mir_promoted
      [... omitted 2 frames ...]
   9: rustc_interface::passes::run_required_analyses
  10: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  11: 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}
  12: 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.

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: please attach the file at `/tmp/im/rustc-ice-2025-03-04T19_37_42-2198288.txt` to your bug report

vs

note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:934:21
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         4: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
         5: rustc_borrowck::type_check::type_check
         6: rustc_borrowck::nll::compute_regions
         7: rustc_borrowck::do_mir_borrowck
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        10: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        11: rustc_interface::passes::run_required_analyses
        12: rustc_interface::passes::analysis
        13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        15: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        16: 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}
        17: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        18: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        19: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        20: std::sys::pal::unix::thread::Thread::new::thread_start
        21: <unknown>
        22: <unknown>
 --> c.rs:8:8
  |
8 |        slf + slf
  |        ^^^^^^^^^

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 nightlynightly-2024-02-09

note: please attach the file at `/tmp/im/rustc-ice-2025-03-04T19_38_25-2198660.txt` to your bug report

and the bisection points to a different commit

nightly-2024-02-09
vs
nightly-2020-10-17

I would think that all or at least most of these would have to match for it to be a duplicate.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants