Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Closed
GGist opened this issue Oct 30, 2014 · 0 comments · Fixed by #18493
Closed

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

GGist opened this issue Oct 30, 2014 · 0 comments · Fixed by #18493
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@GGist
Copy link
Contributor

GGist commented Oct 30, 2014

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.

@ghost ghost self-assigned this Oct 30, 2014
@huonw huonw added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Oct 30, 2014
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants