Skip to content

indexing_slicing should not fire if a valid array index comes from a constant function that is evaluated at compile-time #8348

Description

@c410-f3r
  1. From a inline constant block (indexing_slicing should not fire if a valid array index comes from a constant function that is evaluated at compile-time #8348 (comment)).
#![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);
}
  1. From a 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)).
#![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);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions