Allow MIR borrowck to catch unused mutable locals

This commit is contained in:
Keith Yeung 2018-02-28 01:09:08 -08:00
parent 1eb0cef62b
commit 2338adf48c
2 changed files with 44 additions and 7 deletions

View file

@ -247,6 +247,20 @@ impl<'tcx> Mir<'tcx> {
})
}
/// Returns an iterator over all user-declared mutable locals.
#[inline]
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item=Local> + 'a {
(self.arg_count+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 && decl.mutability == Mutability::Mut {
Some(local)
} else {
None
}
})
}
/// Returns an iterator over all function arguments.
#[inline]
pub fn args_iter(&self) -> impl Iterator<Item=Local> {