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

unused_enumerate_index.rs: index out of bounds #11755

Closed
matthiaskrgr opened this issue Nov 3, 2023 · 0 comments · Fixed by #11756
Closed

unused_enumerate_index.rs: index out of bounds #11755

matthiaskrgr opened this issue Nov 3, 2023 · 0 comments · Fixed by #11756
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

Summary

#![warn(clippy::explicit_into_iter_loop)]

fn main() {
    // Issue #4958
    fn _takes_iterator<T>(iterator: &T)
    where
        for<'a> &'a T: IntoIterator<Item = &'a String>,
    {
        for _ in iterator {}
    }

    struct T;
    impl IntoIterator for &T {
        type Item = ();
        type IntoIter = std::vec::IntoIter<Self::Item>;
        fn into_iter(self) -> Self::IntoIter {
            unimplemented!()
        }
    }

    let mut t = T;

    // No suggestion for this.
    // We'd have to suggest `for _ in *rr {}` which is less clear.
    let rr = &&t;
    for () in rr.into_iter() {}
}

Version

rustc 1.75.0-nightly (9c20ddd95 2023-11-03)
binary: rustc
commit-hash: 9c20ddd956426d577d77cb3f57a7db2227a3c6e9
commit-date: 2023-11-03
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.4

Error output

Backtrace

warning: variable does not need to be mutable
--> src/main.rs:21:9
 |
21 |     let mut t = T;
 |         ----^
 |         |
 |         help: remove this `mut`
 |
 = note: `#[warn(unused_mut)]` on by default

thread 'rustc' panicked at src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs:22:26:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
 0:     0x7fbae6169cfc - std::backtrace_rs::backtrace::libunwind::trace::h758dc582e496f583
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
 1:     0x7fbae6169cfc - std::backtrace_rs::backtrace::trace_unsynchronized::h8dc222be4ae72b4b
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
 2:     0x7fbae6169cfc - std::sys_common::backtrace::_print_fmt::h23e2ea9fbbcd356c
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/sys_common/backtrace.rs:67:5
 3:     0x7fbae6169cfc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb940fea53fcb72c6
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/sys_common/backtrace.rs:44:22
 4:     0x7fbae61cbef0 - core::fmt::rt::Argument::fmt::h2ec284a6958f856b
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/core/src/fmt/rt.rs:142:9
 5:     0x7fbae61cbef0 - core::fmt::write::h1a43870c46fc6b6f
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/core/src/fmt/mod.rs:1117:17
 6:     0x7fbae615dc1f - std::io::Write::write_fmt::he374ab97e1606dfa
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/io/mod.rs:1763:15
 7:     0x7fbae6169ae4 - std::sys_common::backtrace::_print::hca7cfc3a03899ad0
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/sys_common/backtrace.rs:47:5
 8:     0x7fbae6169ae4 - std::sys_common::backtrace::print::h0dd58cdf92547322
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/sys_common/backtrace.rs:34:9
 9:     0x7fbae616c777 - std::panicking::default_hook::{{closure}}::hfc16e8c187950ef4
10:     0x7fbae616c4df - std::panicking::default_hook::h643e9bd7ed7f72e2
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/panicking.rs:292:9
11:     0x7fbae8ce8bf0 - std[518c55d442b65d9f]::panicking::update_hook::<alloc[74508e9abee3a8aa]::boxed::Box<rustc_driver_impl[1e399a535c91638]::install_ice_hook::{closure#0}>>::{closure#0}
12:     0x7fbae616ceb8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h36e8952ab2d612b9
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/alloc/src/boxed.rs:2021:9
13:     0x7fbae616ceb8 - std::panicking::rust_panic_with_hook::h6a54412da87bc2b0
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/panicking.rs:783:13
14:     0x7fbae616cc0e - std::panicking::begin_panic_handler::{{closure}}::hc08d2d7ca1705b25
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/panicking.rs:657:13
15:     0x7fbae616a1c6 - std::sys_common::backtrace::__rust_end_short_backtrace::h1891b26ea5d933da
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/sys_common/backtrace.rs:170:18
16:     0x7fbae616c972 - rust_begin_unwind
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/panicking.rs:645:5
17:     0x7fbae61c8615 - core::panicking::panic_fmt::h9daf40465fe34391
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/core/src/panicking.rs:72:14
18:     0x7fbae61c8832 - core::panicking::panic_bounds_check::h7af9710afaa522af
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/core/src/panicking.rs:190:5
19:     0x555da51fd074 - <clippy_lints[e56e61f55af512fc]::loops::Loops>::check_for_loop
20:     0x555da51f51b2 - <clippy_lints[e56e61f55af512fc]::loops::Loops as rustc_lint[9b82381af560af5d]::passes::LateLintPass>::check_expr
21:     0x7fbae900daf0 - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_expr::{closure#0}
22:     0x7fbae900d978 - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_expr
23:     0x7fbae900ecff - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_block
24:     0x7fbae900e148 - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_expr::{closure#0}
25:     0x7fbae900d978 - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_expr
26:     0x7fbae900c34a - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_nested_body
27:     0x7fbae900e4e4 - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_fn
28:     0x7fbae900cb95 - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_item
29:     0x7fbae900e81a - <rustc_lint[9b82381af560af5d]::late::LateContextAndPass<rustc_lint[9b82381af560af5d]::late::RuntimeCombinedLateLintPass> as rustc_hir[6eb0c9a90e014d38]::intravisit::Visitor>::visit_mod
30:     0x7fbaea6ef3fc - rustc_lint[9b82381af560af5d]::late::check_crate
31:     0x7fbaea39758c - rustc_interface[7f727f1a527a46c]::passes::analysis
32:     0x7fbaea396535 - rustc_query_impl[60decf841e455888]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[60decf841e455888]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c65a3bd53e6d447a]::query::erase::Erased<[u8; 1usize]>>
33:     0x7fbaea8d0ca6 - rustc_query_system[25ce05dcfae31225]::query::plumbing::try_execute_query::<rustc_query_impl[60decf841e455888]::DynamicConfig<rustc_query_system[25ce05dcfae31225]::query::caches::SingleCache<rustc_middle[c65a3bd53e6d447a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[60decf841e455888]::plumbing::QueryCtxt, false>
34:     0x7fbaea8d0ad5 - rustc_query_impl[60decf841e455888]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
35:     0x7fbaea9e99c6 - rustc_interface[7f727f1a527a46c]::interface::run_compiler::<core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>, rustc_driver_impl[1e399a535c91638]::run_compiler::{closure#1}>::{closure#0}
36:     0x7fbaead3115b - std[518c55d442b65d9f]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[7f727f1a527a46c]::util::run_in_thread_with_globals<rustc_interface[7f727f1a527a46c]::interface::run_compiler<core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>, rustc_driver_impl[1e399a535c91638]::run_compiler::{closure#1}>::{closure#0}, core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>>
37:     0x7fbaead30fb3 - <<std[518c55d442b65d9f]::thread::Builder>::spawn_unchecked_<rustc_interface[7f727f1a527a46c]::util::run_in_thread_with_globals<rustc_interface[7f727f1a527a46c]::interface::run_compiler<core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>, rustc_driver_impl[1e399a535c91638]::run_compiler::{closure#1}>::{closure#0}, core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3fe6d5b66435123e]::result::Result<(), rustc_span[fd77bf372609ae77]::ErrorGuaranteed>>::{closure#1} as core[3fe6d5b66435123e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
38:     0x7fbae6177c25 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfcff71f52665e7e6
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/alloc/src/boxed.rs:2007:9
39:     0x7fbae6177c25 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3a2c5ad677d53ad0
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/alloc/src/boxed.rs:2007:9
40:     0x7fbae6177c25 - std::sys::unix::thread::Thread::new::thread_start::h3d93699ba4bcb9bc
                             at /rustc/9c20ddd956426d577d77cb3f57a7db2227a3c6e9/library/std/src/sys/unix/thread.rs:108:17
41:     0x7fbae5e549eb - <unknown>
42:     0x7fbae5ed87cc - <unknown>
43:                0x0 - <unknown>

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?template=ice.yml

note: please attach the file at `/tmp/icemaker/rustc-ice-2023-11-03T19_25_55-3361208.txt` to your bug report

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
note: Clippy version: clippy 0.1.75 (9c20ddd 2023-11-03)

warning: 1 warning emitted

@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 Nov 3, 2023
@bors bors closed this as completed in 789bc73 Nov 3, 2023
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
Development

Successfully merging a pull request may close this issue.

1 participant