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 8 pull requests #94734

Merged
merged 23 commits into from
Mar 8, 2022
Merged

Rollup of 8 pull requests #94734

merged 23 commits into from
Mar 8, 2022

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
  3. Configuration menu
    Copy the full SHA
    700ec66 View commit details
    Browse the repository at this point in the history

Commits on Mar 4, 2022

  1. Generalize get_nullable_type to allow types where null is all-ones.

    Generalize get_nullable_type to accept types that have an all-ones bit
    pattern as their sentry "null" value.
    
    This will allow [`OwnedFd`], [`BorrowedFd`], [`OwnedSocket`], and
    [`BorrowedSocket`] to be marked with
    `#[rustc_nonnull_optimization_guaranteed]`, which will allow
    `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and
    `Option<BorrowedSocket>` to be used in FFI declarations, as described
    in the [I/O safety RFC].
    
    For example, it will allow a function like `open` on Unix and `WSASocketW`
    on Windows to be declared using `Option<OwnedFd>` and `Option<OwnedSocket>`
    return types, respectively.
    
    The actual change to add `#[rustc_nonnull_optimization_guaranteed]`
    to the abovementioned types will be a separate PR, as it'll depend on
    having this patch in the stage0 compiler.
    
    Also, update the diagnostics to mention that "niche optimizations" are
    used in libstd as well as libcore, as `rustc_layout_scalar_valid_range_start`
    and `rustc_layout_scalar_valid_range_end` are already in use in libstd.
    
    [`OwnedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L49
    [`BorrowedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L29
    [`OwnedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L51
    [`BorrowedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L29
    [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
    sunfishcode committed Mar 4, 2022
    Configuration menu
    Copy the full SHA
    86b4658 View commit details
    Browse the repository at this point in the history
  2. Use '_ for irrelevant lifetimes in Debug impl.

    Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
    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
    fbd4cfa View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    776be7e View commit details
    Browse the repository at this point in the history
  3. Use f instead of || f().

    Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
    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. When encountering a match expr with no arms, suggest it

    Given
    
    ```rust
    match Some(42) {}
    ```
    
    suggest
    
    ```rust
    match Some(42) { None | Some(_) => todo!(), }
    ```
    estebank committed Mar 8, 2022
    Configuration menu
    Copy the full SHA
    02a3830 View commit details
    Browse the repository at this point in the history
  2. When finding a match expr with a single arm that requires more, sugge…

    …st it
    
    Given
    
    ```rust
    match Some(42) {
        Some(0) => {}
    }
    ```
    
    suggest
    
    ```rust
    match Some(42) {
        Some(0) => {}
        None | Some(_) => todo!(),
    }
    ```
    estebank committed Mar 8, 2022
    Configuration menu
    Copy the full SHA
    2383858 View commit details
    Browse the repository at this point in the history
  3. When finding a match expr with multiple arms that requires more, sugg…

    …est it
    
    Given
    
    ```rust
    match Some(42) {
        Some(0) => {}
        Some(1) => {}
    }
    ```
    
    suggest
    
    ```rust
    match Some(42) {
        Some(0) => {}
        Some(1) => {}
        None | Some(_) => todo!(),
    }
    ```
    estebank committed Mar 8, 2022
    Configuration menu
    Copy the full SHA
    084ca79 View commit details
    Browse the repository at this point in the history
  4. Point at uncovered variants in enum definition in note instead of a…

    … `span_label`
    
    This makes the order of the output always consistent:
    
    1. Place of the `match` missing arms
    2. The `enum` definition span
    3. The structured suggestion to add a fallthrough arm
    estebank committed Mar 8, 2022
    Configuration menu
    Copy the full SHA
    ab4feea View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    6f45f73 View commit details
    Browse the repository at this point in the history
  6. ⬆️ rust-analyzer

    lnicola committed Mar 8, 2022
    Configuration menu
    Copy the full SHA
    a3158c7 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#91993 - estebank:match-span-suggestion, r=o…

    …li-obk
    
    Tweak output for non-exhaustive `match` expression
    
    * Provide structured suggestion when missing `match` arms
    * Move pointing at the missing variants *after* the main error
    
    <img width="1164" alt="" src="https://user-images.githubusercontent.com/1606434/146312085-b57ef4a3-6e96-4f32-aa2a-803637d9eeba.png">
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    e3ea69f View commit details
    Browse the repository at this point in the history
  8. 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
    e22331c View commit details
    Browse the repository at this point in the history
  9. 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
    aec535f View commit details
    Browse the repository at this point in the history
  10. Rollup merge of rust-lang#94580 - xFrednet:55112-only-reason-in-lint-…

    …attr, r=lcnr
    
    Emit `unused_attributes` if a level attr only has a reason
    
    Fixes a comment from `compiler/rustc_lint/src/levels.rs`. Lint level attributes that only contain a reason will also trigger the `unused_attribute` lint. The lint now also checks for the `expect` lint level.
    
    That's it, have a great rest of the day for everyone reasoning this 🙃
    
    cc: rust-lang#55112
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    83ed227 View commit details
    Browse the repository at this point in the history
  11. Rollup merge of rust-lang#94586 - sunfishcode:sunfishcode/io-lifetime…

    …s-tests, r=davidtwco
    
    Generalize `get_nullable_type` to allow types where null is all-ones.
    
    Generalize get_nullable_type to accept types that have an all-ones bit
    pattern as their sentry "null" value.
    
    This will allow [`OwnedFd`], [`BorrowedFd`], [`OwnedSocket`], and
    [`BorrowedSocket`] to be marked with
    `#[rustc_nonnull_optimization_guaranteed]`, which will allow
    `Option<OwnedFd>`, `Option<BorrowedFd>`, `Option<OwnedSocket>`, and
    `Option<BorrowedSocket>` to be used in FFI declarations, as described
    in the [I/O safety RFC].
    
    For example, it will allow a function like `open` on Unix and `WSASocketW`
    on Windows to be declared using `Option<OwnedFd>` and `Option<OwnedSocket>`
    return types, respectively.
    
    The actual change to add `#[rustc_nonnull_optimization_guaranteed]`
    to the abovementioned types will be a separate PR, as it'll depend on
    having this patch in the stage0 compiler.
    
    Also, update the diagnostics to mention that "niche optimizations" are
    used in libstd as well as libcore, as `rustc_layout_scalar_valid_range_start`
    and `rustc_layout_scalar_valid_range_end` are already in use in libstd.
    
    [`OwnedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L49
    [`BorrowedFd`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/fd/owned.rs#L29
    [`OwnedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L51
    [`BorrowedSocket`]: https://github.com/rust-lang/rust/blob/c9dc44be24c58ff13ce46416c4b97ab5c1bd8429/library/std/src/os/windows/io/socket.rs#L29
    [I/O safety RFC]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md#ownedfd-and-borrowedfdfd-1
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    e4a3627 View commit details
    Browse the repository at this point in the history
  12. Rollup merge of rust-lang#94708 - notriddle:notriddle/cargo-toml-warn…

    …ing, r=lcnr
    
    diagnostics: only talk about `Cargo.toml` if running under Cargo
    
    Fixes rust-lang#94646
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    98d027c View commit details
    Browse the repository at this point in the history
  13. 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
    a077e44 View commit details
    Browse the repository at this point in the history
  14. Rollup merge of rust-lang#94726 - lnicola:rust-analyzer-2022-03-08, r…

    …=lnicola
    
    ⬆️ rust-analyzer
    
    r? `@ghost`
    matthiaskrgr authored Mar 8, 2022
    Configuration menu
    Copy the full SHA
    b879216 View commit details
    Browse the repository at this point in the history