diff options
| author | Keith Yeung <kungfukeith11@gmail.com> | 2018-02-28 01:09:08 -0800 |
|---|---|---|
| committer | Keith Yeung <kungfukeith11@gmail.com> | 2018-04-28 01:55:23 -0700 |
| commit | 2338adf48cbb6bfcf03c5f00f48ee63014d793cd (patch) | |
| tree | 1b40817d44585719634e9c4dd937254961090273 /src/librustc | |
| parent | 1eb0cef62b3e83bf7ce6bc7d1b99e130648a55e8 (diff) | |
Allow MIR borrowck to catch unused mutable locals
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/mir/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index c525c4ed651..501f77547e2 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -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> { |
