Commit Graph

12798 Commits

Author SHA1 Message Date
bors
a19161043a Auto merge of #118321 - WaffleLapkin:unspace-fn-pointer-fake-variadic, r=notriddle
rustdoc: Remove space from fake-variadic fn ptr impls

before: `for fn (T₁, T₂, …, Tₙ) -> Ret`
after: `for fn(T₁, T₂, …, Tₙ) -> Ret`

I don't think we usually have spaces there, so it looks weird.

cc `@notriddle` since you added the space in https://github.com/rust-lang/rust/pull/98180 (or rather, added the feature with a space included).
2023-11-27 06:16:15 +00:00
bors
601a42713c Auto merge of #118313 - WaffleLapkin:fixup_comments_in_some_nonzero_ops, r=thomcc
Improve some comments for non-zero ops

This makes them a bit more explicit/correct.
2023-11-27 04:18:54 +00:00
bors
1bcbb7c93b Auto merge of #117697 - WaffleLapkin:non-null-convenience-ops, r=Amanieu
Non null convenience ops

Based on https://github.com/rust-lang/libs-team/issues/251.

I went through all of the methods on `*mut` and added every method, which does not require additional safety conditions, to `NonNull`. (exceptions: `guaranteed_eq`, `guaranteed_ne`, `with_metadata_of`, it's unclear if they are useful here...)

I'm also not sure what types should the "second pointer parameter" be. `*mut`/`*const` might be more permissible, but given that `NonNull` doesn't coerce to them, it might also be annoying. For now I chose the "use `NonNull` everywhere" path, but I'm not sure it's the correct one...

<sub>I'm eepy, so I probably messed up somewhere while copying...</sub>

cc `@scottmcm`
r? libs-api
2023-11-26 18:41:55 +00:00
Maybe Waffle
e1b4e8a257 Add is_aligned{,_to} convenience methods to NonNull 2023-11-26 16:01:31 +00:00
Maybe Waffle
2bcaa9760e Add align_offset convenience method to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
4cc46df98c Add replace and swap convenience methods to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
4bcdd3bd92 Add offset_from-ish convenience methods to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
ebdc79497f Add offset-ish convenience methods to NonNull 2023-11-26 16:01:30 +00:00
Maybe Waffle
36a587fb62 Add read/write/copy convenience methods to NonNull 2023-11-26 15:57:01 +00:00
Maybe Waffle
1a3c5c40ca rustdoc: Remove space from fake-variadic fn ptr impls
before: `for fn (T₁, T₂, …, Tₙ) -> Ret`
after: `for fn(T₁, T₂, …, Tₙ) -> Ret`
2023-11-26 15:01:42 +00:00
Guillaume Gomez
c67613bef9
Rollup merge of #118302 - mu001999:dead_code/clean, r=cjgillot
Clean dead codes

Clean dead codes detected by #118257
2023-11-26 15:44:54 +01:00
Maybe Waffle
c860ba1994 Improve some comments for non-zero ops 2023-11-26 11:47:08 +00:00
bors
9529a5d265 Auto merge of #110303 - nbdd0121:master, r=Mark-Simulacrum
Add `debug_assert_nounwind` and convert `assert_unsafe_precondition`

`assert_unsafe_precondition` checks non-CTFE-evaluable conditions in runtime and performs no-op in compile time, while many of its current usage can be checked during const eval.
2023-11-26 06:44:03 +00:00
r0cky
91aee2de15 Clean dead codes 2023-11-26 09:25:07 +08:00
Gary Guo
81cd49ddde Address review feedback 2023-11-25 23:58:51 +00:00
Gary Guo
97c1502066 Convert many assert_unsafe_precondition to debug_assert_nounwind 2023-11-25 23:58:51 +00:00
Gary Guo
4ccec4558f Add debug_assert_nounwind 2023-11-25 23:58:51 +00:00
Michael Goulet
fcb9fcc28c
Rollup merge of #117968 - Urgau:stabilize-ptr-addr-eq, r=dtolnay
Stabilize `ptr::addr_eq`

This PR stabilize the `ptr_addr_eq` library feature, representing:

```rust
// core::ptr

pub fn addr_eq<T: ?Sized, U: ?Sized>(p: *const T, q: *const U) -> bool;
```

FCP has already started [on the tracking issue](https://github.com/rust-lang/rust/issues/116324#issuecomment-1813008697) and is waiting on the final period comment.

Note: stabilizing this feature is somewhat of requirement for a new T-lang lint, cf. https://github.com/rust-lang/rust/pull/117758#issuecomment-1813183686.
2023-11-25 17:23:33 -05:00
bors
37b2813a7b Auto merge of #118138 - Nilstrieb:one-previous-error, r=WaffleLapkin
Fixes error count display is different when there's only one error left

Supersedes #114759

### What did I do?

I did the small change in `rustc_errors` by hand. Then I did the other changes in `/compiler` by hand, those were just find replace on `*.rs` in the workspace. The changes in run-make are find replace for `run-make` in the workspace.

All other changes are blessed using `x test TEST --bless`. I blessed the tests that were blessed in #114759.

### how to review this nightmare

ping bors with an `r+`. You should check that my logic is sound and maybe quickly scroll through the diff, but fully verifying it seems fairly hard to impossible. I did my best to do this correctly.

Thank you `@adrianEffe` for bringing this up and your initial implementation.

cc `@flip1995,` you said you want to do a subtree sync asap
cc `@RalfJung` maybe you want to do a quick subtree sync afterwards as well for Miri

r? `@WaffleLapkin`
2023-11-24 21:40:54 +00:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Michael Goulet
9c1b029559
Rollup merge of #118238 - RalfJung:memcpy, r=Mark-Simulacrum
memcpy assumptions: update GCC link

GCC now has this documented on an official website, not just in the bugtracker.
2023-11-24 07:29:12 -08:00
bors
b06258cde4 Auto merge of #118228 - Mark-Simulacrum:alloc-opt, r=scottmcm
Indicate that multiplication in Layout::array cannot overflow

Since https://github.com/rust-lang/rust/pull/113113, we have added a check that skips calling into the allocator at all if `capacity == 0`. The global, default allocator will not actually try to allocate though; it returns a dangling pointer explicitly. However, these two checks are not merged/deduplicated by LLVM and so we're comparing to zero twice whenever vectors are allocated/grown. Probably cheap, but also potentially expensive in code size and seems like an unfortunate miss.

This removes that extra check by telling LLVM that the multiplication as part of Layout::array can't overflow, turning the original non-zero value into a zero value afterwards. In my checks locally this successfully drops the duplicate comparisons.

See https://rust.godbolt.org/z/b6nPP9dcK for a code example.

```rust
pub fn foo(elements: usize) -> Vec<u32> {
    Vec::with_capacity(elements)
}
```

r? `@scottmcm` since you touched this in a32305a80f - curious if you have thoughts on doing this / can confirm my model of this being correct.
2023-11-24 11:19:34 +00:00
Ralf Jung
a5dff378f5 memcpy assumptions: update GCC link 2023-11-24 11:15:53 +01:00
bors
f74f700952 Auto merge of #118232 - matthiaskrgr:rollup-x8crvm0, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #116807 (Improve rewind documentation)
 - #117656 (Update windows-bindgen and define `INVALID_HANDLE_VALUE` ourselves)
 - #117940 (chore: remove unnecessary drop)
 - #118028 (Document behavior of `<dyn Any as Any>::type_id()`)
 - #118060 (Use an absolute path to the NUL device)
 - #118224 (Sort unstable items last in rustdoc, instead of first)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-11-24 09:21:23 +00:00
Matthias Krüger
b2d6480f53
Rollup merge of #118060 - ChrisDenton:abs-device-path, r=thomcc
Use an absolute path to the NUL device

While a bare "NUL" *should* be redirected to the NUL device, especially in this simple case, let's be explicit that we aren't opening a file called "NUL" and instead open it directly.

This will also set a good example for people copying std code.

r? libs
2023-11-24 08:23:53 +01:00
Matthias Krüger
c3216e2a3a
Rollup merge of #118028 - Jules-Bertholet:dyn-any-doc, r=thomcc
Document behavior of `<dyn Any as Any>::type_id()`

See also #57893

`@rustbot` label A-docs T-libs
2023-11-24 08:23:53 +01:00
Matthias Krüger
f38de06ce6
Rollup merge of #117940 - zhiqiangxu:remove_redundant_drop, r=thomcc
chore: remove unnecessary drop

 No need to manually drop since it's implicit.
2023-11-24 08:23:52 +01:00
Matthias Krüger
7e3ec1b0e2
Rollup merge of #117656 - ChrisDenton:invalid, r=thomcc
Update windows-bindgen and define `INVALID_HANDLE_VALUE` ourselves

We generate bindings to the Windows API via the `windows-bindgen` crate, which is ultimately what's also used to generate the `windows-sys` and `windows` crates. However, there currently is some custom sauce just for std which makes it a bit different from the vanilla bindings. I would love for us to reduce and eventually remove the differences entirely so that std is using the exact same bindings as everyone else. Maybe in the future we can even just have a normal dependency on `windows-sys`.

This PR removes one of those special things. Our definition of `INVALID_HANDLE_VALUE` relies on an experimental nightly feature for strict provenance, so lets bring that back in house. It also excludes it from the codegen step though that isn't strictly necessary as we override it in any case.

This PR also updates windows-bingen to 0.52.0.
2023-11-24 08:23:52 +01:00
Matthias Krüger
b8657093d6
Rollup merge of #116807 - seanlinsley:patch-2, r=thomcc
Improve rewind documentation

The persistent use of an internal cursor for readers is expected for buffer data types that aren't read all at once, but for files it leads to the confusing situation where calling `read_to_end` on the same file handle multiple times only returns the contents of the file for the first call. This PR adds a note to the documentation clarifying that in that case, `rewind()` must first be called.

I'm unsure if this is the right location for the docs update. Maybe it should also be duplicated on `File`?
2023-11-24 08:23:51 +01:00
bors
8abf920985 Auto merge of #117722 - okaneco:binarysearch, r=thomcc
Refactor `binary_search_by` to use conditional moves

Refactor the if/else checking on `cmp::Ordering` variants to a "branchless" reassignment of left and right.

This change results in fewer branches and instructions.
https://rust.godbolt.org/z/698eYffTx

---

I saw consistent benchmark improvements locally. Performance of worst case seems about the same, maybe slightly faster for the L3 test.

Current
```
slice::binary_search_l1             43.00ns/iter +/- 3.00ns
slice::binary_search_l1_with_dups   25.00ns/iter +/- 0.00ns
slice::binary_search_l1_worst_case  10.00ns/iter +/- 0.00ns
slice::binary_search_l2             64.00ns/iter +/- 1.00ns
slice::binary_search_l2_with_dups   42.00ns/iter +/- 0.00ns
slice::binary_search_l2_worst_case  16.00ns/iter +/- 0.00ns
slice::binary_search_l3            132.00ns/iter +/- 2.00ns
slice::binary_search_l3_with_dups  108.00ns/iter +/- 2.00ns
slice::binary_search_l3_worst_case  33.00ns/iter +/- 3.00ns
```
This PR
```
slice::binary_search_l1            21.00ns/iter +/- 0.00ns
slice::binary_search_l1_with_dups  14.00ns/iter +/- 0.00ns
slice::binary_search_l1_worst_case  9.00ns/iter +/- 0.00ns
slice::binary_search_l2            34.00ns/iter +/- 0.00ns
slice::binary_search_l2_with_dups  23.00ns/iter +/- 0.00ns
slice::binary_search_l2_worst_case 16.00ns/iter +/- 0.00ns
slice::binary_search_l3            92.00ns/iter +/- 3.00ns
slice::binary_search_l3_with_dups  63.00ns/iter +/- 1.00ns
slice::binary_search_l3_worst_case 29.00ns/iter +/- 0.00ns
```
2023-11-24 07:23:04 +00:00
Mark Rousskov
b81e788d16 Indicate that multiplication in Layout::array cannot overflow
This allows LLVM to optimize comparisons to zero before & after the
multiplication into one, saving on code size and eliminating an (always
true) branch from most Vec allocations.
2023-11-23 22:05:45 -05:00
bors
e68f935117 Auto merge of #98943 - WilliamVenner:feat/bufread_skip_until, r=dtolnay
Add `BufRead::skip_until`

Alternative version of `BufRead::read_until` that simply discards data, rather than copying it into a buffer.

Useful for situations like skipping irrelevant data in a binary file format that is NUL-terminated.

<details>
<summary>Benchmark</summary>

```
running 2 tests
test bench_read_until ... bench:         123 ns/iter (+/- 6)
test bench_skip_until ... bench:          66 ns/iter (+/- 3)
```

```rs
#![feature(test)]
extern crate test;
use test::Bencher;

use std::io::{ErrorKind, BufRead};

fn skip_until<R: BufRead + ?Sized>(r: &mut R, delim: u8) -> Result<usize, std::io::Error> {
    let mut read = 0;
    loop {
        let (done, used) = {
            let available = match r.fill_buf() {
                Ok(n) => n,
                Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                Err(e) => return Err(e),
            };
            match memchr::memchr(delim, available) {
                Some(i) => (true, i + 1),
                None => (false, available.len()),
            }
        };
        r.consume(used);
        read += used;
        if done || used == 0 {
            return Ok(read);
        }
    }
}

const STR: &[u8] = b"Ferris\0Hello, world!\0";

#[bench]
fn bench_skip_until(b: &mut Bencher) {
    b.iter(|| {
        let mut io = std::io::Cursor::new(test::black_box(STR));
        skip_until(&mut io, b'\0').unwrap();
        let mut hello = Vec::with_capacity(b"Hello, world!\0".len());
        let num_bytes = io.read_until(b'\0', &mut hello).unwrap();
        assert_eq!(num_bytes, b"Hello, world!\0".len());
        assert_eq!(hello, b"Hello, world!\0");
    });
}

#[bench]
fn bench_read_until(b: &mut Bencher) {
    b.iter(|| {
        let mut io = std::io::Cursor::new(test::black_box(STR));
        io.read_until(b'\0', &mut Vec::new()).unwrap();
        let mut hello = Vec::with_capacity(b"Hello, world!\0".len());
        let num_bytes = io.read_until(b'\0', &mut hello).unwrap();
        assert_eq!(num_bytes, b"Hello, world!\0".len());
        assert_eq!(hello, b"Hello, world!\0");
    });
}
```
</details>
2023-11-23 22:28:14 +00:00
David Tolnay
52c07b9564
Fix tracking issue of Windows ExitCodeExt 2023-11-23 11:16:10 -08:00
bors
193466525d Auto merge of #115159 - solid-rs:patch/kmc-solid/io-safety, r=workingjubilee
kmc-solid: I/O safety

Adds the I/O safety API (#87329) for socket file descriptors in [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. All new public items are gated by the `solid_ext` library feature.

This PR adds the following public types and traits:

    std::os::solid::io::AsFd
    std::os::solid::io::BorrowedFd
    std::os::solid::io::OwnedFd

    std::os::solid::prelude::AsFd (re-export)
    std::os::solid::prelude::BorrowedFd (re-export)
    std::os::solid::prelude::OwnedFd (re-export)

And trait implementations:

    From<std::net::TcpListener> for std::os::solid::io::OwnedFd
    From<std::net::TcpStream> for std::os::solid::io::OwnedFd
    From<std::net::UdpSocket> for std::os::solid::io::OwnedFd
    From<std::os::solid::io::OwnedFd> for std::net::TcpListener
    From<std::os::solid::io::OwnedFd> for std::net::TcpStream
    From<std::os::solid::io::OwnedFd> for std::net::UdpSocket
    std::fmt::Debug for std::os::solid::io::BorrowedFd<'_>
    std::fmt::Debug for std::os::solid::io::OwnedFd
    std::io::IsTerminal for std::os::solid::io::BorrowedFd<'_>
    std::io::IsTerminal for std::os::solid::io::OwnedFd
    std::os::fd::AsRawFd for std::os::solid::io::BorrowedFd<'_>
    std::os::fd::AsRawFd for std::os::solid::io::OwnedFd
    std::os::fd::FromRawFd for std::os::solid::io::OwnedFd
    std::os::fd::IntoRawFd for std::os::solid::io::OwnedFd
    std::os::solid::io::AsFd for &impl std::os::solid::io::AsFd
    std::os::solid::io::AsFd for &mut impl std::os::solid::io::AsFd
    std::os::solid::io::AsFd for Arc<impl std::os::solid::io::AsFd>
    std::os::solid::io::AsFd for Box<impl std::os::solid::io::AsFd>
    std::os::solid::io::AsFd for Rc<impl std::os::solid::io::AsFd>
    std::os::solid::io::AsFd for std::net::TcpListener
    std::os::solid::io::AsFd for std::net::TcpStream
    std::os::solid::io::AsFd for std::net::UdpSocket
    std::os::solid::io::AsFd for std::os::solid::io::BorrowedFd<'_>
    std::os::solid::io::AsFd for std::os::solid::io::OwnedFd

Taking advantage of the above change, this PR also refactors the internal details of `std::sys::solid::net` to match the design of other targets, e.g., by redefining `Socket` as a newtype of `OwnedFd`.
2023-11-23 04:24:09 +00:00
bors
c387f012b1 Auto merge of #118154 - ChrisDenton:win-clippy, r=scottmcm
Fix some clippy lints for library/std/src/sys/windows

These issues were shown by running `x clippy` on `library/std` and filtering for `windows/` paths. I think running clippy on the full std would be great but I wanted to start smaller and with something that's hopefully easier to review. It'd be good to eventually run clippy in CI but that's a bigger conversation.

I've created separate commits for each clippy lint fixed (with the commit title set to the lint name) and reviewed the changes myself. Most of the fixes here are trivial.

r? libs
2023-11-23 00:30:15 +00:00
Chris Denton
b9fe367b99
x fmt library/std 2023-11-22 13:17:02 +00:00
Chris Denton
6c8ebf174c
redundant_slicing 2023-11-22 13:17:02 +00:00
Chris Denton
852c038393
cmp_null
comparing with null is better expressed by the `.is_null()` method
2023-11-22 13:17:02 +00:00
Chris Denton
c15adf6557
manual_range_contains 2023-11-22 13:17:01 +00:00
Chris Denton
d7e1f1cc08
op_ref
taken reference of right operand
2023-11-22 13:00:30 +00:00
Chris Denton
4c084c576a
manual_map
manual implementation of `Option::map`
2023-11-22 13:00:30 +00:00
Chris Denton
8c85c5b7f4
unnecessary_lazy_evaluations
unnecessary closure used with `bool::then`
2023-11-22 13:00:29 +00:00
Chris Denton
220217af13
redundant_closure 2023-11-22 13:00:29 +00:00
Chris Denton
b962ae1324
duration_subsec
calling `subsec_micros()` is more concise than this calculation
2023-11-22 13:00:29 +00:00
Chris Denton
9e42456a0d
unnecessary_cast
casting to the same type is unnecessary
2023-11-22 13:00:29 +00:00
Chris Denton
24542639aa
needless_borrow
this expression creates a reference which is immediately dereferenced by the compiler
2023-11-22 13:00:29 +00:00
Chris Denton
42734599bd
needless_borrows_for_generic_args
the borrowed expression implements the required traits
2023-11-22 13:00:28 +00:00
Chris Denton
fe255695f9
manual_slice_size_calculation 2023-11-22 13:00:28 +00:00
Chris Denton
bfbeb3ebd9
unnecessary_mut_passed
This is where our Windows API bindings previously (and incorrectly) used `*mut` instead of `*const` pointers. Now that the bindings have been corrected, the mutable references (which auto-convert to `*mut`) are unnecessary and we can use shared references.
2023-11-22 13:00:28 +00:00
Chris Denton
6c22e57c39
useless_conversion 2023-11-22 13:00:28 +00:00