Skip to content

Dead code warning when a constant is used only in a range match #18464

Closed
@GGist

Description

@GGist

This may be related to #18290 but here is some test code for this specific case:

const LOW_RANGE: char = '0';
const HIGH_RANGE: char = '9'; 

fn main() {
    let x: char = '5';

    match x {
        LOW_RANGE...HIGH_RANGE => println!("First Match"),
        _                      => println!("Second Match")
    };
}

Which prints:

<anon>:1:1: 1:29 warning: constant item is never used: `LOW_RANGE`, #[warn(dead_code)] on by default
<anon>:1 const LOW_RANGE: char = '0';
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
<anon>:2:1: 2:30 warning: constant item is never used: `HIGH_RANGE`, #[warn(dead_code)] on by default
<anon>:2 const HIGH_RANGE: char = '9'; 
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
First Match

Ideally this would not issue a warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions