<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/library/std/src/thread/scoped.rs, branch 1.76.0</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.76.0</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.76.0'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2022-12-05T08:42:36+00:00</updated>
<entry>
<title>fix dupe word typos</title>
<updated>2022-12-05T08:42:36+00:00</updated>
<author>
<name>Rageking8</name>
<email>tomleetyt@gmail.com</email>
</author>
<published>2022-12-05T08:42:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=58110572fb23e0ad1944bdf3d8cdb3f84cb91aa2'/>
<id>urn:sha1:58110572fb23e0ad1944bdf3d8cdb3f84cb91aa2</id>
<content type='text'>
</content>
</entry>
<entry>
<title>fix data race in thread::scope</title>
<updated>2022-06-27T20:50:42+00:00</updated>
<author>
<name>Ralf Jung</name>
<email>post@ralfj.de</email>
</author>
<published>2022-06-25T20:30:57+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=af0c1fe83dcbb3b5b651962095ed9784a6746308'/>
<id>urn:sha1:af0c1fe83dcbb3b5b651962095ed9784a6746308</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Improve docs for `is_running` to explain use case</title>
<updated>2022-06-20T20:42:49+00:00</updated>
<author>
<name>Josh Triplett</name>
<email>josh@joshtriplett.org</email>
</author>
<published>2022-02-15T22:51:24+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=7098a714e8dffe32ae10a27a18a3d73b23431a55'/>
<id>urn:sha1:7098a714e8dffe32ae10a27a18a3d73b23431a55</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Stabilize scoped threads.</title>
<updated>2022-06-11T13:01:52+00:00</updated>
<author>
<name>Mara Bos</name>
<email>m-ou.se@m-ou.se</email>
</author>
<published>2022-06-09T08:53:45+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=ae0a533b0b1f53a9fce48b51d2ff4cc9f3c41699'/>
<id>urn:sha1:ae0a533b0b1f53a9fce48b51d2ff4cc9f3c41699</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Don't stabilize ScopedJoinHandle::is_finished yet.</title>
<updated>2022-03-30T11:59:27+00:00</updated>
<author>
<name>Mara Bos</name>
<email>m-ou.se@m-ou.se</email>
</author>
<published>2022-03-30T11:59:27+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=25eb06077997bca0b20f0ef7d828672a8140519e'/>
<id>urn:sha1:25eb06077997bca0b20f0ef7d828672a8140519e</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Stabilize thread::is_finished</title>
<updated>2022-03-20T02:53:26+00:00</updated>
<author>
<name>Jubilee Young</name>
<email>workingjubilee@gmail.com</email>
</author>
<published>2022-03-20T02:53:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=5a25e228eb7df1f8d227460c577215e5c75794b2'/>
<id>urn:sha1:5a25e228eb7df1f8d227460c577215e5c75794b2</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Use implicit capture syntax in format_args</title>
<updated>2022-03-10T15:23:40+00:00</updated>
<author>
<name>T-O-R-U-S</name>
<email>bageliq@protonmail.com</email>
</author>
<published>2022-02-12T19:16:17+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=72a25d05bf1a4b155d74139ef700ff93af6d8e22'/>
<id>urn:sha1:72a25d05bf1a4b155d74139ef700ff93af6d8e22</id>
<content type='text'>
This updates the standard library's documentation to use the new syntax. The
documentation is worthwhile to update as it should be more idiomatic
(particularly for features like this, which are nice for users to get acquainted
with). The general codebase is likely more hassle than benefit to update: it'll
hurt git blame, and generally updates can be done by folks updating the code if
(and when) that makes things more readable with the new format.

A few places in the compiler and library code are updated (mostly just due to
already having been done when this commit was first authored).
</content>
</entry>
<entry>
<title>Add documentation about lifetimes to thread::scope.</title>
<updated>2022-03-09T14:20:00+00:00</updated>
<author>
<name>Mara Bos</name>
<email>m-ou.se@m-ou.se</email>
</author>
<published>2022-03-09T09:17:49+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=4d56c1563c5ae75acbcb8c163296561a6e17e47a'/>
<id>urn:sha1:4d56c1563c5ae75acbcb8c163296561a6e17e47a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Rollup merge of #94559 - m-ou-se:thread-scope-spawn-closure-without-arg, r=Mark-Simulacrum</title>
<updated>2022-03-08T10:04:51+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2022-03-08T10:04:51+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=aec535f8051c7cf00b1e373a05893b2cb580eeac'/>
<id>urn:sha1:aec535f8051c7cf00b1e373a05893b2cb580eeac</id>
<content type='text'>
Remove argument from closure in thread::Scope::spawn.

This implements ```@danielhenrymantilla's``` [suggestion](https://github.com/rust-lang/rust/issues/93203#issuecomment-1040798286) for improving the scoped threads interface.

Summary:

The `Scope` type gets an extra lifetime argument, which represents basically its own lifetime that will be used in `&amp;'scope Scope&lt;'scope, 'env&gt;`:

```diff
- pub struct Scope&lt;'env&gt; { .. };
+ pub struct Scope&lt;'scope, 'env: 'scope&gt; { .. }

  pub fn scope&lt;'env, F, T&gt;(f: F) -&gt; T
  where
-     F: FnOnce(&amp;Scope&lt;'env&gt;) -&gt; T;
+     F: for&lt;'scope&gt; FnOnce(&amp;'scope Scope&lt;'scope, 'env&gt;) -&gt; T;
```

This simplifies the `spawn` function, which now no longer passes an argument to the closure you give it, and now uses the `'scope` lifetime for everything:

```diff
-     pub fn spawn&lt;'scope, F, T&gt;(&amp;'scope self, f: F) -&gt; ScopedJoinHandle&lt;'scope, T&gt;
+     pub fn spawn&lt;F, T&gt;(&amp;'scope self, f: F) -&gt; ScopedJoinHandle&lt;'scope, T&gt;
      where
-         F: FnOnce(&amp;Scope&lt;'env&gt;) -&gt; T + Send + 'env,
+         F: FnOnce() -&gt; T + Send + 'scope,
-         T: Send + 'env;
+         T: Send + 'scope;
```

The only difference the user will notice, is that their closure now takes no arguments anymore, even when spawning threads from spawned threads:

```diff
  thread::scope(|s| {
-     s.spawn(|_| {
+     s.spawn(|| {
          ...
      });
-     s.spawn(|s| {
+     s.spawn(|| {
          ...
-         s.spawn(|_| ...);
+         s.spawn(|| ...);
      });
  });
```

&lt;details&gt;&lt;summary&gt;And, as a bonus, errors get &lt;em&gt;slightly&lt;/em&gt; better because now any lifetime issues point to the outermost &lt;code&gt;s&lt;/code&gt; (since there is only one &lt;code&gt;s&lt;/code&gt;), rather than the innermost &lt;code&gt;s&lt;/code&gt;, making it clear that the lifetime lasts for the entire &lt;code&gt;thread::scope&lt;/code&gt;.

&lt;/summary&gt;

```diff
  error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
   --&gt; src/main.rs:9:21
    |
- 7 |         s.spawn(|s| {
-   |                  - has type `&amp;Scope&lt;'1&gt;`
+ 6 |     thread::scope(|s| {
+   |                    - lifetime `'1` appears in the type of `s`
  9 |             s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
    |                     ^^                  - `a` is borrowed here
    |                     |
    |                     may outlive borrowed value `a`
    |
  note: function requires argument type to outlive `'1`
   --&gt; src/main.rs:9:13
    |
  9 |             s.spawn(|| println!("{:?}", a)); // might run after `a` is dropped
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword
    |
  9 |             s.spawn(move || println!("{:?}", a)); // might run after `a` is dropped
    |                     ++++
"
```
&lt;/details&gt;

The downside is that the signature of `scope` and `Scope` gets slightly more complex, but in most cases the user wouldn't need to write those, as they just use the argument provided by `thread::scope` without having to name its type.

Another downside is that this does not work nicely in Rust 2015 and Rust 2018, since in those editions, `s` would be captured by reference and not by copy. In those editions, the user would need to use `move ||` to capture `s` by copy. (Which is what the compiler suggests in the error.)
</content>
</entry>
<entry>
<title>Use `f` instead of `|| f()`.</title>
<updated>2022-03-07T22:14:02+00:00</updated>
<author>
<name>Mara Bos</name>
<email>m-ou.se@m-ou.se</email>
</author>
<published>2022-03-07T22:14:02+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=a3d269e91cceb4d6234668014930f81fff587ff3'/>
<id>urn:sha1:a3d269e91cceb4d6234668014930f81fff587ff3</id>
<content type='text'>
Co-authored-by: Mark Rousskov &lt;mark.simulacrum@gmail.com&gt;</content>
</entry>
</feed>
