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

Clippy slice panic on --fix #8878

Closed
Raytwo opened this issue May 23, 2022 · 8 comments · Fixed by #8880
Closed

Clippy slice panic on --fix #8878

Raytwo opened this issue May 23, 2022 · 8 comments · Fixed by #8880
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Raytwo
Copy link

Raytwo commented May 23, 2022

Summary

Getting a panic message slice index starts at 1 but ends at 0 by running the following command:

cargo +nightly-2022-05-21 clippy --fix --no-default-features

Which results in this stack backtrace:

Backtrace (Click to Expand)
stack backtrace:
   0:     0x7ff6dd68b3bf - git_midx_writer_dump
   1:     0x7ff6dd6b112a - git_midx_writer_dump
   2:     0x7ff6dd6818e9 - git_midx_writer_dump
   3:     0x7ff6dd68e67b - git_midx_writer_dump
   4:     0x7ff6dd68e26e - git_midx_writer_dump
   5:     0x7ff6dd68ec71 - git_midx_writer_dump
   6:     0x7ff6dd68eb2d - git_midx_writer_dump
   7:     0x7ff6dd68bf77 - git_midx_writer_dump
   8:     0x7ff6dd68e809 - git_midx_writer_dump
   9:     0x7ff6dd7449e5 - git_midx_writer_dump
  10:     0x7ff6dd6b2f2b - git_midx_writer_dump
  11:     0x7ff6dd6a9659 - git_midx_writer_dump
  12:     0x7ff6dd6ae4f9 - git_midx_writer_dump
  13:     0x7ff6dd744b29 - git_midx_writer_dump
  14:     0x7ff6dd519b48 - git_midx_writer_dump
  15:     0x7ff6dd519e8d - git_midx_writer_dump
  16:     0x7ff6dd29efdf - git_filter_source_path
  17:     0x7ff6dd29f7a2 - git_filter_source_path
  18:     0x7ff6dcd957e9 - <unknown>
  19:     0x7ff6dd019435 - git_odb_object_id
  20:     0x7ff6dcd0c270 - <unknown>
  21:     0x7ff6dcd562d6 - <unknown>
  22:     0x7ff6dcd7d50c - <unknown>
  23:     0x7ff6dd678411 - git_midx_writer_dump
  24:     0x7ff6dcd0e877 - <unknown>
  25:     0x7ff6dd6b96d0 - git_midx_writer_dump
  26:     0x7fffbbd9244d - BaseThreadInitThunk
  27:     0x7fffbcd0df88 - RtlUserThreadStart
error: could not compile `arcropolis

Reproducer

Code and commit

Simply run the following command: cargo +nightly-2022-05-21 clippy --fix --no-default-features

Version

rustc 1.63.0-nightly (e6a4afc3a 2022-05-20)
binary: rustc
commit-hash: e6a4afc3af2d2a53f91fc8a77bdfe94bea375b29
commit-date: 2022-05-20
host: x86_64-pc-windows-msvc
release: 1.63.0-nightly
LLVM version: 14.0.4

Additional Labels

No response

@Raytwo Raytwo added the C-bug Category: Clippy is not doing the correct thing label May 23, 2022
@hellow554
Copy link
Contributor

I can't compile your code :/

error[E0557]: feature has been removed
  --> /home/marcel/.cargo/git/checkouts/skyline-rs-652bad0610bd03a8/3278cf5/src/lib.rs:14:13
   |
14 |     feature(const_generics, impl_trait_in_bindings, alloc_prelude)
   |             ^^^^^^^^^^^^^^ feature has been removed
   |
   = note: removed in favor of `#![feature(adt_const_params)]` and `#![feature(generic_const_exprs)]`

error[E0557]: feature has been removed
  --> /home/marcel/.cargo/git/checkouts/skyline-rs-652bad0610bd03a8/3278cf5/src/lib.rs:14:29
   |
14 |     feature(const_generics, impl_trait_in_bindings, alloc_prelude)
   |                             ^^^^^^^^^^^^^^^^^^^^^^ feature has been removed
   |
   = note: the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done

error[E0433]: failed to resolve: could not find `prelude` in `alloc`
   --> /home/marcel/.cargo/git/checkouts/skyline-rs-652bad0610bd03a8/3278cf5/src/lib.rs:100:27
    |
100 |     pub use crate::alloc::prelude::v1::*;
    |                           ^^^^^^^ could not find `prelude` in `alloc`

error[E0635]: unknown feature `alloc_prelude`
  --> /home/marcel/.cargo/git/checkouts/skyline-rs-652bad0610bd03a8/3278cf5/src/lib.rs:14:53
   |
14 |     feature(const_generics, impl_trait_in_bindings, alloc_prelude)
   |                                                     ^^^^^^^^^^^^^

@jam1garner
Copy link

@hellow554 I believe he was using RUSTFLAGS="--cfg skyline_std_v3"

(long story short it has to do with trying to do some forwards compatible upgrading of things, the code those errors are from unfortunately needs to work on some weird out-of-tree toolchains)

@jam1garner
Copy link

And I guess I should clarify, I walked him through a lot of issue reduction and the issue occurs on the standard toolchain, not just the fork. There was also suspicion of build-std being involved but that too was ruled out.

The reduction boiled down to these requirements:

  • the linked codebase
  • any recent nightly
  • clippy
  • --fix

Anything else didn't effect whether or not the panic occured. Some things specifically tested and ruled out as having no effect on the panic:

  • build-std
  • custom toolchain/std
  • git state
    • this one due to the backtrace pointing at libgit2 (specifically code dealing with the git ondex)
    • this included deleting .git entirely, which still has no effect

@hellow554
Copy link
Contributor

Here's a MCVE:

use std::collections::HashMap;

pub fn crash() -> Option<&'static str> {
    let function_map: HashMap<String, ()> = HashMap::new();
    function_map
        .get("")
        .map(|_| {



            Some("") // three newline are important as well
 // whitespace beforehand is important!
        })
        .flatten()
}

make sure that the whitespace is important. I'm providing the base64 input as well for clarity:

dXNlIHN0ZDo6Y29sbGVjdGlvbnM6Okhhc2hNYXA7CgpwdWIgZm4gY3Jhc2goKSAtPiBPcHRpb248JidzdGF0aWMgc3RyPiB7CiAgICBsZXQgZnVuY3Rpb25fbWFwOiBIYXNoTWFwPFN0cmluZywgKCk+ID0gSGFzaE1hcDo6bmV3KCk7CiAgICBmdW5jdGlvbl9tYXAKICAgICAgICAuZ2V0KCIiKQogICAgICAgIC5tYXAofF98IHsKCgoKICAgICAgICAgICAgU29tZSgiIikgLy8gdGhyZWUgbmV3bGluZSBhcmUgaW1wb3J0YW50IGFzIHdlbGwKIC8vIHdoaXRlc3BhY2UgYmVmb3JlaGFuZCBpcyBpbXBvcnRhbnQhCiAgICAgICAgfSkKICAgICAgICAuZmxhdHRlbigpCn0K

I'm trying to get the culprit.

@hellow554
Copy link
Contributor

Btw: the ICE comes from these lines:

https://github.com/Raytwo/ARCropolis/blob/44b16445fd9d01a63a67f5ef0252b6c98f68de71/src/fs/loaders.rs#L318-L336

you want to use and_then instead of map and flatten to get rid of the ICE ;)

@hellow554
Copy link
Contributor

Seems to be a dup of #8734 :)
I submit a PR to close both issues

hellow554 added a commit to hellow554/rust-clippy that referenced this issue May 24, 2022
@jam1garner
Copy link

@hellow554 wow awesome! thanks so much ❤️

@Raytwo
Copy link
Author

Raytwo commented May 24, 2022

Wow, I never expect such a fast reply, thanks a lot!

@bors bors closed this as completed in 67a0891 May 24, 2022
botahamec pushed a commit to botahamec/rust-clippy that referenced this issue May 25, 2022
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants