Skip to content

Commit 8c607ea

Browse files
committed
Skip implicit self argument for closures
1 parent 180e242 commit 8c607ea

File tree

1 file changed

+10
-3
lines changed
  • src/librustc_mir/borrow_check

1 file changed

+10
-3
lines changed

src/librustc_mir/borrow_check/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
265265
if let ClearCrossCrate::Set(ref vsi) = mbcx.mir.visibility_scope_info {
266266
let local_decl = &mbcx.mir.local_decls[local];
267267

268+
// Skip implicit `self` argument for closures
269+
if local.index() == 1 && tcx.is_closure(mbcx.mir_def_id) {
270+
continue;
271+
}
272+
268273
// Skip over locals that begin with an underscore
269274
match local_decl.name {
270275
Some(name) if name.as_str().starts_with("_") => continue,
@@ -1890,9 +1895,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18901895
match tnm.mutbl {
18911896
// `*const` raw pointers are not mutable
18921897
hir::MutImmutable => return Err(place),
1893-
// `*mut` raw pointers are always mutable, regardless of context
1894-
// The users have to check by themselve.
1895-
hir::MutMutable => return Ok((place, is_local_mutation_allowed)),
1898+
// `*mut` raw pointers are always mutable, regardless of
1899+
// context. The users have to check by themselves.
1900+
hir::MutMutable => {
1901+
return Ok((place, is_local_mutation_allowed));
1902+
}
18961903
}
18971904
}
18981905
// `Box<T>` owns its content, so mutable if its location is mutable

0 commit comments

Comments
 (0)