-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Clippy --fix panics with index error #8734
Comments
it looks like its related to #8718. |
Hey, thank you for the report. This looks like the linked issue. Could you provide the Stacktrace, by setting |
You can also try to replicate it yourself on this repo. I get this: thread 'main' panicked at 'slice index starts at 1 but ends at 0', library/core/src/slice/index.rs:91:5
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::slice::index::slice_index_order_fail_rt
3: core::ops::function::FnOnce::call_once
4: core::intrinsics::const_eval_select
5: core::slice::index::slice_index_order_fail
6: rustfix::parse_snippet
7: rustfix::collect_span
8: <alloc::vec::Vec<rustfix::Replacement> as alloc::vec::spec_from_iter::SpecFromIter<rustfix::Replacement, core::iter::adapters::filter_map::FilterMap<core::iter::adapters::filter::Filter<core::slice::iter::Iter<rustfix::diagnostics::DiagnosticSpan>, rustfix::collect_suggestions<std::collections::hash::map::RandomState>::{closure#1}::{closure#0}>, rustfix::collect_span>>>::from_iter
9: <&mut rustfix::collect_suggestions<std::collections::hash::map::RandomState>::{closure#1} as core::ops::function::FnMut<(&rustfix::diagnostics::Diagnostic,)>>::call_mut
10: <alloc::vec::Vec<rustfix::Solution> as alloc::vec::spec_from_iter::SpecFromIter<rustfix::Solution, core::iter::adapters::filter_map::FilterMap<core::slice::iter::Iter<rustfix::diagnostics::Diagnostic>, rustfix::collect_suggestions<std::collections::hash::map::RandomState>::{closure#1}>>>::from_iter
11: rustfix::collect_suggestions::<std::collections::hash::map::RandomState>
12: cargo::ops::fix::fix_maybe_exec_rustc
13: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: could not compile `chess`
warning: build failed, waiting for other jobs to finish...
thread 'main' panicked at 'slice index starts at 1 but ends at 0', library/core/src/slice/index.rs:91:5
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: core::slice::index::slice_index_order_fail_rt
3: core::ops::function::FnOnce::call_once
4: core::intrinsics::const_eval_select
5: core::slice::index::slice_index_order_fail
6: rustfix::parse_snippet
7: rustfix::collect_span
8: <alloc::vec::Vec<rustfix::Replacement> as alloc::vec::spec_from_iter::SpecFromIter<rustfix::Replacement, core::iter::adapters::filter_map::FilterMap<core::iter::adapters::filter::Filter<core::slice::iter::Iter<rustfix::diagnostics::DiagnosticSpan>, rustfix::collect_suggestions<std::collections::hash::map::RandomState>::{closure#1}::{closure#0}>, rustfix::collect_span>>>::from_iter
9: <&mut rustfix::collect_suggestions<std::collections::hash::map::RandomState>::{closure#1} as core::ops::function::FnMut<(&rustfix::diagnostics::Diagnostic,)>>::call_mut
10: <alloc::vec::Vec<rustfix::Solution> as alloc::vec::spec_from_iter::SpecFromIter<rustfix::Solution, core::iter::adapters::filter_map::FilterMap<core::slice::iter::Iter<rustfix::diagnostics::Diagnostic>, rustfix::collect_suggestions<std::collections::hash::map::RandomState>::{closure#1}>>>::from_iter
11: rustfix::collect_suggestions::<std::collections::hash::map::RandomState>
12: cargo::ops::fix::fix_maybe_exec_rustc
13: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: could not compile `chess` |
Looks like it's coming from the It doesn't like the long multiline suggestions. For example, this works: [0u8, 1, 2, 3]
.into_iter()
.map(|n| match n {
1 => [n.saturating_add(1)],
n => [n],
})
.flatten(); While this causes the panic: [0u8, 1, 2, 3]
.into_iter()
.map(|n| match n {
1 => [n
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)],
n => [n],
})
.flatten(); Works just fine in stable, so it's likely #8520 |
|
This is actually a Cargo issue. rust-lang/rustfix@635eef7 didn't make it into rustfix 0.6.0, which Cargo depends on. Just have to wait for a new release. |
I ran into this as well, I see we are waiting for an answer on rust-lang/rustfix#211. |
The culprit should be solved by updating rustfix to 0.6.1, but @Serial-ATA discovered a very interesting case: fn issue8734() {
let _ = [0u8, 1, 2, 3]
.into_iter()
.map(|n| match n {
1 => [n
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)],
n => [n],
})
.flatten();
} gets autocorrect to fn issue8734() {
let _ = [0u8, 1, 2, 3]
.into_iter()
.flat_map(|n| match n {
1 => [n
.saturating_add(1)
1 => [n
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)
.saturating_add(1)],
n => [n],
});
} which is weird and incorrect. Let's investigate this further |
Add some testcases for recent rustfix update changelog: none This adds a testcase for a bugfix that has been fixed by https://github.com/rust-lang/rustfix/tree/v0.6.1 `rustfix` is pulled in by `compiletest_rs`. So to test that the correct rustfix version is used, I added one (and a half) testcase. I tried to add a testcase for #8734 as well, but interesting enough the rustfix is wrong: ```diff fn issue8734() { let _ = [0u8, 1, 2, 3] .into_iter() - .and_then(|n| match n { + .flat_map(|n| match n { + 1 => [n + .saturating_add(1) 1 => [n .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1) .saturating_add(1)], n => [n], }); } ``` this needs some investigation and then this testcase needs to be enabled by commenting it out closes #8878 related to #8734
Summary
cargo clippy --fix
causes an index error.Reproducer
I pushed the code that causes the error to this repo, so you can reproduce it. The error was triggerd by
cargo clippy --fix
. Note that this does not seem to panic in stable.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: