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: invalid asymmetric binary op Lt #134352

Closed
matthiaskrgr opened this issue Dec 15, 2024 · 3 comments · Fixed by #134371
Closed

ICE: invalid asymmetric binary op Lt #134352

matthiaskrgr opened this issue Dec 15, 2024 · 3 comments · Fixed by #134371
Labels
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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

pub struct Struct<const N: i64>(pub [u8; N]);

pub fn function(value: Struct<3>) -> u8 {
    value.0[0]
}

original:

pub struct Struct<const N: i64>(pub [u8; N]);

pub type Alias = Struct<2>;

pub fn function(value: Struct<3>) -> u8 {
    value.0[0]
}

Version information

rustc 1.85.0-nightly (d18506299 2024-12-15)
binary: rustc
commit-hash: d18506299bfb20488aba466a69641a2bab6f7a4a
commit-date: 2024-12-15
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

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

error: the constant `N` is not of type `usize`
 --> /tmp/icemaker_global_tempdir.YagNzzKWUw8B/rustc_testrunner_tmpdir_reporting.w16l0x3yyxRt/mvce.rs:1:37
  |
1 | pub struct Struct<const N: i64>(pub [u8; N]);
  |                                     ^^^^^^^ expected `usize`, found `i64`

error: internal compiler error: /rustc/d18506299bfb20488aba466a69641a2bab6f7a4a/compiler/rustc_const_eval/src/interpret/operator.rs:163:13: invalid asymmetric binary op Lt: 0x0000000000000000 (usize), 0x0000000000000003 (i64)
 --> /tmp/icemaker_global_tempdir.YagNzzKWUw8B/rustc_testrunner_tmpdir_reporting.w16l0x3yyxRt/mvce.rs:3:1
  |
3 | pub fn function(value: Struct<3>) -> u8 {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at /rustc/d18506299bfb20488aba466a69641a2bab6f7a4a/compiler/rustc_const_eval/src/interpret/operator.rs:163:13:
Box<dyn Any>
stack backtrace:
   0:     0x7793221a842a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3ec6acdc8021b780
   1:     0x779322a13d26 - core::fmt::write::ha1e51f9ad754b246
   2:     0x7793239e9fd1 - std::io::Write::write_fmt::h447409d450220636
   3:     0x7793221a8282 - std::sys::backtrace::BacktraceLock::print::h0c9f47621987f564
   4:     0x7793221aa77a - std::panicking::default_hook::{{closure}}::h32dab02cf4eb3fec
   5:     0x7793221aa5c3 - std::panicking::default_hook::h977c01aba3fe59ba
   6:     0x7793212fd1e8 - std[8a615549bd1790e3]::panicking::update_hook::<alloc[3a7c820246e0185d]::boxed::Box<rustc_driver_impl[8936f116e8865c1]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7793221aaf38 - std::panicking::rust_panic_with_hook::hba51aacb56857061
   8:     0x779321333051 - std[8a615549bd1790e3]::panicking::begin_panic::<rustc_errors[16504968b0874da0]::ExplicitBug>::{closure#0}
   9:     0x779321328236 - std[8a615549bd1790e3]::sys::backtrace::__rust_end_short_backtrace::<std[8a615549bd1790e3]::panicking::begin_panic<rustc_errors[16504968b0874da0]::ExplicitBug>::{closure#0}, !>
  10:     0x779321328223 - std[8a615549bd1790e3]::panicking::begin_panic::<rustc_errors[16504968b0874da0]::ExplicitBug>
  11:     0x77932133cfb1 - <rustc_errors[16504968b0874da0]::diagnostic::BugAbort as rustc_errors[16504968b0874da0]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x77932189c9cc - <rustc_errors[16504968b0874da0]::DiagCtxtHandle>::span_bug::<rustc_span[75c3ac87255cc802]::span_encoding::Span, alloc[3a7c820246e0185d]::string::String>
  13:     0x779321933a07 - rustc_middle[80851824623efb4c]::util::bug::opt_span_bug_fmt::<rustc_span[75c3ac87255cc802]::span_encoding::Span>::{closure#0}
  14:     0x7793219193aa - rustc_middle[80851824623efb4c]::ty::context::tls::with_opt::<rustc_middle[80851824623efb4c]::util::bug::opt_span_bug_fmt<rustc_span[75c3ac87255cc802]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x77932191923b - rustc_middle[80851824623efb4c]::ty::context::tls::with_context_opt::<rustc_middle[80851824623efb4c]::ty::context::tls::with_opt<rustc_middle[80851824623efb4c]::util::bug::opt_span_bug_fmt<rustc_span[75c3ac87255cc802]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x77931fcf4527 - rustc_middle[80851824623efb4c]::util::bug::span_bug_fmt::<rustc_span[75c3ac87255cc802]::span_encoding::Span>
  17:     0x7793244c6219 - <rustc_const_eval[ebb6297578ee0f46]::interpret::eval_context::InterpCx<rustc_const_eval[ebb6297578ee0f46]::const_eval::dummy_machine::DummyMachine>>::binary_op.cold
  18:     0x77931f9b9b96 - <rustc_mir_transform[2781f817185d0af4]::known_panics_lint::ConstPropagator as rustc_middle[80851824623efb4c]::mir::visit::Visitor>::visit_assign
  19:     0x77931f9b687b - <rustc_mir_transform[2781f817185d0af4]::known_panics_lint::ConstPropagator as rustc_middle[80851824623efb4c]::mir::visit::Visitor>::visit_body
  20:     0x7793238d7650 - <rustc_mir_transform[2781f817185d0af4]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[2781f817185d0af4]::pass_manager::MirLint>::run_lint
  21:     0x779322a099a5 - rustc_mir_transform[2781f817185d0af4]::run_analysis_to_runtime_passes
  22:     0x77931ffe16a0 - rustc_mir_transform[2781f817185d0af4]::mir_drops_elaborated_and_const_checked
  23:     0x779322cd1c39 - rustc_query_impl[4e0376acc8b13a14]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[4e0376acc8b13a14]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[80851824623efb4c]::query::erase::Erased<[u8; 8usize]>>
  24:     0x779322cd1f91 - rustc_query_system[20737a1fda201ff5]::query::plumbing::try_execute_query::<rustc_query_impl[4e0376acc8b13a14]::DynamicConfig<rustc_data_structures[57370b606fe3e33d]::vec_cache::VecCache<rustc_span[75c3ac87255cc802]::def_id::LocalDefId, rustc_middle[80851824623efb4c]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[20737a1fda201ff5]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[4e0376acc8b13a14]::plumbing::QueryCtxt, false>
  25:     0x779322cd19e7 - rustc_query_impl[4e0376acc8b13a14]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  26:     0x779322e8f146 - rustc_interface[c7a5d74730d5794b]::passes::run_required_analyses
  27:     0x7793239d9c5e - rustc_interface[c7a5d74730d5794b]::passes::analysis
  28:     0x7793239d9c2f - rustc_query_impl[4e0376acc8b13a14]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[4e0376acc8b13a14]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[80851824623efb4c]::query::erase::Erased<[u8; 0usize]>>
  29:     0x779323a2ca55 - rustc_query_system[20737a1fda201ff5]::query::plumbing::try_execute_query::<rustc_query_impl[4e0376acc8b13a14]::DynamicConfig<rustc_query_system[20737a1fda201ff5]::query::caches::SingleCache<rustc_middle[80851824623efb4c]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[4e0376acc8b13a14]::plumbing::QueryCtxt, false>
  30:     0x779323a2c78e - rustc_query_impl[4e0376acc8b13a14]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  31:     0x779323a7ff74 - rustc_interface[c7a5d74730d5794b]::interface::run_compiler::<(), rustc_driver_impl[8936f116e8865c1]::run_compiler::{closure#0}>::{closure#1}
  32:     0x7793239a7187 - std[8a615549bd1790e3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c7a5d74730d5794b]::util::run_in_thread_with_globals<rustc_interface[c7a5d74730d5794b]::util::run_in_thread_pool_with_globals<rustc_interface[c7a5d74730d5794b]::interface::run_compiler<(), rustc_driver_impl[8936f116e8865c1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  33:     0x7793239a6e20 - <<std[8a615549bd1790e3]::thread::Builder>::spawn_unchecked_<rustc_interface[c7a5d74730d5794b]::util::run_in_thread_with_globals<rustc_interface[c7a5d74730d5794b]::util::run_in_thread_pool_with_globals<rustc_interface[c7a5d74730d5794b]::interface::run_compiler<(), rustc_driver_impl[8936f116e8865c1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[4d4c849bd23b5fc3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7793239a61c1 - std::sys::pal::unix::thread::Thread::new::thread_start::hb315ab60bee23a2e
  35:     0x77931daa339d - <unknown>
  36:     0x77931db2849c - <unknown>
  37:                0x0 - <unknown>

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.85.0-nightly (d18506299 2024-12-15) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `function`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

@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 Dec 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 15, 2024
@matthiaskrgr
Copy link
Member Author

bisects to #133734 🤔 cc @scottmcm

@matthiaskrgr
Copy link
Member Author

struct Struct<const N: i64>(pub [u8; N]);  // compiles and ice fixed with `<const N: usize>`

fn function(value: Struct<3>) -> u8 {
    value.0[0]
}

pub fn main() {}

@scottmcm
Copy link
Member

Hmm, annoying that we're running mir passes on something that didn't pass type checking.

What's MIR building supposed to be doing in a case like this where the array type is malformed?

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 16, 2024
Check for array lengths that aren't actually `usize`

I wish typeck wouldn't give us `ty::Array`s that have this problem in the first place, but we can check for it.

Fixes rust-lang#134352
cc `@matthiaskrgr`
@bors bors closed this as completed in 7c301ec Dec 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 16, 2024
Rollup merge of rust-lang#134371 - scottmcm:fix-134352, r=oli-obk

Check for array lengths that aren't actually `usize`

I wish typeck wouldn't give us `ty::Array`s that have this problem in the first place, but we can check for it.

Fixes rust-lang#134352
cc ``@matthiaskrgr``
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 17, 2024
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants