Skip to content

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

@GGist

Description

@GGist
Contributor

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.

Activity

ghost
self-assigned this
on Oct 30, 2014
added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Oct 30, 2014
added 2 commits that reference this issue on Nov 2, 2014
3d8b29c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @huonw@GGist

      Issue actions

        Dead code warning when a constant is used only in a range match · Issue #18464 · rust-lang/rust