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 16 pull requests #101114

Closed
wants to merge 57 commits into from

Commits on Jul 13, 2022

  1. Add a File::create_new constructor

    We have `File::create` for creating a file or opening an existing file,
    but the secure way to guarantee creating a new file requires a longhand
    invocation via `OpenOptions`.
    
    Add `File::create_new` to handle this case, to make it easier for people
    to do secure file creation.
    joshtriplett committed Jul 13, 2022
    Configuration menu
    Copy the full SHA
    e540425 View commit details
    Browse the repository at this point in the history

Commits on Aug 4, 2022

  1. std::io: migrate ReadBuf to BorrowBuf/BorrowCursor

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 4, 2022
    Configuration menu
    Copy the full SHA
    c1aae4d View commit details
    Browse the repository at this point in the history
  2. Add some docs for BorrowBuf

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 4, 2022
    Configuration menu
    Copy the full SHA
    b56cf67 View commit details
    Browse the repository at this point in the history

Commits on Aug 5, 2022

  1. non-linux platforms

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 5, 2022
    Configuration menu
    Copy the full SHA
    1a2122f View commit details
    Browse the repository at this point in the history

Commits on Aug 9, 2022

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

Commits on Aug 14, 2022

  1. Start uplifting clippy::for_loops_over_fallibles

    I refactored the code:
    - Removed handling of methods, as it felt entirely unnecessary
    - Removed clippy utils (obviously...)
    - Used some shiny compiler features
      (let-else is very handy for lints 👀)
    - I also renamed the lint to `for_loop_over_fallibles` (note: no `s`).
      I'm not sure what's the naming convention here, so maybe I'm wrong.
    WaffleLapkin committed Aug 14, 2022
    Configuration menu
    Copy the full SHA
    7b4cd17 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    810cf60 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b661157 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7cf94ad View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    14b8f24 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    2bf213b View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    5128140 View commit details
    Browse the repository at this point in the history
  8. for_loop_over_fallibles: fix suggestion for "remove .next()" case

    if the iterator is used after the loop, we need to use `.by_ref()`
    WaffleLapkin committed Aug 14, 2022
    Configuration menu
    Copy the full SHA
    34815a9 View commit details
    Browse the repository at this point in the history
  9. for_loop_over_fallibles: don't use MachineApplicable

    The loop could contain `break;` that won't work with an `if let`
    WaffleLapkin committed Aug 14, 2022
    Configuration menu
    Copy the full SHA
    c4ab59e View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    41fccb1 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    86360f4 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    d7b8a65 View commit details
    Browse the repository at this point in the history

Commits on Aug 15, 2022

  1. remove an infinite loop

    WaffleLapkin committed Aug 15, 2022
    Configuration menu
    Copy the full SHA
    aed1ae4 View commit details
    Browse the repository at this point in the history

Commits on Aug 18, 2022

  1. Configuration menu
    Copy the full SHA
    71b8c89 View commit details
    Browse the repository at this point in the history
  2. Address reviewer comments

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 18, 2022
    Configuration menu
    Copy the full SHA
    ac70aea View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2022

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

Commits on Aug 24, 2022

  1. Configuration menu
    Copy the full SHA
    2a26987 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    36c42fa View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    63700a8 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    89c74e8 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    d61ecec View commit details
    Browse the repository at this point in the history
  6. error::Error: rename the chain method to sources

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 24, 2022
    Configuration menu
    Copy the full SHA
    80442f3 View commit details
    Browse the repository at this point in the history
  7. error::Error: rename the Demand arguments from req to demand

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 24, 2022
    Configuration menu
    Copy the full SHA
    b556a5b View commit details
    Browse the repository at this point in the history
  8. translations: rename warn_ to warning

    The macro warn_ was named like that because it the
    keyword warn is a built-in attribute and at the time
    this macro was created the word 'warning' was also
    taken.
    
    However it is no longer the case and we can rename
    warn_ to warning.
    beowolx committed Aug 24, 2022
    Configuration menu
    Copy the full SHA
    b508b50 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    4e97626 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    4ff5872 View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    d464d3a View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    8189a45 View commit details
    Browse the repository at this point in the history

Commits on Aug 25, 2022

  1. error::Error: remove some comments

    Signed-off-by: Nick Cameron <nrc@ncameron.org>
    nrc committed Aug 25, 2022
    Configuration menu
    Copy the full SHA
    9372c4f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    252c65e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    7529029 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    c3f568b View commit details
    Browse the repository at this point in the history

Commits on Aug 27, 2022

  1. Configuration menu
    Copy the full SHA
    b33c3d6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    aa76e13 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    fc3f3c3 View commit details
    Browse the repository at this point in the history
  4. unstable-book-gen: use std::fs::write

    I wrote this code in 2017 back when std::fs::write wasn't available.
    Also, use the t macro from tidy.
    est31 committed Aug 27, 2022
    Configuration menu
    Copy the full SHA
    4a82c21 View commit details
    Browse the repository at this point in the history

Commits on Aug 28, 2022

  1. Rollup merge of rust-lang#97015 - nrc:read-buf-cursor, r=Mark-Simulacrum

    std::io: migrate ReadBuf to BorrowBuf/BorrowCursor
    
    This PR replaces `ReadBuf` (used by the `Read::read_buf` family of methods) with `BorrowBuf` and `BorrowCursor`.
    
    The general idea is to split `ReadBuf` because its API is large and confusing. `BorrowBuf` represents a borrowed buffer which is mostly read-only and (other than for construction) deals only with filled vs unfilled segments. a `BorrowCursor` is a mostly write-only view of the unfilled part of a `BorrowBuf` which distinguishes between initialized and uninitialized segments. For `Read::read_buf`, the caller would create a `BorrowBuf`, then pass a `BorrowCursor` to `read_buf`.
    
    In addition to the major API split, I've made the following smaller changes:
    
    * Removed some methods entirely from the API (mostly the functionality can be replicated with two calls rather than a single one)
    * Unified naming, e.g., by replacing initialized with init and assume_init with set_init
    * Added an easy way to get the number of bytes written to a cursor (`written` method)
    
    As well as simplifying the API (IMO), this approach has the following advantages:
    
    * Since we pass the cursor by value, we remove the 'unsoundness footgun' where a malicious `read_buf` could swap out the `ReadBuf`.
    * Since `read_buf` cannot write into the filled part of the buffer, we prevent the filled part shrinking or changing which could cause underflow for the caller or unexpected behaviour.
    
    ## Outline
    
    ```rust
    pub struct BorrowBuf<'a>
    
    impl Debug for BorrowBuf<'_>
    
    impl<'a> From<&'a mut [u8]> for BorrowBuf<'a>
    impl<'a> From<&'a mut [MaybeUninit<u8>]> for BorrowBuf<'a>
    
    impl<'a> BorrowBuf<'a> {
        pub fn capacity(&self) -> usize
        pub fn len(&self) -> usize
        pub fn init_len(&self) -> usize
        pub fn filled(&self) -> &[u8]
        pub fn unfilled<'this>(&'this mut self) -> BorrowCursor<'this, 'a>
        pub fn clear(&mut self) -> &mut Self
        pub unsafe fn set_init(&mut self, n: usize) -> &mut Self
    }
    
    pub struct BorrowCursor<'buf, 'data>
    
    impl<'buf, 'data> BorrowCursor<'buf, 'data> {
        pub fn clone<'this>(&'this mut self) -> BorrowCursor<'this, 'data>
        pub fn capacity(&self) -> usize
        pub fn written(&self) -> usize
        pub fn init_ref(&self) -> &[u8]
        pub fn init_mut(&mut self) -> &mut [u8]
        pub fn uninit_mut(&mut self) -> &mut [MaybeUninit<u8>]
        pub unsafe fn as_mut(&mut self) -> &mut [MaybeUninit<u8>]
        pub unsafe fn advance(&mut self, n: usize) -> &mut Self
        pub fn ensure_init(&mut self) -> &mut Self
        pub unsafe fn set_init(&mut self, n: usize) -> &mut Self
        pub fn append(&mut self, buf: &[u8])
    }
    ```
    
    ## TODO
    
    * ~~Migrate non-unix libs and tests~~
    * ~~Naming~~
      * ~~`BorrowBuf` or `BorrowedBuf` or `SliceBuf`? (We might want an owned equivalent for the async IO traits)~~
      * ~~Should we rename the `readbuf` module? We might keep the name indicate it includes both the buf and cursor variations and someday the owned version too. Or we could change it. It is not publicly exposed, so it is not that important~~.
      * ~~`read_buf` method: we read into the cursor now, so the `_buf` suffix is a bit weird.~~
    * ~~Documentation~~
    * Tests are incomplete (I adjusted existing tests, but did not add new ones).
    
    cc rust-lang#78485, rust-lang#94741
    supersedes: rust-lang#95770, rust-lang#93359
    fixes rust-lang#93305
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    084bf8d View commit details
    Browse the repository at this point in the history
  2. Rollup merge of rust-lang#98301 - ortem:pretty-printers-nonzero, r=we…

    …sleywiser
    
    Add GDB/LLDB pretty-printers for NonZero types
    
    Add GDB/LLDB pretty-printers for `NonZero` types.
    These pretty-printers were originally implemented for IntelliJ Rust by ``@Kobzol`` in intellij-rust/intellij-rust#5270.
    
    Part of rust-lang#29392.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    e5ca6a6 View commit details
    Browse the repository at this point in the history
  3. Rollup merge of rust-lang#98801 - joshtriplett:file-create-new, r=thomcc

    Add a `File::create_new` constructor
    
    We have `File::create` for creating a file or opening an existing file,
    but the secure way to guarantee creating a new file requires a longhand
    invocation via `OpenOptions`.
    
    Add `File::create_new` to handle this case, to make it easier for people
    to do secure file creation.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    be9ed40 View commit details
    Browse the repository at this point in the history
  4. Rollup merge of rust-lang#99696 - WaffleLapkin:uplift, r=fee1-dead

    Uplift `clippy::for_loops_over_fallibles` lint into rustc
    
    This PR, as the title suggests, uplifts [`clippy::for_loops_over_fallibles`] lint into rustc. This lint warns for code like this:
    ```rust
    for _ in Some(1) {}
    for _ in Ok::<_, ()>(1) {}
    ```
    i.e. directly iterating over `Option` and `Result` using `for` loop.
    
    There are a number of suggestions that this PR adds (on top of what clippy suggested):
    1. If the argument (? is there a better name for that expression) of a `for` loop is a `.next()` call, then we can suggest removing it (or rather replacing with `.by_ref()` to allow iterator being used later)
       ```rust
        for _ in iter.next() {}
        // turns into
        for _ in iter.by_ref() {}
        ```
    2. (otherwise) We can suggest using `while let`, this is useful for non-iterator, iterator-like things like [async] channels
       ```rust
       for _ in rx.recv() {}
       // turns into
       while let Some(_) = rx.recv() {}
       ```
    3. If the argument type is `Result<impl IntoIterator, _>` and the body has a `Result<_, _>` type, we can suggest using `?`
       ```rust
       for _ in f() {}
       // turns into
       for _ in f()? {}
       ```
    4. To preserve the original behavior and clear intent, we can suggest using `if let`
       ```rust
       for _ in f() {}
       // turns into
       if let Some(_) = f() {}
       ```
    (P.S. `Some` and `Ok` are interchangeable depending on the type)
    
    I still feel that the lint wording/look is somewhat off, so I'll be happy to hear suggestions (on how to improve suggestions :D)!
    
    Resolves rust-lang#99272
    
    [`clippy::for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    049c73e View commit details
    Browse the repository at this point in the history
  5. Rollup merge of rust-lang#100337 - camelid:stabilize-io_read_to_strin…

    …g, r=JohnTitor
    
    Stabilize `std::io::read_to_string`
    
    Closes rust-lang#80218. 🎉
    
    This PR stabilizes the `std::io::read_to_string` function, with the following public API:
    
    ```rust
    pub fn read_to_string<R: Read>(reader: R) -> Result<String>;
    ```
    
    It's analogous to `std::fs::read_to_string` for files, but it works on anything that implements `io::Read`, including `io::stdin()`.
    
    See the tracking issue (rust-lang#80218) or documentation for details.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    b87b660 View commit details
    Browse the repository at this point in the history
  6. Rollup merge of rust-lang#100437 - compiler-errors:better-const-misma…

    …tch-err, r=oli-obk
    
    Improve const mismatch `FulfillmentError`
    
    Fixes rust-lang#100414
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    ea30a62 View commit details
    Browse the repository at this point in the history
  7. Rollup merge of rust-lang#100640 - reitermarkus:socket-display-buffer…

    …, r=thomcc
    
    Use `DisplayBuffer` for socket addresses.
    
    Continuation of rust-lang#100625 for socket addresses.
    
    Renames `net::addr` to `net::addr::socket`, `net::ip` to `net::addr::ip` and `net::ip::display_buffer::IpDisplayBuffer` to `net::addr::display_buffer::DisplayBuffer`.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    09496a8 View commit details
    Browse the repository at this point in the history
  8. Rollup merge of rust-lang#100885 - mzohreva:mz/sgx-export-cancel-type…

    …, r=Mark-Simulacrum
    
    Export Cancel from std::os::fortanix_sgx::usercalls::raw
    
    This was missed in rust-lang#100642
    
    cc `@raoulstrackx` and `@jethrogb`
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    9ccd9c3 View commit details
    Browse the repository at this point in the history
  9. Rollup merge of rust-lang#100898 - compiler-errors:too-many-expr-fiel…

    …ds, r=spastorino
    
    Do not report too many expr field candidates
    
    When considering "this expressions' field has a {field/method}" suggestions:
    1. Don't report methods that are out of scope
    2. Use `span_suggestions` instead of reporting each field candidate, which caps the number of suggestions to 4
    4. Blacklist some common traits like `Clone` and `Deref`
    
    Fixes rust-lang#100894
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    f83d275 View commit details
    Browse the repository at this point in the history
  10. Rollup merge of rust-lang#100955 - nrc:chain, r=joshtriplett

    Some papercuts on error::Error
    
    Renames the chain method, since I chain could mean anything and doesn't refer to a chain of sources (cc rust-lang#58520) (and adds a comment explaining why sources is not a provided method on Error). Renames arguments to the request method from `req` to `demand` since the type is `Demand` rather than Request or Requisition.
    
    r? `@yaahc`
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    0b8e6a2 View commit details
    Browse the repository at this point in the history
  11. Rollup merge of rust-lang#100959 - LuisCardosoOliveira:translation-re…

    …name-attr-warning, r=davidtwco
    
    translations: rename warn_ to warning
    
    ## Description
    
    This MR renames the the macro `warn_` to `warning`.
    
    To give a little bit of context, as [explained](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20diag.20translation/near/295074146) by `@davidtwco` in the Zulip channel, `warn_`  was named like that because the keyword `warn` is a built-in attribute and at the time this macro was created the word `warning` was also
    taken.
    
    However, it is no longer the case and we can rename `warn_` to `warning`.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    ac11fcb View commit details
    Browse the repository at this point in the history
  12. Rollup merge of rust-lang#101002 - estebank:hashmap-idx, r=davidtwco

    Provide structured suggestion for `hashmap[idx] = val`
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    f37d3ea View commit details
    Browse the repository at this point in the history
  13. Rollup merge of rust-lang#101055 - TaKO8Ki:use-smaller-span, r=compil…

    …er-errors
    
    Use smaller span for suggestions
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    df64d82 View commit details
    Browse the repository at this point in the history
  14. Rollup merge of rust-lang#101091 - TaKO8Ki:fix-101076, r=notriddle

    Extend attrs if local_def_id exists
    
    Fixes rust-lang#101076
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    0dc6ab6 View commit details
    Browse the repository at this point in the history
  15. Rollup merge of rust-lang#101098 - petrochenkov:noinvis, r=TaKO8Ki

    rustc_middle: Remove `Visibility::Invisible`
    
    It had a different meaning in the past, but now it's only used as an implementation detail of import resolution.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    58ed74c View commit details
    Browse the repository at this point in the history
  16. Rollup merge of rust-lang#101102 - est31:unstable_book_gen_write, r=M…

    …ark-Simulacrum
    
    unstable-book-gen: use std::fs::write
    
    I wrote this code in 2017 back when std::fs::write wasn't available.
    Also, use the t macro from tidy.
    matthiaskrgr committed Aug 28, 2022
    Configuration menu
    Copy the full SHA
    a5fd83a View commit details
    Browse the repository at this point in the history