Skip to content

Commit 1fd8e4c

Browse files
committed
auto merge of #18014 : hirschenberger/rust/issue-17999, r=alexcrichton
Fix issue #17999 (Unused variables inside `for` are not detected)
2 parents a1e2eb0 + af2f538 commit 1fd8e4c

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,8 @@ fn check_expr(this: &mut Liveness, expr: &Expr) {
14711471
this.pat_bindings(&**pat, |this, ln, var, sp, id| {
14721472
this.warn_about_unused(sp, id, ln, var);
14731473
});
1474+
1475+
visit::walk_expr(this, expr);
14741476
}
14751477

14761478
// no correctness conditions related to liveness

src/test/compile-fail/issue-17999.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(unused_variable)]
12+
13+
fn main() {
14+
for _ in range(1i, 101) {
15+
let x = (); //~ ERROR: unused variable: `x`
16+
match () {
17+
a => {} //~ ERROR: unused variable: `a`
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)