diff options
| author | bors <bors@rust-lang.org> | 2018-05-04 08:22:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-04 08:22:13 +0000 |
| commit | 22a41e45157869b9a4d2ab7a21c7142a93d35cb1 (patch) | |
| tree | e17da6cbd2c5e0abf1cfbc91be40f30e6db8a535 | |
| parent | e78c51adc2a51fbec1d254d2ba8d8718688c7429 (diff) | |
| parent | 4bc48480c08b9749e6b7f1701a1e03529496382d (diff) | |
| download | rust-22a41e45157869b9a4d2ab7a21c7142a93d35cb1.tar.gz rust-22a41e45157869b9a4d2ab7a21c7142a93d35cb1.zip | |
Auto merge of #50409 - KiChjang:issue-50343, r=nikomatsakis
Skip checking for unused mutable locals that have no name Fixes #50343.
| -rw-r--r-- | src/librustc_mir/borrow_check/mod.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/nll/unused-mut-issue-50343.rs | 17 | ||||
| -rw-r--r-- | src/test/run-pass/nll/issue-50343.rs | 17 |
3 files changed, 37 insertions, 3 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 7e1c20dff6a..c619f350f58 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -295,10 +295,10 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( continue; } - // Skip over locals that begin with an underscore + // Skip over locals that begin with an underscore or have no name match local_decl.name { - Some(name) if name.as_str().starts_with("_") => continue, - _ => {}, + Some(name) => if name.as_str().starts_with("_") { continue; }, + None => continue, } let source_info = local_decl.source_info; diff --git a/src/test/compile-fail/nll/unused-mut-issue-50343.rs b/src/test/compile-fail/nll/unused-mut-issue-50343.rs new file mode 100644 index 00000000000..e9110b8114b --- /dev/null +++ b/src/test/compile-fail/nll/unused-mut-issue-50343.rs @@ -0,0 +1,17 @@ +// Copyright 2012 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. + +#![feature(nll)] +#![deny(unused_mut)] + +fn main() { + vec![(42, 22)].iter().map(|(mut x, _y)| ()).count(); + //~^ ERROR: variable does not need to be mutable +} diff --git a/src/test/run-pass/nll/issue-50343.rs b/src/test/run-pass/nll/issue-50343.rs new file mode 100644 index 00000000000..f01d99c68cc --- /dev/null +++ b/src/test/run-pass/nll/issue-50343.rs @@ -0,0 +1,17 @@ +// Copyright 2012 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. + +#![feature(nll)] +#![deny(unused_mut)] + +fn main() { + vec![42].iter().map(|_| ()).count(); + vec![(42, 22)].iter().map(|(_x, _y)| ()).count(); +} |
