-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
should not fire if a valid array index comes from a constant function that is evaluated at compile-time
#8348
Comments
I think here we should distinguish if the type is an array with a fixed size, as that will be caught by the compiler or a slice. The lint should still trigger in the later case, as the range check will be done at runtime. This should be a simple type check 🙃 @rustbot label +good-first-issue |
I think this is functioning as designed. |
Here's a disassembly of a similar code snippet showing that the call to #![feature(inline_const)]
#![forbid(clippy::indexing_slicing)]
const FOO: [i32; 1] = [1];
const fn idx() -> usize {
0
}
pub fn main() {
assert_eq!(FOO[const { idx() }], 1);
}
This should presumably be allowed for the same reason as normal array indexing (any misuse would be caught by |
Oh, I forgot about this feature. Thanks for pointing out such behavior. In addition to what @PatchMixolydic said, the following snippet should also not fire #![forbid(clippy::indexing_slicing)]
const FOO: [i32; 1] = [1];
const REF: &i32 = &FOO[idx()];
const fn idx() -> usize {
0
}
pub fn main() {
assert_eq!(REF, &1);
} |
indexing_slicing
should not fire if the index comes from a constant functionindexing_slicing
should not fire if the index comes from a constant function that is evaluated at compile-time
Updated the issue based on the provided feedback |
indexing_slicing
should not fire if the index comes from a constant function that is evaluated at compile-timeindexing_slicing
should not lint valid arrays if an index comes from a constant function that is evaluated at compile-time
indexing_slicing
should not lint valid arrays if an index comes from a constant function that is evaluated at compile-timeindexing_slicing
should not fire if a valid array index comes from a constant function that is evaluated at compile-time
@rustbot claim |
Thanks @pitaj |
Do not fire `panic` in a constant environment Let rustc handle panics in constant environments. Since #8348 I thought that such modification would require a lot of work but thanks to #8588 I now know that it is not the case. changelog: [`panic`]: No longer lint in constant context. `rustc` already handles this.
indexing_slicing
should not fire if a valid array index comes from a constant function that is evaluated at compile-time #8348 (comment)).const
declaration (indexing_slicing
should not fire if a valid array index comes from a constant function that is evaluated at compile-time #8348 (comment)).The text was updated successfully, but these errors were encountered: