Commit graph

11321 commits

Author SHA1 Message Date
bors fe76e14955 Auto merge of #111646 - Voultapher:restore-branchless-code-gen-for-merge, r=cuviper
Use code with reliable branchless code-gen for slice::sort merge

The recent LLVM 16 update changes code-gen to be not branchless anymore, in the slice::sort implementation merge function. This improves performance by 30% for random patterns, restoring the performance to the state with LLVM 15.

Fixes #111559
2023-05-20 21:52:10 +00:00
bors 6d1bf733d6 Auto merge of #111778 - Dylan-DPC:rollup-107ig9h, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #111491 (Dont check `must_use` on nested `impl Future` from fn)
 - #111606 (very minor cleanups)
 - #111619 (Add timings for MIR passes to profiling report)
 - #111652 (Better diagnostic for `use Self::..`)
 - #111665 (Add more tests for the offset_of macro)
 - #111708 (Give a more useful location for where a span_bug was delayed)
 - #111715 (Fix doc comment for `ConstParamTy` derive)
 - #111723 (style: do not overwrite obligations)
 - #111743 (Improve cgu merging debug output)
 - #111762 (fix: emit error when fragment is `MethodReceiverExpr` and items is empty)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-20 10:30:30 +00:00
Dylan DPC 93c031f6e6
Rollup merge of #111715 - juntyr:const-param-ty-derive-fix, r=Nilstrieb
Fix doc comment for `ConstParamTy` derive

See https://github.com/rust-lang/rust/pull/111670#discussion_r1196453888

Thanks ````@Nilstrieb```` for the pointer :)
2023-05-20 12:21:01 +05:30
Dylan DPC e892e32df4
Rollup merge of #111665 - est31:offset_of_tests, r=WaffleLapkin
Add more tests for the offset_of macro

Implements what I [suggested in the tracking issue](https://github.com/rust-lang/rust/issues/106655#issuecomment-1535007205), plus some further improvements:

* ensuring that offset_of!(Self, ...) works iff inside an impl block
* ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision
* improving the privacy checking test
* ensuring that generics don't let you escape the unsized check

r? `````@WaffleLapkin`````
2023-05-20 12:21:00 +05:30
bors e86fd62b6b Auto merge of #111524 - scottmcm:escape-using-ascii, r=cuviper
`ascii::Char`-ify the escaping code in `core`

This means that `EscapeIterInner::as_str` no longer needs unsafe code, because the type system ensures the internal buffer is only ASCII, and thus valid UTF-8.

Come to think of it, this also gives it a (non-guaranteed) niche.

cc `@BurntSushi` as potentially interested
`ascii::Char` tracking issue: #110998
2023-05-20 04:43:17 +00:00
bors 7047d97e01 Auto merge of #111453 - scottmcm:constify-as-slice, r=Mark-Simulacrum
constify `slice_as_chunks` (unstable)

Tracking issue: #74985

Nothing complicated required; just adding `const` to the declarations.
2023-05-19 23:12:36 +00:00
bors 521f4dae1b Auto merge of #109773 - beetrees:set-file-time-improvements, r=Amanieu
Add creation time support to `FileTimes` on apple and windows

Adds support for setting file creation times on platforms which support changing it directly (currently only Apple and Windows). Based on top of #110093 (which was split from this PR).

ACP: rust-lang/libs-team#199 (currently still in progress)

Tracking issue: #98245

`@rustbot` label +T-libs-api -T-libs
2023-05-19 19:53:14 +00:00
Ibraheem Ahmed 4fbca2e1d5 tidy 2023-05-19 12:45:41 +02:00
Ibraheem Ahmed b997f3ca13 remove unstable Poll::ready 2023-05-19 12:42:58 +02:00
Scott McMurray 62fcebdf7a constify slice_as_chunks (unstable)
Tracking issue: 74985

Nothing complicated required; just adding `const` to the declarations.
2023-05-19 02:32:10 -07:00
bors 2d17294d18 Auto merge of #111590 - dtolnay:panictemporaries, r=bjorn3
Shorten even more panic temporary lifetimes

Followup to #104134. As pointed out by `@bjorn3` in https://github.com/rust-lang/rust/pull/104134#pullrequestreview-1425585948, there are other cases in the panic macros which would also benefit from dropping their non-Send temporaries as soon as possible, avoiding pointlessly holding them across an await point.

For the tests added in this PR, here are the failures you get today on master without the macro changes in this PR:

<details>
<summary>tests/ui/macros/panic-temporaries-2018.rs</summary>

```console
error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries-2018.rs:52:18
   |
LL |     require_send(panic_display());
   |                  ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send`
   |
   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries-2018.rs:35:31
   |
LL |     f(panic!("{}", NOT_SEND)).await;
   |                    --------   ^^^^^- `NOT_SEND` is later dropped here
   |                    |          |
   |                    |          await occurs here, with `NOT_SEND` maybe used later
   |                    has type `NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries-2018.rs:48:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries-2018.rs:52:18
   |
LL |     require_send(panic_display());
   |                  ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send`
   |
   = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries-2018.rs:35:31
   |
LL |     f(panic!("{}", NOT_SEND)).await;
   |       ----------------------  ^^^^^- the value is later dropped here
   |       |                       |
   |       |                       await occurs here, with the value maybe used later
   |       has type `&NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries-2018.rs:48:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries-2018.rs:53:18
   |
LL |     require_send(panic_str());
   |                  ^^^^^^^^^^^ future returned by `panic_str` is not `Send`
   |
   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries-2018.rs:40:36
   |
LL |     f(panic!((NOT_SEND, "...").1)).await;
   |               --------             ^^^^^- `NOT_SEND` is later dropped here
   |               |                    |
   |               |                    await occurs here, with `NOT_SEND` maybe used later
   |               has type `NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries-2018.rs:48:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries-2018.rs:54:18
   |
LL |     require_send(unreachable_display());
   |                  ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send`
   |
   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries-2018.rs:45:31
   |
LL |     f(unreachable!(NOT_SEND)).await;
   |                    --------   ^^^^^- `NOT_SEND` is later dropped here
   |                    |          |
   |                    |          await occurs here, with `NOT_SEND` maybe used later
   |                    has type `NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries-2018.rs:48:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries-2018.rs:54:18
   |
LL |     require_send(unreachable_display());
   |                  ^^^^^^^^^^^^^^^^^^^^^ future returned by `unreachable_display` is not `Send`
   |
   = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries-2018.rs:45:31
   |
LL |     f(unreachable!(NOT_SEND)).await;
   |       ----------------------  ^^^^^- the value is later dropped here
   |       |                       |
   |       |                       await occurs here, with the value maybe used later
   |       has type `&NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries-2018.rs:48:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: aborting due to 5 previous errors
```
</details>

<details>
<summary>tests/ui/macros/panic-temporaries.rs</summary>

```console
error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries.rs:42:18
   |
LL |     require_send(panic_display());
   |                  ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send`
   |
   = help: within `impl Future<Output = ()>`, the trait `Send` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries.rs:35:31
   |
LL |     f(panic!("{}", NOT_SEND)).await;
   |                    --------   ^^^^^- `NOT_SEND` is later dropped here
   |                    |          |
   |                    |          await occurs here, with `NOT_SEND` maybe used later
   |                    has type `NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries.rs:38:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: future cannot be sent between threads safely
  --> tests/ui/macros/panic-temporaries.rs:42:18
   |
LL |     require_send(panic_display());
   |                  ^^^^^^^^^^^^^^^ future returned by `panic_display` is not `Send`
   |
   = help: within `NotSend`, the trait `Sync` is not implemented for `*const u8`
note: future is not `Send` as this value is used across an await
  --> tests/ui/macros/panic-temporaries.rs:35:31
   |
LL |     f(panic!("{}", NOT_SEND)).await;
   |       ----------------------  ^^^^^- the value is later dropped here
   |       |                       |
   |       |                       await occurs here, with the value maybe used later
   |       has type `&NotSend` which is not `Send`
note: required by a bound in `require_send`
  --> tests/ui/macros/panic-temporaries.rs:38:25
   |
LL | fn require_send(_: impl Send) {}
   |                         ^^^^ required by this bound in `require_send`

error: aborting due to 2 previous errors
```
</details>

r? bjorn3
2023-05-19 07:15:38 +00:00
est31 30c0e4e72b Add more tests for the offset_of!() macro
* ensuring that offset_of!(Self, ...) works iff inside an impl block
* ensuring that the output type is usize and doesn't coerce. this can be
  changed in the future, but if it is done, it should be a conscious descision
* improving the privacy checking test
* ensuring that generics don't let you escape the unsized check
2023-05-18 13:16:17 +02:00
Juniper Tyree f577cc4dea
Fix doc comment for ConstParamTy derive
See https://github.com/rust-lang/rust/pull/111670#discussion_r1196453888

Thanks @Nilstrieb for the pointer :)
2023-05-18 11:54:51 +03:00
bors 9052ca9393 Auto merge of #111710 - Dylan-DPC:rollup-eutrx54, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #110884 (Support RISC-V unaligned-scalar-mem target feature)
 - #111160 (Update serde in workspace and non-synced dependencies)
 - #111168 (Specialize ToString implementation for fmt::Arguments)
 - #111527 (add examples of port 0 binding behavior)
 - #111561 (Include better context for "already exists" error in compiletest)
 - #111633 (Avoid `&format("...")` calls in error message code.)
 - #111679 (Remove libs message about ACPs from triagebot)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-18 07:14:23 +00:00
Dylan DPC f9bbd23adf
Rollup merge of #111527 - knickish:bind_port_0_documentation, r=Mark-Simulacrum
add examples of port 0 binding behavior

Was trying to find the method to specify the IP address but not the port, and there wasn't information easily accessible about it in the `TcpListener` or `SocketAddr`. Adding examples to `TcpListener` and `UdpSocket` for clarity.
2023-05-18 10:52:34 +05:30
Dylan DPC e0991b7bcd
Rollup merge of #111168 - DaniPopes:arguments-to-string, r=Mark-Simulacrum
Specialize ToString implementation for fmt::Arguments

Generates far fewer instructions by formatting into a String with `fmt::format` directly instead of going through the `fmt::Display` impl. This change is insta-stable.
2023-05-18 10:52:34 +05:30
yukang c3394b3eaa Fix #107910, Shorten backtraces in ICEs 2023-05-17 17:56:26 +08:00
Dylan DPC 71fdb95272
Rollup merge of #111654 - JoJoJet:unsafe-cell-from-mut-lib, r=joshtriplett
Add a conversion from `&mut T` to `&mut UnsafeCell<T>`

Provides a safe way of downgrading an exclusive reference into an alias-able `&UnsafeCell<T>` reference.

ACP: https://github.com/rust-lang/libs-team/issues/198.
2023-05-17 11:13:57 +05:30
Dylan DPC bc3b94a486
Rollup merge of #111649 - Nilstrieb:derive-const-param-ty, r=BoxyUwU
Add derive for `core::marker::ConstParamTy`

This makes it easier to implement it for a type, just like `Copy`.

`@BoxyUwU` half asked me to add it
2023-05-17 11:13:57 +05:30
Dylan DPC 5b58471c4c
Rollup merge of #111043 - jmillikin:cstr-is-empty, r=dtolnay
Stabilize feature `cstr_is_empty`

Fixes #102444

ACP: https://github.com/rust-lang/libs-team/issues/106
2023-05-17 11:13:56 +05:30
JoJoJet ffacb8861a add UnsafeCell::from_mut 2023-05-16 15:36:05 -04:00
Matthias Krüger 20f6aa1365
Rollup merge of #111592 - Nemo157:fix-vec-capacity-examples, r=joshtriplett
Change Vec examples to not assert exact capacity except where it is guaranteed

It was [brought up on discord](https://discord.com/channels/273534239310479360/818964227783262209/1107633959329878077) that the `Vec::into_boxed_slice` example contradicted the `Vec::with_capacity` docs in that the returned `Vec` might have _more_ capacity than requested.

So, to reduce confusion change all the `assert_eq!(vec.capacity(), _)` to `assert!(vec.capacity() >= _)`, except in 4 examples that have guaranteed capacities: `Vec::from_raw_parts`, `Vec::from_raw_parts_in`, `Vec::<()>::with_capacity`,`Vec::<(), _>::with_capacity_in`.
2023-05-16 20:12:17 +02:00
Nilstrieb 0336dd132b Add derive for core::marker::ConstParamTy
This makes it easier to implement it for a type, just like `Copy`.
2023-05-16 20:09:25 +02:00
David Tolnay e7963a65ed
Hide repr attribute from doc of types without guaranteed repr 2023-05-16 10:00:52 -07:00
Lukas Bergdoll 42655ff03b Use code with reliable branchless code-gen for slice::sort merge
The recent LLVM 16 update changes code-gen to be not branchless anymore, in the
slice::sort implementation merge function. This improves performance by 30% for
random patterns, restoring the performance to the state with LLVM 15.
2023-05-16 18:38:32 +02:00
Nilstrieb 0db9de843d
Rollup merge of #111617 - kesleta:master, r=Dylan-DPC
Fixed typo

Fixed typo in BTree Curser.
2023-05-16 11:39:41 +02:00
bors 3ea9ad5324 Auto merge of #111134 - GilShoshan94:remove-send-bound-on-error, r=dtolnay
Remove unnecessary Send bound

Hi,

While working on a [PR on Tokio](https://github.com/tokio-rs/tokio/pull/5666), I took inspiration from the std channel mpsc and stumbled on a `Send` bound for a `Error` impl.

Tokio's maintainer `@Darksonn` pointed out to me that `Error` used to required the `Send` bound long time ago (here https://github.com/rust-lang/rust/pull/23541).

In the meantime, the `Send` bound `Error` got removed (see https://github.com/rust-lang/rust/pull/21312 and https://github.com/rust-lang/rust/pull/23799).

So here a PR to removed this bound for `SendError<T>`, `TrySendError<T>` and `SendTimeoutError<T>`.
2023-05-16 04:03:26 +00:00
bors 76e79ca026 Auto merge of #111044 - jmillikin:nonzero-negation, r=dtolnay
Stabilize feature `nonzero_negation_ops`

Fixes #102443

ACP: https://github.com/rust-lang/libs-team/issues/105
2023-05-16 01:07:42 +00:00
Benjamin Atelsek 9688a6cebb Fixed typo 2023-05-15 15:13:21 -04:00
Matthias Krüger eeebb6590a
Rollup merge of #111587 - cbeuw:copy-for-deref, r=oli-obk
Custom MIR: Support `Rvalue::CopyForDeref`

r? `@oli-obk` or `@tmiasko` or `@JakobDegen`
2023-05-15 17:12:47 +02:00
Matthias Krüger c93c2985d8
Rollup merge of #110049 - SkiFire13:localkey-with-docs-fix, r=workingjubilee
Don't claim `LocalKey::with` prevents a reference to be sent across threads

The documentation for `LocalKey` claims that `with` yields a reference that cannot be sent across threads, but this is false since you can easily do that with scoped threads. What it actually prevents is the reference from outliving the current thread.
2023-05-15 17:12:44 +02:00
Matthias Krüger 1063548a1a
Rollup merge of #108356 - gftea:master, r=workingjubilee
improve doc test for UnsafeCell::raw_get

improve docs of public API `UnsafeCell::raw_get`
2023-05-15 17:12:44 +02:00
Matthias Krüger fc30207b16
Rollup merge of #108291 - chenyukang:yukang/fix-benchmarks, r=workingjubilee
Fix more benchmark test with black_box

Follow up fix for https://github.com/rust-lang/rust/issues/107590
2023-05-15 17:12:43 +02:00
beetrees 246dcbcbcd
Add test for FileTimes 2023-05-15 15:04:45 +01:00
beetrees db90a0b78d
Add creation time support to FileTimes on apple and windows 2023-05-15 15:04:39 +01:00
Wim Looman a9cb4822be
Change Vec examples to not assert exact capacity except where it is guaranteed 2023-05-15 14:25:05 +02:00
David Tolnay 2f5d993945
Shorten lifetime of even more panic temporaries 2023-05-15 03:47:37 -07:00
Andy Wang 3d938ddb39
Documentation 2023-05-15 12:08:16 +02:00
Andy Wang c3ab4f28d3
Add CopyForDeref to custom MIR 2023-05-15 12:05:10 +02:00
Matthias Krüger 75186c0f7d
Rollup merge of #111582 - Vagelis-Prokopiou:fix/wanting, r=workingjubilee
(docs) Change "wanting" to "want"

Changing " If you’re wanting" to "If you want".

Wanting is not wrong, of course, but I think that "If you want" feels more natural to most readers.
2023-05-15 10:58:42 +02:00
Matthias Krüger 9d8c11ba75
Rollup merge of #111581 - scottmcm:fix-pattern-comment, r=workingjubilee
Fix some misleading and copy-pasted `Pattern` examples

These examples were listed twice and also were confusable with doing a substring match instead of a any-of-set match.
2023-05-15 10:58:42 +02:00
Matthias Krüger 28bc8745ad
Rollup merge of #102673 - lukas-code:infered-lifetimes, r=ehuss
Update doc for `PhantomData` to match code example

After https://github.com/rust-lang/rust/pull/106621, there is no longer a `T: 'a` annotation in the doc example, so update the text to match the code.
2023-05-15 10:58:39 +02:00
Vagelis Prokopiou 5fa8c4aced wanting => want 2023-05-15 10:13:08 +03:00
Scott McMurray 47232ade61 Fix some misleading and copy-pasted Pattern examples
These examples were listed twice and also were confusable with doing a substring match instead of a any-of-set match.
2023-05-14 23:03:50 -07:00
bors 0bcfd2d96e Auto merge of #108273 - tspiteri:const_slice_split_at_not_mut, r=dtolnay
Stabilize const slice::split_at

This stabilizes the use of the following method in const context:

```rust
impl<T> [T] {
    pub const fn split_at(&self, mid: usize) -> (&[T], &[T]);
}
```

cc tracking issue #101158
2023-05-15 03:54:33 +00:00
bors a14d6961f9 Auto merge of #108196 - sunfishcode:sunfishcode/windows-as-socket-impls, r=dtolnay
Implement `AsHandle`/`AsSocket` for `Arc`/`Rc`/`Box` on Windows

Implement the Windows counterpart to #97437 and #107317: Implement `AsHandle` and `AsSocket` for `Arc<T>`, `Rc<T>`, and `Box<T>`.
2023-05-14 22:10:09 +00:00
bors 18bfe5d8a9 Auto merge of #92048 - Urgau:num-midpoint, r=scottmcm
Add midpoint function for all integers and floating numbers

This pull-request adds the `midpoint` function to `{u,i}{8,16,32,64,128,size}`, `NonZeroU{8,16,32,64,size}` and `f{32,64}`.

This new function is analog to the [C++ midpoint](https://en.cppreference.com/w/cpp/numeric/midpoint) function, and basically compute `(a + b) / 2` with a rounding towards ~~`a`~~ negative infinity in the case of integers. Or simply said: `midpoint(a, b)` is `(a + b) >> 1` as if it were performed in a sufficiently-large signed integral type.

Note that unlike the C++ function this pull-request does not implement this function on pointers (`*const T` or `*mut T`). This could be implemented in a future pull-request if desire.

### Implementation

For `f32` and `f64` the implementation in based on the `libcxx` [one](18ab892ff7/libcxx/include/__numeric/midpoint.h (L65-L77)). I originally tried many different approach but all of them failed or lead me with a poor version of the `libcxx`. Note that `libstdc++` has a very similar one; Microsoft STL implementation is also basically the same as `libcxx`. It unfortunately doesn't seems like a better way exist.

For unsigned integers I created the macro `midpoint_impl!`, this macro has two branches:
 - The first one take `$SelfT` and is used when there is no unsigned integer with at least the double of bits. The code simply use this formula `a + (b - a) / 2` with the arguments in the correct order and signs to have the good rounding.
 - The second branch is used when a `$WideT` (at least double of bits as `$SelfT`) is provided, using a wider number means that no overflow can occur, this greatly improve the codegen (no branch and less instructions).

For signed integers the code basically forwards the signed numbers to the unsigned version of midpoint by mapping the signed numbers to their unsigned numbers (`ex: i8 [-128; 127] to [0; 255]`) and vice versa.
I originally created a version that worked directly on the signed numbers but the code was "ugly" and not understandable. Despite this mapping "overhead" the codegen is better than my most optimized version on signed integers.

~~Note that in the case of unsigned numbers I tried to be smart and used `#[cfg(target_pointer_width = "64")]` to determine if using the wide version was better or not by looking at the assembly on godbolt. This was applied to `u32`, `u64` and `usize` and doesn't change the behavior only the assembly code generated.~~
2023-05-14 19:33:02 +00:00
Lukas Markeffsky 3d02aa850b explain that PhantomData<&'a T> infers T: 'a 2023-05-14 16:52:08 +02:00
David Tolnay cb109a672d
Shorten lifetime of panic temporaries in panic_fmt case 2023-05-14 07:27:20 -07:00
bors ad6ab11234 Auto merge of #111425 - Bryanskiy:privacy_ef, r=petrochenkov
Populate effective visibilities in `rustc_privacy` (take 2)

Same as https://github.com/rust-lang/rust/pull/110907 + regressions fixes.
Fixes https://github.com/rust-lang/rust/issues/111359.

r? `@petrochenkov`
2023-05-14 02:53:52 +00:00