asomers / mockall

A powerful mock object library for Rust
Apache License 2.0
1.5k stars 62 forks source link

fix(mockall_derive): add allow(clippy::indexing_slicing) to generated module. #579

Closed JosiahBull closed 4 months ago

JosiahBull commented 5 months ago

I tend to configure Cargo.toml with:

[workspace.lints.clippy]
indexing_slicing = "deny"

https://rust-lang.github.io/rust-clippy/master/index.html#/indexing_slicing

Among other lints to catch code that might panic. The generated code from mockall currently fails this lint, and it's difficult to add an exception for it with #[allow()] as it's occurring within a proc macro.

This PR updates codegen to replace the instance of index slicing with .get().unwrap(). This does not represent any real change in functionality, just passes the lint check now. It will still panic the same as it would have previously.

I am happy to change this to add a #[allow()] annotation in the generated code if this is preferred. :)

asomers commented 4 months ago

LGTM, thanks.