Skip to content

Incorrect warning about unused const #47133

Open
@robz

Description

@robz

In the following program:

const SIZE: usize = 4;

fn _f(arr: [i32; SIZE]) {
    for x in arr.iter() {
      println!("{}", x);
    }
}

fn main() {}

I get a warning about SIZE being unused:

warning: constant item is never used: `SIZE`
 --> src/main.rs:1:1
  |
1 | const SIZE: usize = 4;
  | ^^^^^^^^^^^^^^^^^^^^^^
  |

It seems to me that this warning isn't correct, since SIZE is used in the signature of _f

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-diagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions