]> git.lizzy.rs Git - rust.git/commitdiff
Skip implicit self argument for closures
authorKeith Yeung <kungfukeith11@gmail.com>
Fri, 23 Mar 2018 08:59:56 +0000 (01:59 -0700)
committerKeith Yeung <kungfukeith11@gmail.com>
Sat, 28 Apr 2018 08:55:26 +0000 (01:55 -0700)
src/librustc_mir/borrow_check/mod.rs

index 9da5d1dcdcd4fac5f347a095f0f7f049608dce29..a70c601bd1a06c16bdc3b14c0f556152c76aa633 100644 (file)
@@ -265,6 +265,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
         if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.visibility_scope_info {
             let local_decl = &mbcx.mir.local_decls[local];
 
+            // Skip implicit `self` argument for closures
+            if local.index() == 1 && tcx.is_closure(mbcx.mir_def_id) {
+                continue;
+            }
+
             // Skip over locals that begin with an underscore
             match local_decl.name {
                 Some(name) if name.as_str().starts_with("_") => continue,
@@ -1890,9 +1895,11 @@ fn is_mutable<'d>(
                                 match tnm.mutbl {
                                     // `*const` raw pointers are not mutable
                                     hir::MutImmutable => return Err(place),
-                                    // `*mut` raw pointers are always mutable, regardless of context
-                                    // The users have to check by themselve.
-                                    hir::MutMutable => return Ok((place, is_local_mutation_allowed)),
+                                    // `*mut` raw pointers are always mutable, regardless of
+                                    // context. The users have to check by themselves.
+                                    hir::MutMutable => {
+                                        return Ok((place, is_local_mutation_allowed));
+                                    }
                                 }
                             }
                             // `Box<T>` owns its content, so mutable if its location is mutable