Commit Graph

11288 Commits

Author SHA1 Message Date
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
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
bors
16d3e18281 Auto merge of #111447 - scottmcm:remove-more-assumes, r=thomcc
Remove useless `assume`s from `slice::iter(_mut)`

You were right in https://github.com/rust-lang/rust/pull/111395#discussion_r1190312704,
r? `@the8472`

LLVM already removes these assumes while optimizing, as can be seen in <https://rust.godbolt.org/z/KTfWKbdEM>.
2023-05-13 03:09:05 +00:00
Scott McMurray
c50a2e1d17 Remove useless assumes from slice::iter(_mut) 2023-05-12 17:34:55 -07:00
bors
9850584a4e Auto merge of #103413 - RalfJung:phantom-dropck, r=lcnr
PhantomData: fix documentation wrt interaction with dropck

As far as I could find out, the `PhantomData`-dropck interaction *only* affects code using `may_dangle`. The documentation in the standard library has not been updated for 8 years and thus stems from a time when Rust still used "parametric dropck", before [RFC 1238](https://rust-lang.github.io/rfcs/1238-nonparametric-dropck.html). Back then what the docs said was correct, but with `may_dangle` dropck it stopped being entirely accurate and these days, with NLL, it is actively misleading.

Fixes https://github.com/rust-lang/rust/issues/102810
Fixes https://github.com/rust-lang/rust/issues/70841
Cc `@nikomatsakis` I hope what I am saying here is right.^^
2023-05-13 00:23:51 +00:00
Ralf Jung
b93fd8355a hedge for future changes
Co-authored-by: lcnr <rust@lcnr.de>
2023-05-12 15:28:51 +02:00
bors
077fc26f0a Auto merge of #109732 - Urgau:uplift_drop_forget_ref_lints, r=davidtwco
Uplift `clippy::{drop,forget}_{ref,copy}` lints

This PR aims at uplifting the `clippy::drop_ref`, `clippy::drop_copy`, `clippy::forget_ref` and `clippy::forget_copy` lints.

Those lints are/were declared in the correctness category of clippy because they lint on useless and most probably is not what the developer wanted.

## `drop_ref` and `forget_ref`

The `drop_ref` and `forget_ref` lint checks for calls to `std::mem::drop` or `std::mem::forget` with a reference instead of an owned value.

### Example

```rust
let mut lock_guard = mutex.lock();
std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex
// still locked
operation_that_requires_mutex_to_be_unlocked();
```

### Explanation

Calling `drop` or `forget` on a reference will only drop the reference itself, which is a no-op. It will not call the `drop` or `forget` method on the underlying referenced value, which is likely what was intended.

## `drop_copy` and `forget_copy`

The `drop_copy` and `forget_copy` lint checks for calls to `std::mem::forget` or `std::mem::drop` with a value that derives the Copy trait.

### Example

```rust
let x: i32 = 42; // i32 implements Copy
std::mem::forget(x) // A copy of x is passed to the function, leaving the
                    // original unaffected
```

### Explanation

Calling `std::mem::forget` [does nothing for types that implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the value will be copied and moved into the function on invocation.

-----

Followed the instructions for uplift a clippy describe here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751

cc `@m-ou-se` (as T-libs-api leader because the uplifting was discussed in a recent meeting)
2023-05-12 12:04:32 +00:00
bors
26e0c57dde Auto merge of #111475 - workingjubilee:sync-simd-2023-may-10, r=workingjubilee
Sync portable-simd to 2023 May 10

Take 2.

r? `@ghost`
2023-05-12 02:05:05 +00:00
Jubilee Young
e4cecc1ab7 Correct swizzle_dyn cfg for armv7 neon 2023-05-11 17:22:00 -07:00
bors
5b24e12785 Auto merge of #111395 - scottmcm:slice-iter-zst-experiment, r=the8472
Simplify the implementation of iterators over slices of ZSTs

Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`.

That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like #42789, for example.

This PR instead changes it to just `end = ptr::invalid(len)` instead.

That's easier to think about (IMHO, at least) as well as easier to represent.

`next` is still to big to get inlined into the mir-opt/pre-codegen/ tests, but if I bump the inline threshold to force it to show the whole thing, this implementation is also less MIR:
```
> git diff --numstat
241     370     tests/mir-opt/pre-codegen/slice_iter.forward_loop.PreCodegen.after.mir
255     329     tests/mir-opt/pre-codegen/slice_iter.reverse_loop.PreCodegen.after.mir
184     216     tests/mir-opt/pre-codegen/slice_iter.slice_iter_mut_next_back.PreCodegen.after.mir
182     254     tests/mir-opt/pre-codegen/slice_iter.slice_iter_next.PreCodegen.after.mir
```
(That's ≈70 lines less for `Iter::next`, for example.)

r? `@ghost`

~~Built atop #111282, so draft until that lands.~~
2023-05-11 23:26:55 +00:00
Jubilee Young
b05d7e5bfa Sync portable-simd to 2023 May 10
Sync up to rust-lang/portable-simd@852762563a
2023-05-11 12:13:00 -07:00
Bryanskiy
670f5b134e Populate effective visibilities in rustc_privacy 2023-05-11 14:51:01 +03:00
Urgau
f5aede9c82 Improve code around SGX waitqueue
Followed up of d36e390d81
See https://github.com/rust-lang/rust/pull/109732#issuecomment-1543574908
for more details.

Co-authored-by: Jethro Beekman <jethro@fortanix.com>
2023-05-11 11:03:07 +02:00
Scott McMurray
15aa7fad7e Simplify the implementation of iterators over slices of ZSTs
Currently, slice iterators over ZSTs store `end = start.wrapping_byte_add(len)`.

That's slightly convenient for `is_empty`, but kinda annoying for pretty much everything else -- see bugs like 42789, for example.

This PR instead changes it to just `end = ptr::invalid(len)` instead.

That's easier to think about (IMHO, at least) as well as easier to represent.
2023-05-10 13:01:43 -07:00
Urgau
77773ad002 Allow the drop_copy lint in some library examples 2023-05-10 19:36:02 +02:00
Urgau
7dab6094bb Remove useless drop of copy type 2023-05-10 19:36:01 +02:00
Urgau
d36e390d81 Remove and fix useless drop of reference 2023-05-10 19:36:01 +02:00
bors
cba14074bb Auto merge of #111401 - ChrisDenton:no-windows-allowed, r=workingjubilee
Don't force include Windows goop when documenting

Why do we need to include all the windows bits on non-windows platforms? Let's try not doing that.

Possible alternative to #111394, if it works.
2023-05-10 10:28:38 +00:00
Matthias Krüger
f60a174c2d
Rollup merge of #111408 - TomMD:patch-1, r=workingjubilee
Fix incorrect implication of transmuting slices

transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-10 06:12:15 +02:00
Thomas M. DuBuisson
55d86b9da8
Fix incorrect implication of transmuting slices
transmute<&[u8]> would be useful and as a beginner it is confusing to see documents casually confuse the types of &[u8] and [u8; SZ]
2023-05-09 14:08:13 -07:00
Matthias Krüger
273fbf47ab
Rollup merge of #111282 - scottmcm:remove-unneeded-assumes, r=workingjubilee
Remove some `assume`s from slice iterators that don't do anything

Because the start pointer is iterators is already a `NonNull`, we emit the appropriate `!nonnull` metadata when loading the pointer to tell LLVM that it's non-null.

Probably the best way to see that it's the metadata that's important (and not the `assume`) is to observe that LLVM actually *removes* the `assume` from the optimized IR: <https://rust.godbolt.org/z/KhE6G963n>.

(I also checked that, yes, the if-not-ZST `assume` on `end` is still doing something: it's how there's a `!nonnull` metadata on its load, even though it's an ordinary raw pointer.  The codegen test added in this PR fails if the other `assume` is  removed.)
2023-05-09 20:49:33 +02:00
Matthias Krüger
e4c82501c2
Rollup merge of #110770 - m-ou-se:fmt-temp-lifetime, r=oli-obk
Limit lifetime of format_args!() with inlined args.

Fixes #110769
2023-05-09 20:49:31 +02:00
Matthias Krüger
88fbfafe9e
Rollup merge of #97320 - usbalbin:stabilize_const_ptr_read, r=m-ou-se
Stabilize const_ptr_read

Stabilizes const_ptr_read, with tracking issue #80377
2023-05-09 20:49:30 +02:00
Chris Denton
d076607983
Don't force include Windows goop when documenting 2023-05-09 19:34:01 +01:00
bors
3a37c2f052 Auto merge of #111371 - compiler-errors:revert-110907, r=petrochenkov
Revert "Populate effective visibilities in `rustc_privacy`"

This reverts commit cff85f22f5, cc #110907. It needs to be fixed, but there are too many issues being reported that I wanted to put up a revert until a proper fix can be committed.

Fixes a ton of issues where private but still reachable impls were missing during codegen:
Fixes #111320
Fixes #111321
Fixes #111334
Fixes #111357
Fixes #111368
Fixes #111373
Fixes #111377
Fixes #111386
Fixes #111387

`@bors` p=1

r? `@petrochenkov`
2023-05-09 15:16:17 +00:00
Mara Bos
d5843ddaf1 Limit lifetime of format_args!() with inlined args. 2023-05-09 16:08:40 +02:00
bors
f7b831ac8a Auto merge of #110285 - KisaragiEffective:sync-stdarch, r=Amanieu
stdarch: update submodule

We need [this commit](cf3deeae3a) introduced by [stdarch#1411](https://github.com/rust-lang/stdarch/pull/1411) in order to merge #110189.

Note to myself: `git pull && git submodule update --remote library/stdarch`
2023-05-09 12:28:34 +00:00
bors
ecd3dbab4e Auto merge of #111380 - Dylan-DPC:rollup-xiptbhn, r=Dylan-DPC
Rollup of 7 pull requests

Successful merges:

 - #110304 (Add GNU Property Note)
 - #110504 (Tweak borrow suggestion span)
 - #110583 (tweak "make mut" spans when assigning to locals)
 - #110694 (Implement builtin # syntax and use it for offset_of!(...))
 - #111120 (Suggest let for possible binding with ty)
 - #111252 (Min specialization improvements)
 - #111361 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2023-05-09 08:16:26 +00:00
Dylan DPC
dbd090c655
Rollup merge of #110694 - est31:builtin, r=petrochenkov
Implement builtin # syntax and use it for offset_of!(...)

Add `builtin #` syntax to the parser, as well as a generic infrastructure to support both item and expression position builtin syntaxes. The PR also uses this infrastructure for the implementation of the `offset_of!` macro, added by #106934.

cc `@petrochenkov` `@DrMeepster`

cc #110680 `builtin #` tracking issue
cc #106655 `offset_of!` tracking issue
2023-05-09 12:33:45 +05:30
bors
7e7483d26e Auto merge of #110152 - ChrisDenton:windows-sys, r=thomcc
Start using `windows sys` for Windows FFI bindings in std

Switch to using windows-sys for FFI. In order to avoid some currently contentious issues, this uses windows-bindgen to generate a smaller set of bindings instead of using the full crate.

Unlike the windows-sys crate, the generated bindings uses `*mut c_void` for handle types instead of `isize`. This to sidestep opsem concerns about mixing pointer types and integers between languages. Note that `SOCKET` remains defined as an integer but instead of being a usize, it's changed to fit the [standard library definition](a41fc00eaf/library/std/src/os/windows/raw.rs (L12-L16)):

```rust
#[cfg(target_pointer_width = "32")]
pub type SOCKET = u32;
#[cfg(target_pointer_width = "64")]
pub type SOCKET = u64;
```

The generated bindings also customizes the `#[link]` imports. I hope to switch to using raw-dylib but I don't want to tie that too closely with the switch to windows-sys.

---

Changes outside of the bindings are, for the most part, fairly minimal (e.g. some differences in `*mut` vs. `*const` or a few types differ). One issue is that our own bindings sometimes mix in higher level types, like `BorrowedHandle`. This is pretty adhoc though.
2023-05-09 05:20:41 +00:00
bors
33a01e2e93 Auto merge of #110027 - nbdd0121:dieting, r=m-ou-se
Add `#[inline]` to functions that are never called

This makes libcore binary size reduce by ~300 bytes. Not much, but these functions are never called so it doesn't make sense for them to get into the binary anyway.
2023-05-09 02:41:46 +00:00