Skip to content

Commit

Permalink
Fix issue rust-lang#17999 (Unused variables inside for are not dete…
Browse files Browse the repository at this point in the history
…cted)
  • Loading branch information
hirschenberger committed Oct 13, 2014
1 parent 4a382d7 commit af2f538
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,8 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
this.pat_bindings(&**pat, |this, ln, var, sp, id| {
this.warn_about_unused(sp, id, ln, var);
});

visit::walk_expr(this, expr);
}

// no correctness conditions related to liveness
Expand Down
20 changes: 20 additions & 0 deletions src/test/compile-fail/issue-17999.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(unused_variable)]

fn main() {
for _ in range(1i, 101) {
let x = (); //~ ERROR: unused variable: `x`
match () {
a => {} //~ ERROR: unused variable: `a`
}
}
}

0 comments on commit af2f538

Please sign in to comment.