From 4bc48480c08b9749e6b7f1701a1e03529496382d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 30 Apr 2018 15:31:37 -0700 Subject: [PATCH] Skip checking for unused mutable locals that have no name --- src/librustc_mir/borrow_check/mod.rs | 6 +++--- .../compile-fail/nll/unused-mut-issue-50343.rs | 17 +++++++++++++++++ src/test/run-pass/nll/issue-50343.rs | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/nll/unused-mut-issue-50343.rs create mode 100644 src/test/run-pass/nll/issue-50343.rs diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 3145be7df85..4b714100816 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 or the MIT license +// , 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 or the MIT license +// , 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(); +} -- 2.44.0