Closed
Description
Summary
The indexing_slicing
-lint is not triggered within const fn
s. In the following example, is_negative
performs indexing on a slice (self.value[0]
) which should get linted but isn't. However if I remove the const
-attribute for is_negative
, the lint gets triggered as expected.
#![warn(clippy::indexing_slicing)]
/// An opaque integer representation
pub struct Integer<'a> {
/// The underlying data
value: &'a [u8],
}
impl<'a> Integer<'a> {
// Check whether `self` holds a negative number or not
pub const fn is_negative(&self) -> bool {
self.value[0] & 0b1000_0000 != 0
}
}
Lint Name
indexing_slicing
Reproducer
I tried this code:
#![warn(clippy::indexing_slicing)]
/// An opaque integer representation
pub struct Integer<'a> {
/// The underlying data
value: &'a [u8],
}
impl<'a> Integer<'a> {
// Check whether `self` holds a negative number or not
pub const fn is_negative(&self) -> bool {
self.value[0] & 0b1000_0000 != 0
}
}
I expected to see this happen: The lint warns me on self.value[0]
.
Instead, this happened: The lint does not warn me on self.value[0]
😅
Version
rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: aarch64-apple-darwin
release: 1.65.0
LLVM version: 15.0.0