From c80fc88829eec9b3b7759cffdbcb49bc778eefef Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 30 Apr 2018 15:31:37 -0700 Subject: [PATCH] Only check for unused mut user variables and not all arguments --- src/librustc/mir/mod.rs | 4 +--- src/test/run-pass/nll/issue-50343.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/nll/issue-50343.rs diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index c26b3014e53dd..213af84af87b8 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -254,9 +254,7 @@ impl<'tcx> Mir<'tcx> { (1..self.local_decls.len()).filter_map(move |index| { let local = Local::new(index); let decl = &self.local_decls[local]; - if (decl.is_user_variable || index < self.arg_count + 1) - && decl.mutability == Mutability::Mut - { + if decl.is_user_variable && decl.mutability == Mutability::Mut { Some(local) } else { None 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 0000000000000..17acd1bcf9eda --- /dev/null +++ b/src/test/run-pass/nll/issue-50343.rs @@ -0,0 +1,16 @@ +// 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 foo<'r>(_: &'r ()) -> &'r () { &() } + +fn main() { }