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

indexing_slicing emitting errors on proc-macro code. #12824

Open
JosiahBull opened this issue May 19, 2024 · 0 comments
Open

indexing_slicing emitting errors on proc-macro code. #12824

JosiahBull opened this issue May 19, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@JosiahBull
Copy link

Summary

When running the lint while using the mockall library I found it was generating lints from inside a proc-macro that are impossible to allow or ignore. This is correctly generating on proc-macro code which violates the lint, but should be squashed as it's coming from inside a proc-macro.

Lint Name

indexing_slicing

Reproducer

I tried this code:

#![deny(clippy::indexing_slicing)]

#[cfg(test)]
use mockall::{automock, mock, predicate::*};

pub struct ExampleEntity {
    id: u64,
}

#[allow(clippy::indexing_slicing)]
#[cfg_attr(test, automock)]
impl ExampleEntity {
    pub fn new(id: u64) -> Self {
        Self { id }
    }

    pub fn get_id(&self) -> u64 {
        self.id
    }
}

I saw this happen:

warning: unused import: `mock`
 --> src/lib.rs:4:25
  |
4 | use mockall::{automock, mock, predicate::*};
  |                         ^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: indexing may panic
  --> src/lib.rs:11:18
   |
11 | #[cfg_attr(test, automock)]
   |                  ^^^^^^^^
   |
   = help: consider using `.get(n)` or `.get_mut(n)` instead
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
note: the lint level is defined here
  --> src/lib.rs:1:9
   |
1  | #![deny(clippy::indexing_slicing)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `automock` (in Nightly builds, run with -Z macro-backtrace for more info)

error: indexing may panic
  --> src/lib.rs:11:18
   |
11 | #[cfg_attr(test, automock)]
   |                  ^^^^^^^^
   |
   = help: consider using `.get(n)` or `.get_mut(n)` instead
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing
   = note: this error originates in the attribute macro `automock` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `min-reproduction` (lib test) generated 1 warning
error: could not compile `min-reproduction` (lib test) due to 15 previous errors; 1 warning emitted

I expected to see this happen:

NO lints emitted.

Version

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Additional Labels

No response

@JosiahBull JosiahBull added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 19, 2024
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-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant