diff options
| author | Falco Hirschenberger <falco.hirschenberger@gmail.com> | 2014-10-13 23:15:07 +0200 |
|---|---|---|
| committer | Falco Hirschenberger <falco.hirschenberger@gmail.com> | 2014-10-13 23:15:07 +0200 |
| commit | af2f538390f2fd2395edc23e98cbaa55d8177f9e (patch) | |
| tree | 713e0a9ad2d4d455e6da9a18bc7491aeb8786757 | |
| parent | 4a382d7c4743775e9ee87735ed606b0a673d8ed5 (diff) | |
| download | rust-af2f538390f2fd2395edc23e98cbaa55d8177f9e.tar.gz rust-af2f538390f2fd2395edc23e98cbaa55d8177f9e.zip | |
Fix issue #17999 (Unused variables inside `for` are not detected)
| -rw-r--r-- | src/librustc/middle/liveness.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-17999.rs | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 2176cd56589..dea17b2ff02 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -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 diff --git a/src/test/compile-fail/issue-17999.rs b/src/test/compile-fail/issue-17999.rs new file mode 100644 index 00000000000..4d4b40ed12d --- /dev/null +++ b/src/test/compile-fail/issue-17999.rs @@ -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` + } + } +} |
