Skip to content

Duplicate unused variable warning #22599

New issue

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

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

Already on GitHub? Sign in to your account

Closed
zokier opened this issue Feb 20, 2015 · 1 comment
Closed

Duplicate unused variable warning #22599

zokier opened this issue Feb 20, 2015 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@zokier
Copy link

zokier commented Feb 20, 2015

I get two identical unused variable warnings when trying to compile the following code:

#[allow(dead_code)]
#[derive(Copy)]
enum ParseState {
    Quoted,
    BackslashQuoted,
    Normal,
    BackslashNormal,
}

pub fn parse(line: &str) -> Result<Vec<String>, String> {
    let res = Vec::<String>::new();
    let mut current_token = String::new();
    let mut state = ParseState::Normal;
    for c in line.chars() {
        state = match (c, state) {
            (c, ParseState::BackslashQuoted) => {
                current_token.push('\\');
                current_token.push(c);
                ParseState::Quoted
            },
            (c, ParseState::BackslashNormal) => {
                //TODO some fancy escape codes, eg \n
                ParseState::Normal
            },
            (c, _) => {
                current_token.push(c);
                state
            }
        }
    }

    return Ok(res);
}

fn main() {}

I get the following output:

$ rustc reduction.rs 
reduction.rs:21:14: 21:15 warning: unused variable: `c`, #[warn(unused_variables)] on by default
reduction.rs:21             (c, ParseState::BackslashNormal) => {
                             ^
reduction.rs:21:14: 21:15 warning: unused variable: `c`, #[warn(unused_variables)] on by default
reduction.rs:21             (c, ParseState::BackslashNormal) => {
                             ^
$

rustc version:

rustc 1.0.0-nightly (b63cee4a1 2015-02-14 17:01:11 +0000)

Operating system: Arch Linux x86_64

@kmcallister kmcallister added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. A-diagnostics Area: Messages for errors, warnings, and lints labels Feb 21, 2015
@nham
Copy link
Contributor

nham commented Jun 29, 2015

Smaller example with the same error:

fn main() {
    let mut state = 0;
    println!("{:?}", state);

    let ch = 'z';

    state = match ch  {
        bar => 1,
    };
    println!("{:?}", state);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

3 participants