Skip to content

Commit b03939b

Browse files
committed
rollup merge of rust-lang#23619: steveklabnik/gh23220
Fixes rust-lang#23571 I _think_ this is better, but other suggestions welcome too.
2 parents a78eb53 + 81801f2 commit b03939b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/doc/intro.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,16 @@ It gives us this error:
446446
error: aborting due to previous error
447447
```
448448
449-
It mentions that "captured outer variable in an `FnMut` closure".
450-
Because we declared the closure as a moving closure, and it referred
451-
to `numbers`, the closure will try to take ownership of the
452-
vector. But the closure itself is created in a loop, and hence we will
453-
actually create three closures, one for every iteration of the
454-
loop. This means that all three of those closures would try to own
455-
`numbers`, which is impossible -- `numbers` must have just one
456-
owner. Rust detects this and gives us the error: we claim that
457-
`numbers` has ownership, but our code tries to make three owners. This
458-
may cause a safety problem, so Rust disallows it.
449+
This is a little confusing because there are two closures here: the one passed
450+
to `map`, and the one passed to `thread::scoped`. In this case, the closure for
451+
`thread::scoped` is attempting to reference `numbers`, a `Vec<i32>`. This
452+
closure is a `FnOnce` closure, as that’s what `thread::scoped` takes as an
453+
argument. `FnOnce` closures take ownership of their environment. That’s fine,
454+
but there’s one detail: because of `map`, we’re going to make three of these
455+
closures. And since all three try to take ownership of `numbers`, that would be
456+
a problem. That’s what it means by ‘cannot move out of captured outer
457+
variable’: our `thread::scoped` closure wants to take ownership, and it can’t,
458+
because the closure for `map` won’t let it.
459459
460460
What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
461461
*Arc* stands for "atomically reference counted". In other words, an Arc will

0 commit comments

Comments
 (0)