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: unnested_or_patterns while checking rustc_typeck #5780

Closed
matthiaskrgr opened this issue Jul 9, 2020 · 1 comment · Fixed by #5784
Closed

ICE: unnested_or_patterns while checking rustc_typeck #5780

matthiaskrgr opened this issue Jul 9, 2020 · 1 comment · Fixed by #5784
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@matthiaskrgr
Copy link
Member

Clippy crashes while checking rustcs rustc_typeck crate.
clippy 0.0.212 (8aa18cb 2020-07-08)

Backtrace:

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs:403:27
stack backtrace:
   0:     0x7fc4bdcb58a5 - backtrace::backtrace::libunwind::trace::h34afbfad7fd770fc
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1:     0x7fc4bdcb58a5 - backtrace::backtrace::trace_unsynchronized::h460d522b1619a600
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2:     0x7fc4bdcb58a5 - std::sys_common::backtrace::_print_fmt::ha45fac10086813b4
                               at src/libstd/sys_common/backtrace.rs:78
   3:     0x7fc4bdcb58a5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hde84f63fcfd0e6de
                               at src/libstd/sys_common/backtrace.rs:59
   4:     0x7fc4bdcf232c - core::fmt::write::h540ac4a6a1232abc
                               at src/libcore/fmt/mod.rs:1076
   5:     0x7fc4bdca7622 - std::io::Write::write_fmt::hc344eafd6e850b4d
                               at src/libstd/io/mod.rs:1537
   6:     0x7fc4bdcba740 - std::sys_common::backtrace::_print::h4db88ff15cb5d61d
                               at src/libstd/sys_common/backtrace.rs:62
   7:     0x7fc4bdcba740 - std::sys_common::backtrace::print::h5fc39e1b1f610bd3
                               at src/libstd/sys_common/backtrace.rs:49
   8:     0x7fc4bdcba740 - std::panicking::default_hook::{{closure}}::h59e55edacb1d974a
                               at src/libstd/panicking.rs:198
   9:     0x7fc4bdcba48c - std::panicking::default_hook::heee4c8016dfbf328
                               at src/libstd/panicking.rs:217
  10:     0x55613a432c61 - clippy_driver::report_clippy_ice::h0e13321a0601dc3a
  11:     0x7fc4bdcbaeb8 - std::panicking::rust_panic_with_hook::h8405b6301c79fb5a
                               at src/libstd/panicking.rs:530
  12:     0x7fc4bdcbaa8b - rust_begin_unwind
                               at src/libstd/panicking.rs:437
  13:     0x7fc4bdceeed1 - core::panicking::panic_fmt::h78830ea6a34e7206
                               at src/libcore/panicking.rs:85
  14:     0x7fc4bdceee92 - core::panicking::panic_bounds_check::hdef4fff11e167a6a
                               at src/libcore/panicking.rs:62
  15:     0x55613a4daa87 - clippy_lints::unnested_or_patterns::eq_pre_post::hc91d82b8fff79e75
  16:     0x55613a57baeb - <alloc::vec::DrainFilter<T,F> as core::iter::traits::iterator::Iterator>::next::h3d1fe73d02a8b853
  17:     0x55613a4d87b9 - <clippy_lints::unnested_or_patterns::unnest_or_patterns::Visitor as rustc_ast::mut_visit::MutVisitor>::visit_pat::hf6ef0e32dca88cc5
  18:     0x55613a4d7c89 - <clippy_lints::unnested_or_patterns::unnest_or_patterns::Visitor as rustc_ast::mut_visit::MutVisitor>::visit_pat::hf6ef0e32dca88cc5
  19:     0x55613a62cfdd - rustc_ast::mut_visit::noop_visit_pat::h00ccb57e0a7e0c92
  20:     0x55613a4d9d83 - <clippy_lints::unnested_or_patterns::unnest_or_patterns::Visitor as rustc_ast::mut_visit::MutVisitor>::visit_pat::hf6ef0e32dca88cc5
  21:     0x55613a4d78b9 - clippy_lints::unnested_or_patterns::lint_unnested_or_patterns::hed89529dfabfc49d
  22:     0x7fc4c0385da3 - <rustc_lint::early::EarlyLintPassObjects as rustc_lint::passes::EarlyLintPass>::check_arm::h702c4cfb2d5a0003
  23:     0x7fc4be66525c - rustc_ast::visit::walk_expr::hc6f2fa2739b5bd44
  24:     0x7fc4be60a90d - <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_expr::h1ec66f13d405e19d
  25:     0x7fc4be60b4ed - <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_local::h8fe4e8c834fcace8
  26:     0x7fc4be665152 - rustc_ast::visit::walk_expr::hc6f2fa2739b5bd44
  27:     0x7fc4be60a90d - <rustc_lint::early::EarlyContextAndPass<T> as rustc_ast::visit::Visitor>::visit_expr::h1ec66f13d405e19d
  28:     0x7fc4be660db1 - rustc_ast::visit::walk_fn::hb33763d93347ea2c
  29:     0x7fc4be65bffd - rustc_ast::visit::walk_assoc_item::hf809cdfa669afdd4
  30:     0x7fc4be666ac7 - rustc_ast::visit::walk_item::hadb85d96c7e22896
  31:     0x7fc4be661f57 - rustc_ast::visit::walk_mod::h44239b070db7d8eb
  32:     0x7fc4be665e92 - rustc_ast::visit::walk_item::hadb85d96c7e22896
  33:     0x7fc4be661f57 - rustc_ast::visit::walk_mod::h44239b070db7d8eb
  34:     0x7fc4be665e92 - rustc_ast::visit::walk_item::hadb85d96c7e22896
  35:     0x7fc4be661f57 - rustc_ast::visit::walk_mod::h44239b070db7d8eb
  36:     0x7fc4be5e353e - rustc_lint::early::early_lint_crate::h69be7315dc13e506
  37:     0x7fc4be5e2cb9 - rustc_lint::early::check_ast_crate::he9606f65d602b3ad
  38:     0x7fc4be66cb3e - rustc_session::utils::<impl rustc_session::session::Session>::time::hb9014418586e5e41
  39:     0x7fc4be5c5388 - rustc_interface::passes::BoxedResolver::access::{{closure}}::h86171b927fa2cfca
  40:     0x7fc4be62b10b - rustc_interface::passes::configure_and_expand::{{closure}}::hd6cfede8be3ee7f8
  41:     0x7fc4be5c5164 - rustc_interface::passes::BoxedResolver::access::h689cbc08776fdcff
  42:     0x7fc4be5df367 - rustc_interface::queries::Queries::lower_to_hir::h84562e3bfbe512f1
  43:     0x7fc4be5dffe7 - rustc_interface::queries::Queries::global_ctxt::h534722f6d7513c5d
  44:     0x7fc4be3df3ab - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::hfbc63b8f1bb864b3
  45:     0x7fc4be47f787 - rustc_span::with_source_map::h57513f6df947164e
  46:     0x7fc4be3e0aa6 - rustc_interface::interface::run_compiler_in_existing_thread_pool::ha77eec52fccd45a0
  47:     0x7fc4be40b31d - scoped_tls::ScopedKey<T>::set::hf9bed68bfc8ed2b7
  48:     0x7fc4be42d420 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha0325e6c1df2523d
  49:     0x7fc4be3ee98e - core::ops::function::FnOnce::call_once{{vtable.shim}}::hb9561786ae71a4d6
  50:     0x7fc4bdcc9c7a - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h13d34828db364579
                               at /rustc/8aa18cbdc5d4bc33bd61e2d9a4b643d87f5d21de/src/liballoc/boxed.rs:1081
  51:     0x7fc4bdcc9c7a - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hd51b619e0f884abf
                               at /rustc/8aa18cbdc5d4bc33bd61e2d9a4b643d87f5d21de/src/liballoc/boxed.rs:1081
  52:     0x7fc4bdcc9c7a - std::sys::unix::thread::Thread::new::thread_start::h02c6e34c2c73f344
                               at src/libstd/sys/unix/thread.rs:87
  53:     0x7fc4bdbde422 - start_thread
  54:     0x7fc4bdaf3bf3 - __GI___clone
  55:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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: Clippy version: clippy 0.0.212 (8aa18cb 2020-07-08)

query stack during panic:
end of query stack
warning: 1 warning emitted

error: could not compile `rustc_typeck`.

To learn more, run the command again with --verbose.
command did not execute successfully: "/home/matthias/vcs/github/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "clippy" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "1" "--release" "--features" " llvm" "--manifest-path" "/home/matthias/vcs/github/rust/src/rustc/Cargo.toml" "--message-format" "json-render-diagnostics" "--" "--cap-lints" "warn" "-Aclippy::too_many_arguments" "-Aclippy::many_single_char_names" "-Aclippy::unreadable_literal" "-Aclippy::missing_safety_doc" "-Aclippy::collapsible_if" "-Aclippy::excessive_precision" "-Aclippy::wrong_self_convention" "-Aclippy::cognitive_complexity" "-Aclippy::trivially_copy_pass_by_ref" "-Aclippy::eval_order_dependence" "-Aclippy::partialeq_ne_impl" "-Aclippy::declare_interior_mutable_const" "-Aclippy::new_without_default" "-Aclippy::len_without_is_empty" "-Aclippy::should_implement_trait" "-Aclippy::transmute_float_to_int" "-Aclippy::mut_from_ref" "-Aclippy::deref_addrof" "-Aclippy::transmute_int_to_float" "-Aclippy::float_cmp" "-Aclippy::mem_replace_with_default" "-Aclippy::not_unsafe_ptr_arg_deref" "-Aclippy::needless_doctest_main" "-Aclippy::transmute_ptr_to_ptr" "-Aclippy::type_complexity" "-Aclippy::ptr_offset_with_cast" "-Aclippy::or_fun_call" "-Aclippy::manual_saturating_arithmetic" "-Aclippy::ptr_arg" "-Aclippy::derive_hash_xor_eq" "-Aclippy::drop_copy" "-Aclippy::diverging_sub_expression" "-Aclippy::just_underscores_and_digits" "-Aclippy::boxed_local" "-Aclippy::vec_box" "-Aclippy::drop_ref" "-Aclippy::match_bool" "-Aclippy::range_plus_one" "-Aclippy::to_digit_is_some" "-Aclippy::absurd_extreme_comparisons" "-Aclippy::assign_op_pattern" "-Aclippy::box_vec" "-Aclippy::cast_ptr_alignment" "-Aclippy::cmp_null" "-Aclippy::enum_variant_names" "-Aclippy::extra_unused_lifetimes" "-Aclippy::identity_op" "-Aclippy::implicit_hasher" "-Aclippy::inconsistent_digit_grouping" "-Aclippy::inherent_to_string" "-Aclippy::inherent_to_string_shadow_display" "-Aclippy::large_enum_variant" "-Aclippy::let_unit_value" "-Aclippy::match_as_ref" "-Aclippy::match_overlapping_arm" "-Aclippy::module_inception" "-Aclippy::modulo_one" "-Aclippy::mutable_key_type" "-Aclippy::option_option" "-Aclippy::range_minus_one" "-Aclippy::transmute_int_to_char" "-Aclippy::transmute_ptr_to_ref" "-Aclippy::option_map_unit_fn" "-Aclippy::comparison_chain" "-Aclippy::write_literal" "-Aclippy::write_with_newline" "-Aclippy::needless_lifetimes"
expected success, got: exit code: 101
failed to run: /home/matthias/vcs/github/rust/build/bootstrap/debug/bootstrap clippy -j 1
Build completed unsuccessfully in 0:00:02
@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jul 9, 2020
@matthiaskrgr matthiaskrgr self-assigned this Jul 11, 2020
@matthiaskrgr
Copy link
Member Author

I believe the problem is we access by index BEFORE doing the length check here:

fn eq_pre_post(ps1: &[P<Pat>], ps2: &[P<Pat>], idx: usize) -> bool {
    ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`.
        && ps1.len() == ps2.len()         // this should come first
        && over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r))
        && over(&ps1[idx + 1..], &ps2[idx + 1..], |l, r| eq_pat(l, r))
}

bors added a commit that referenced this issue Jul 12, 2020
Fix out of bounds access by checking length equality BEFORE accessing by index.

Fixes #5780

changelog: fix out of bounds access in unnested_or_patterns lint.

Edit: I did not bother reducing a testcase from `librustc_typeck` crate but I can confirm that with the change the crash no longer occurs.
flip1995 added a commit to flip1995/rust-clippy that referenced this issue Jul 13, 2020
Fix out of bounds access by checking length equality BEFORE accessing by index.

Fixes rust-lang#5780

changelog: fix out of bounds access in unnested_or_patterns lint.

Edit: I did not bother reducing a testcase from `librustc_typeck` crate but I can confirm that with the change the crash no longer occurs.
flip1995 added a commit to flip1995/rust-clippy that referenced this issue Jul 13, 2020
Fix out of bounds access by checking length equality BEFORE accessing by index.

Fixes rust-lang#5780

changelog: fix out of bounds access in unnested_or_patterns lint.

Edit: I did not bother reducing a testcase from `librustc_typeck` crate but I can confirm that with the change the crash no longer occurs.
@bors bors closed this as completed in 1b3bc16 Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
1 participant