rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.43k stars 1.54k forks source link

Clippy fails to allocate for uninit check with large arrays #11715

Open aapoalas opened 1 year ago

aapoalas commented 1 year ago

Summary

Trying to run clippy --fix on https://github.com/trynova/nova fails in the nova_vm due to this type:

Option<[Option<Value>; 4294967296]>

(Value is 8 bytes)

with the error:

thread 'rustc' panicked at 'OOM: failed to allocate for uninit check: InterpErrorInfo(InterpErrorInfoInner { kind: ResourceExhaustion(MemoryExhausted), backtrace: InterpErrorBacktrace { backtrace: None } })', compiler/rustc_const_eval/src/util/check_validity_requirement.rs:53:10

Admittedly this type is a bit ridiculous but theoretically possible in the context.

Version

rustc 1.72.0 (5680fa18f 2023-08-23)
binary: rustc
commit-hash: 5680fa18feaa87f3ff04063800aec256c3d4b4be
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.72.0
LLVM version: 16.0.5

Error output

Backtrace

``` thread 'rustc' panicked at 'OOM: failed to allocate for uninit check: InterpErrorInfo(InterpErrorInfoInner { kind: ResourceExhaustion(MemoryExhausted), backtrace: InterpErrorBacktrace { backtrace: None } })', compiler/rustc_const_eval/src/util/check_validity_requirement.rs:53:10 stack backtrace: 0: 0x7fef48362b61 - std::backtrace_rs::backtrace::libunwind::trace::he648b5c8dd376705 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7fef48362b61 - std::backtrace_rs::backtrace::trace_unsynchronized::h5da3e203eef39e9f at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7fef48362b61 - std::sys_common::backtrace::_print_fmt::h8d28d3f20588ae4c at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7fef48362b61 - ::fmt::hd9a5b0c9c6b058c0 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7fef483c977f - core::fmt::rt::Argument::fmt::h0afc04119f252b53 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/rt.rs:138:9 5: 0x7fef483c977f - core::fmt::write::h50b1b3e73851a6fe at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/mod.rs:1094:21 6: 0x7fef483554a7 - std::io::Write::write_fmt::h184eaf275e4484f0 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/io/mod.rs:1714:15 7: 0x7fef48362975 - std::sys_common::backtrace::_print::hf58c3a5a25090e71 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7fef48362975 - std::sys_common::backtrace::print::hb9cf0a7c7f077819 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7fef48365753 - std::panicking::default_hook::{{closure}}::h066adb2e3f3e2c07 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:269:22 10: 0x7fef483654e4 - std::panicking::default_hook::h277fa2776900ff14 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:288:9 11: 0x7fef4b66756b - >::call_once::{shim:vtable#0} 12: 0x7fef48365f7e - as core::ops::function::Fn>::call::h09cad52ea08435f2 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/alloc/src/boxed.rs:2007:9 13: 0x7fef48365f7e - std::panicking::rust_panic_with_hook::hceaf38da6d9db792 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:709:13 14: 0x7fef48365d07 - std::panicking::begin_panic_handler::{{closure}}::h2bce3ed2516af7df at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:597:13 15: 0x7fef48362fc6 - std::sys_common::backtrace::__rust_end_short_backtrace::h090f3faf8f98a395 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:151:18 16: 0x7fef48365a52 - rust_begin_unwind at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5 17: 0x7fef483c59f3 - core::panicking::panic_fmt::h4ec8274704d163a3 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14 18: 0x7fef483c6013 - core::result::unwrap_failed::h170bc2721a6c6ff2 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1651:5 19: 0x7fef4acb2aa6 - rustc_const_eval[54457b2d97152e93]::util::check_validity_requirement::check_validity_requirement 20: 0x7fef4acb2684 - ))>>::call_once 21: 0x7fef4aa1ba12 - rustc_query_impl[7f6201a046a7a363]::plumbing::__rust_begin_short_backtrace::> 22: 0x7fef4aa1b9d2 - ))>>::call_once 23: 0x7fef4bf3ee62 - ), rustc_middle[4cadb439cfabc8cf]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[7f6201a046a7a363]::plumbing::QueryCtxt>::{closure#2}::{closure#2} as core[f12ae36cc2e1ecf0]::ops::function::FnOnce<((rustc_query_impl[7f6201a046a7a363]::plumbing::QueryCtxt, rustc_query_impl[7f6201a046a7a363]::DynamicConfig), rustc_middle[4cadb439cfabc8cf]::query::erase::Erased<[u8; 16usize]>>, false, false, false>), (rustc_middle[4cadb439cfabc8cf]::ty::layout::ValidityRequirement, rustc_middle[4cadb439cfabc8cf]::ty::ParamEnvAnd))>>::call_once 24: 0x7fef4add7dd7 - rustc_query_system[5a9d202ec1d2890c]::query::plumbing::try_execute_query::), rustc_middle[4cadb439cfabc8cf]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[7f6201a046a7a363]::plumbing::QueryCtxt, true> 25: 0x7fef4add76ea - rustc_query_impl[7f6201a046a7a363]::query_impl::check_validity_requirement::get_query_incr::__rust_end_short_backtrace 26: 0x55c430112aba - clippy_utils[9fa82ae0af62f35d]::ty::is_uninit_value_valid_for_ty 27: 0x55c42fe71945 - clippy_lints[cd65760e4a7ded1c]::uninit_vec::handle_uninit_vec_pair 28: 0x55c42fe715e3 - ::check_block 29: 0x7fef4baa9073 - ::check_arm 30: 0x7fef4ba3fa8e - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_block 31: 0x7fef4ba3e6b1 - >::with_lint_attrs::< as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}> 32: 0x7fef4ba3f98c - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_expr 33: 0x7fef4ba4008d - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_arm 34: 0x7fef4ba0ecd6 - rustc_hir[c7c79bd3af2232c6]::intravisit::walk_expr::> 35: 0x7fef4ba3e6b1 - >::with_lint_attrs::< as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}> 36: 0x7fef4ba3f98c - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_expr 37: 0x7fef4ba3fa99 - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_block 38: 0x7fef4ba3e6b1 - >::with_lint_attrs::< as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_expr::{closure#0}::{closure#0}> 39: 0x7fef4ba3f98c - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_expr 40: 0x7fef4ba3fde5 - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_nested_body 41: 0x7fef4ba3ffca - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_fn 42: 0x7fef4ba0dafc - rustc_hir[c7c79bd3af2232c6]::intravisit::walk_impl_item::> 43: 0x7fef4ba4095f - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_nested_impl_item 44: 0x7fef4ba0f0c3 - rustc_hir[c7c79bd3af2232c6]::intravisit::walk_item::> 45: 0x7fef4ba406b7 - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_nested_item 46: 0x7fef4ba0e7f8 - rustc_hir[c7c79bd3af2232c6]::intravisit::walk_mod::> 47: 0x7fef4ba406b7 - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_nested_item 48: 0x7fef4ba0e7f8 - rustc_hir[c7c79bd3af2232c6]::intravisit::walk_mod::> 49: 0x7fef4ba406b7 - as rustc_hir[c7c79bd3af2232c6]::intravisit::Visitor>::visit_nested_item 50: 0x7fef4ba0e7f8 - rustc_hir[c7c79bd3af2232c6]::intravisit::walk_mod::> 51: 0x7fef4aa3002e - rustc_lint[9d740a8528938e29]::late::late_lint_crate:: 52: 0x7fef4aa2f448 - ::time::<(), rustc_lint[9d740a8528938e29]::late::check_crate::{closure#0}::{closure#0}> 53: 0x7fef4aa2f2d3 - ::time::<(), rustc_interface[7e6a9899d53a1fe5]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}> 54: 0x7fef4aa2ee0f - as core[f12ae36cc2e1ecf0]::ops::function::FnOnce<()>>::call_once 55: 0x7fef4aa2e800 - ::time::<(), rustc_interface[7e6a9899d53a1fe5]::passes::analysis::{closure#5}> 56: 0x7fef4aa2d2d7 - rustc_interface[7e6a9899d53a1fe5]::passes::analysis 57: 0x7fef4aa7dcfa - rustc_query_impl[7f6201a046a7a363]::plumbing::__rust_begin_short_backtrace::> 58: 0x7fef4aa7dce9 - >::call_once 59: 0x7fef4ae19d8c - rustc_query_system[5a9d202ec1d2890c]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7f6201a046a7a363]::plumbing::QueryCtxt, true> 60: 0x7fef4ae19934 - rustc_query_impl[7f6201a046a7a363]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 61: 0x7fef4ab2ddf2 - >::enter::, rustc_driver_impl[10725d833993dc31]::run_compiler::{closure#1}::{closure#2}::{closure#4}> 62: 0x7fef4ab2ca97 - ::enter::, rustc_span[14af2d27fb997609]::ErrorGuaranteed>> 63: 0x7fef4ab29cc5 - rustc_span[14af2d27fb997609]::set_source_map::, rustc_interface[7e6a9899d53a1fe5]::interface::run_compiler, rustc_driver_impl[10725d833993dc31]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 64: 0x7fef4ab29736 - >::set::, rustc_driver_impl[10725d833993dc31]::run_compiler::{closure#1}>::{closure#0}, core[f12ae36cc2e1ecf0]::result::Result<(), rustc_span[14af2d27fb997609]::ErrorGuaranteed>> 65: 0x7fef4ab28cfc - std[7c7acd4e376d60d3]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[10725d833993dc31]::run_compiler::{closure#1}>::{closure#0}, core[f12ae36cc2e1ecf0]::result::Result<(), rustc_span[14af2d27fb997609]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f12ae36cc2e1ecf0]::result::Result<(), rustc_span[14af2d27fb997609]::ErrorGuaranteed>> 66: 0x7fef4aea1305 - <::spawn_unchecked_, rustc_driver_impl[10725d833993dc31]::run_compiler::{closure#1}>::{closure#0}, core[f12ae36cc2e1ecf0]::result::Result<(), rustc_span[14af2d27fb997609]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f12ae36cc2e1ecf0]::result::Result<(), rustc_span[14af2d27fb997609]::ErrorGuaranteed>>::{closure#1} as core[f12ae36cc2e1ecf0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 67: 0x7fef48370435 - as core::ops::function::FnOnce>::call_once::hc0b1022758ecac73 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/alloc/src/boxed.rs:1993:9 68: 0x7fef48370435 - as core::ops::function::FnOnce>::call_once::h0c9654ebe7ad657e at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/alloc/src/boxed.rs:1993:9 69: 0x7fef48370435 - std::sys::unix::thread::Thread::new::thread_start::h04c8e9c7d83d3bd5 at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys/unix/thread.rs:108:17 70: 0x7fef480229eb - 71: 0x7fef480a67cc - 72: 0x0 - error: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new note: rustc 1.72.0 (5680fa18f 2023-08-23) running on x86_64-unknown-linux-gnu note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [check_validity_requirement] checking validity requirement for `core::option::Option<[core::option::Option; 4294967296]>`: allows being left uninitialized #1 [analysis] running analysis passes on this crate end of query stack note: Clippy version: clippy 0.1.72 (5680fa1 2023-08-23) ```

aapoalas commented 1 year ago

Apparently this doesn't error after some I manually fixed a bunch of clippy lints. The error reproduces with this commit https://github.com/trynova/nova/commit/f1ee408bd981df095bf4ca1f2ff741a94288f16b but not on some later ones.