Skip to content

indexing_slicing emitting errors on proc-macro code. #12824

Closed
@JosiahBull

Description

@JosiahBull

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions