Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 4 pull requests #94717

Closed
wants to merge 11 commits into from

Commits on Jan 29, 2022

  1. Configuration menu
    Copy the full SHA
    19645ac View commit details
    Browse the repository at this point in the history

Commits on Mar 3, 2022

  1. Configuration menu
    Copy the full SHA
    24fe35a View commit details
    Browse the repository at this point in the history
  2. Fix doctests.

    m-ou-se committed Mar 3, 2022
    Configuration menu
    Copy the full SHA
    6b46a52 View commit details
    Browse the repository at this point in the history

Commits on Mar 4, 2022

  1. Use '_ for irrelevant lifetimes in Debug impl.

    Co-authored-by: Daniel Henry-Mantilla <[email protected]>
    m-ou-se and danielhenrymantilla authored Mar 4, 2022
    Configuration menu
    Copy the full SHA
    9099353 View commit details
    Browse the repository at this point in the history

Commits on Mar 7, 2022

  1. Configuration menu
    Copy the full SHA
    776be7e View commit details
    Browse the repository at this point in the history
  2. Use f instead of || f().

    Co-authored-by: Mark Rousskov <[email protected]>
    m-ou-se and Mark-Simulacrum authored Mar 7, 2022
    Configuration menu
    Copy the full SHA
    a3d269e View commit details
    Browse the repository at this point in the history

Commits on Mar 8, 2022

  1. update Miri

    RalfJung committed Mar 8, 2022
    Configuration menu
    Copy the full SHA
    5756239 View commit details
    Browse the repository at this point in the history
  2. Rollup merge of rust-lang#92385 - clarfonthey:const_option, r=fee1-dead

    Add Result::{ok, err, and, or, unwrap_or} as const
    
    Already opened tracking issue rust-lang#92384.
    
    I don't think that this should actually cause any issues as long as the constness is unstable, but we may want to double-check that this doesn't get interpreted as a weird `Drop` bound even for non-const usages.
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    b5ac2cb View commit details
    Browse the repository at this point in the history
  3. Rollup merge of rust-lang#94559 - m-ou-se:thread-scope-spawn-closure-…

    …without-arg, r=Mark-Simulacrum
    
    Remove argument from closure in thread::Scope::spawn.
    
    This implements `@danielhenrymantilla's` [suggestion](rust-lang#93203 (comment)) 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 `&'scope Scope<'scope, 'env>`:
    
    ```diff
    - pub struct Scope<'env> { .. };
    + pub struct Scope<'scope, 'env: 'scope> { .. }
    
      pub fn scope<'env, F, T>(f: F) -> T
      where
    -     F: FnOnce(&Scope<'env>) -> T;
    +     F: for<'scope> FnOnce(&'scope Scope<'scope, 'env>) -> 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<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
    +     pub fn spawn<F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
          where
    -         F: FnOnce(&Scope<'env>) -> T + Send + 'env,
    +         F: FnOnce() -> 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(|| ...);
          });
      });
    ```
    
    <details><summary>And, as a bonus, errors get <em>slightly</em> better because now any lifetime issues point to the outermost <code>s</code> (since there is only one <code>s</code>), rather than the innermost <code>s</code>, making it clear that the lifetime lasts for the entire <code>thread::scope</code>.
    
    </summary>
    
    ```diff
      error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
       --> src/main.rs:9:21
        |
    - 7 |         s.spawn(|s| {
    -   |                  - has type `&Scope<'1>`
    + 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`
       --> 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
        |                     ++++
    "
    ```
    </details>
    
    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.)
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    8ea834a View commit details
    Browse the repository at this point in the history
  4. Rollup merge of rust-lang#94712 - kckeiks:remove-rwlock-read-error-as…

    …sumption, r=Mark-Simulacrum
    
    promot debug_assert to assert
    
    Fixes rust-lang#94705
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    3e0f5c3 View commit details
    Browse the repository at this point in the history
  5. Rollup merge of rust-lang#94716 - RalfJung:miri, r=RalfJung

    update Miri
    
    Fixes rust-lang#94687
    r? `@rust-lang/miri`
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    de31dcf View commit details
    Browse the repository at this point in the history