Skip to content

Commit 22a41e4

Browse files
committed
Auto merge of #50409 - KiChjang:issue-50343, r=nikomatsakis
Skip checking for unused mutable locals that have no name Fixes #50343.
2 parents e78c51a + 4bc4848 commit 22a41e4

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/librustc_mir/borrow_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
295295
continue;
296296
}
297297

298-
// Skip over locals that begin with an underscore
298+
// Skip over locals that begin with an underscore or have no name
299299
match local_decl.name {
300-
Some(name) if name.as_str().starts_with("_") => continue,
301-
_ => {},
300+
Some(name) => if name.as_str().starts_with("_") { continue; },
301+
None => continue,
302302
}
303303

304304
let source_info = local_decl.source_info;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 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+
#![feature(nll)]
12+
#![deny(unused_mut)]
13+
14+
fn main() {
15+
vec![(42, 22)].iter().map(|(mut x, _y)| ()).count();
16+
//~^ ERROR: variable does not need to be mutable
17+
}

src/test/run-pass/nll/issue-50343.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2012 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+
#![feature(nll)]
12+
#![deny(unused_mut)]
13+
14+
fn main() {
15+
vec![42].iter().map(|_| ()).count();
16+
vec![(42, 22)].iter().map(|(_x, _y)| ()).count();
17+
}

0 commit comments

Comments
 (0)