Skip to content

panic [index out of bounds] at clippy_lints/src/misc_early.rs:413:38 #4480

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

Closed
imp opened this issue Sep 1, 2019 · 5 comments · Fixed by #4486
Closed

panic [index out of bounds] at clippy_lints/src/misc_early.rs:413:38 #4480

imp opened this issue Sep 1, 2019 · 5 comments · Fixed by #4486
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@imp
Copy link
Contributor

imp commented Sep 1, 2019

Starting about a week ago we are hitting panic when running clippy on one of our crates

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 18446744073709551612', src/tools/clippy/clippy_lints/src/misc_early.rs:413:38

I would guess c1a4b26 may have something to do with it as the code in question appeared in this commit about same time.

Unfortunately the crate that fails to clippy is private (and really large), so I am not able to share it as an example for panic reproduction.

cargo clippy --all --all-targets
    Checking xxx v0.14.3 (/home/yyy/xxx)
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 18446744073709551612', src/tools/clippy/clippy_lints/src/misc_early.rs:413:38
stack backtrace:
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 18446744073709551612', src/tools/clippy/clippy_lints/src/misc_early.rs:413:38
stack backtrace:
   0:     0x7f348f844912 - backtrace::backtrace::libunwind::trace::h9f78d5c23e5ca9ac
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.35/src/backtrace/libunwind.rs:88
   1:     0x7f348f844912 - backtrace::backtrace::trace_unsynchronized::h82031343c7337d60
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.35/src/backtrace/mod.rs:66
   2:     0x7f348f844912 - std::sys_common::backtrace::_print::h49ccb0849442b97a
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7f348f844912 - std::sys_common::backtrace::print::ha559b8b604244066
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7f348f844912 - std::panicking::default_hook::{{closure}}::h54c7a33b963f1aa8
                               at src/libstd/panicking.rs:200
   5:     0x7f348f8445f6 - std::panicking::default_hook::h13b1f924de36489b
                               at src/libstd/panicking.rs:214
   6:     0x7f349171f781 - rustc::util::common::panic_hook::h590460f8d4d0c2cd
   7:     0x7f348f84514c - std::panicking::rust_panic_with_hook::h5605376f33a24a14
                               at src/libstd/panicking.rs:481
   8:     0x7f348f844c02 - std::panicking::continue_panic_fmt::h8daafd31e5424d17
                               at src/libstd/panicking.rs:384
   9:     0x7f348f844af6 - rust_begin_unwind
                               at src/libstd/panicking.rs:311
  10:     0x7f348f87193a - core::panicking::panic_fmt::hade9d5174dac2b2b
                               at src/libcore/panicking.rs:85
  11:     0x7f348f8718f5 - core::panicking::panic_bounds_check::h55b51e817be982c8
                               at src/libcore/panicking.rs:61
  12:     0x556cd01e0190 - <clippy_lints::misc_early::MiscEarlyLints as rustc::lint::EarlyLintPass>::check_expr::h5f3a6f5f4188708a
  13:     0x7f34911e25f3 - <rustc::lint::context::EarlyLintPassObjects as rustc::lint::EarlyLintPass>::check_expr::ha4a67c52fc4f656b
  14:     0x7f348fee9005 - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr::haecde6fc3a4dd97a
  15:     0x7f348fe1002c - syntax::visit::walk_expr::hc00dd50baaac12d9
  16:     0x7f348fee9010 - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr::haecde6fc3a4dd97a
  17:     0x7f348fe1093e - syntax::visit::walk_expr::hc00dd50baaac12d9
  18:     0x7f348fee9010 - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr::haecde6fc3a4dd97a
  19:     0x7f348fe0ff7c - syntax::visit::walk_expr::hc00dd50baaac12d9
  20:     0x7f348fee9010 - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr::haecde6fc3a4dd97a
  21:     0x7f348fe10562 - syntax::visit::walk_expr::hc00dd50baaac12d9
  22:     0x7f348fee9010 - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr::haecde6fc3a4dd97a
  23:     0x7f348fe0c201 - syntax::visit::walk_fn::h706cd820cb3e30e6
  24:     0x7f348fe0952b - syntax::visit::walk_trait_item::h5c7bb3811768039b
  25:     0x7f348feea71e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_trait_item::hd7d603dfef3e1be4
  26:     0x7f348fe112d2 - syntax::visit::walk_item::h53c2876b3908660e
  27:     0x7f348fee918e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_item::h7578974a1b8f5ccd
  28:     0x7f348fe10e4c - syntax::visit::walk_item::h53c2876b3908660e
  29:     0x7f348fee918e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_item::h7578974a1b8f5ccd
  30:     0x7f348fe10e4c - syntax::visit::walk_item::h53c2876b3908660e
  31:     0x7f348fee918e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_item::h7578974a1b8f5ccd
  32:     0x7f348fe10e4c - syntax::visit::walk_item::h53c2876b3908660e
  33:     0x7f348fee918e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_item::h7578974a1b8f5ccd
  34:     0x7f348fe06b5d - syntax::visit::walk_crate::h783afe50d881c8a6
  35:     0x7f348fee345b - rustc::lint::context::early_lint_crate::h729da3e7aa0dba6b
  36:     0x7f348fee1bbf - rustc::lint::context::check_ast_crate::h8b9a49cc35594b07
  37:     0x7f348fe68edd - rustc::util::common::time::hff840c499eacc297
  38:     0x7f348fe25a09 - rustc_interface::passes::BoxedResolver::access::{{closure}}::hd63f0fdfaaf0717a
  39:     0x7f348fea1e5b - rustc_interface::passes::configure_and_expand::{{closure}}::h8e23705f8af170f0
  40:     0x7f348fe730b6 - rustc_data_structures::box_region::PinnedGenerator<I,A,R>::access::h6056e50938be0f64
  41:     0x7f348fe03e84 - rustc_interface::queries::Query<T>::compute::h6a72551537a7d9ed
  42:     0x7f348fe05626 - rustc_interface::queries::Query<T>::compute::ha962515f8d2eb7a0
  43:     0x7f348feeba04 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::prepare_outputs::hcc4482b56706640e
  44:     0x7f348fd45983 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h0c773fa2d3d24442
  45:     0x7f348fd56402 - std::thread::local::LocalKey<T>::with::hee4c54b3ff09c09d
  46:     0x7f348fd69fde - scoped_tls::ScopedKey<T>::set::h803ee77de4f4746c
  47:     0x7f348fd9eb62 - syntax::with_globals::h3ed2ebfa1df32604
  48:     0x7f348fd0dca0 - std::sys_common::backtrace::__rust_begin_short_backtrace::h8378d8b6f2c712a4
  49:     0x7f348f85580a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  50:     0x7f348fd32179 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hb4cd51cfbc1469db
  51:     0x7f348f82840f - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h9c77d1d34d6748a1
                               at /rustc/fba38ac27e2ade309f4c2504a6d6cd3556972a28/src/liballoc/boxed.rs:922
  52:     0x7f348f8544b0 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h4e306b8f11317515
                               at /rustc/fba38ac27e2ade309f4c2504a6d6cd3556972a28/src/liballoc/boxed.rs:922
  53:     0x7f348f8544b0 - std::sys_common::thread::start_thread::h9a129262bccfcd59
                               at src/libstd/sys_common/thread.rs:13
  54:     0x7f348f8544b0 - std::sys::unix::thread::Thread::new::thread_start::h78acbe07b54a39d4
                               at src/libstd/sys/unix/thread.rs:79
  55:     0x7f348f5c66ba - start_thread
  56:     0x7f348f0e641d - clone
  57:                0x0 - <unknown>
query stack during panic:
end of query stack

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.39.0-nightly (fba38ac27 2019-08-31) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `rexlog`.
@flip1995 flip1995 added the I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 2, 2019
@flip1995
Copy link
Member

flip1995 commented Sep 2, 2019

cc @lzutao It seems that the index calculation for the suffix separation position can be wrong in some cases:

let maybe_last_sep_idx = lit_snip.len() - suffix.len() - 1;
// Do not lint when literal is unsuffixed.
if !suffix.is_empty() && lit_snip.as_bytes()[maybe_last_sep_idx] != b'_' {

18446744073709551612 is -4 in the twos complement. So I guess the lit_snip has a length of 0, while the suffix has a length of 3 (e.g. i32, u32, ...). This would result in an index like this. This could happen if the span of the expression resolves to the DUMMY_SP, which most likely is caused by macro expanded code. (Maybe proc-macro?).

Would it be possible for you to extract a reproducible example?

@tesuji
Copy link
Contributor

tesuji commented Sep 2, 2019

I know very little about proc-macro. I submitted the fix in #4486. Hopefully
someone will find a reproducible test case for it.

@flip1995
Copy link
Member

flip1995 commented Sep 2, 2019

@imp Can you checkout the fix in #4486? Steps to do this:

  1. Checkout the fix-panic-unseparate-literals branch from @lzutaos fork
  2. Compile Clippy: cargo +nightly build
  3. Execute the clippy driver on your code: $PATH_TO_CLIPPY/target/debug/cargo-clippy.
    (You may have to set export LD_LIBRARY_PATH=$(rustc +nightly --print sysroot)/lib)

After that report back if this fixed the ICE.

@imp
Copy link
Contributor Author

imp commented Sep 2, 2019

Yep, I can confirm that the fix doesn't panic! Thanks a lot!

@flip1995
Copy link
Member

flip1995 commented Sep 3, 2019

Nice, in that case, we can merge it.

bors added a commit that referenced this issue Sep 3, 2019
Fix index out of bound in case of empty snippet

cc #4480

changelog: none
@bors bors closed this as completed in #4486 Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants