Commit graph

8226 commits

Author SHA1 Message Date
bors
2b646bd533 Auto merge of #98224 - eddyb:proc-macro-spurious-repr, r=bjorn3
proc_macro/bridge: remove `#[repr(C)]` from non-ABI-relevant types.

Not sure how this happened, maybe some of these were passed through the bridge a long time ago?

r? `@bjorn3`
2022-06-19 17:32:12 +00:00
Dylan DPC
6a2a56da45
Rollup merge of #98233 - RalfJung:ref-alloc, r=thomcc
Remove accidental uses of `&A: Allocator`

Cc https://github.com/rust-lang/rust/issues/98232

Fixes https://github.com/rust-lang/rust/issues/98176 (for real this time)
2022-06-19 15:26:31 +02:00
bors
15fc228d0d Auto merge of #97791 - m-ou-se:const-locks, r=m-ou-se
Make {Mutex, Condvar, RwLock}::new() const.

This makes it possible to have `static M: Mutex<_> = Mutex::new(..);` 🎉

Our implementations [on Linux](https://github.com/rust-lang/rust/pull/95035), [on Windows](https://github.com/rust-lang/rust/pull/77380), and various BSDs and some tier 3 platforms have already been using a non-allocating const-constructible implementation. As of https://github.com/rust-lang/rust/pull/97647, the remaining platforms (most notably macOS) now have a const-constructible implementation as well. This means we can finally make these functions publicly const.

Tracking issue: https://github.com/rust-lang/rust/issues/93740
2022-06-19 08:20:36 +00:00
bors
5fb8a39266 Auto merge of #97367 - WaffleLapkin:stabilize_checked_slice_to_str_conv, r=dtolnay
Stabilize checked slice->str conversion functions

This PR stabilizes the following APIs as `const` functions in Rust 1.63:
```rust
// core::str

pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Note that the `from_utf8_mut` function is not stabilized as unique references (`&mut _`) are [unstable in const context].

FCP: https://github.com/rust-lang/rust/issues/91006#issuecomment-1134593095

[unstable in const context]: https://github.com/rust-lang/rust/issues/57349
2022-06-19 05:51:42 +00:00
Matthias Krüger
f351f347b8
Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se
once cell renamings

This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128

- Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`
- Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}`

(I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc)

```@rustbot``` label +T-libs-api -T-libs
2022-06-19 00:17:13 +02:00
bors
ec21d7ea3c Auto merge of #97924 - cuviper:unguarded-poison, r=Mark-Simulacrum
Avoid `thread::panicking()` in non-poisoning methods of `Mutex` and `RwLock`

`Mutex::lock()` and `RwLock::write()` are poison-guarded against panics,
in that they set the poison flag if a panic occurs while they're locked.
But if we're already in a panic (`thread::panicking()`), they leave the
poison flag alone.

That check is a bit of a waste for methods that never set the poison
flag though, namely `get_mut()`, `into_inner()`, and `RwLock::read()`.
These use-cases are now split to avoid that unnecessary call.
2022-06-18 15:18:50 +00:00
Ralf Jung
b05d71f880 make std not use &A: Allocator instance 2022-06-18 07:38:28 -07:00
Ralf Jung
7952205bc8 make btree not use &A: Allocator instance 2022-06-18 07:37:41 -07:00
bors
2cec6874c0 Auto merge of #98004 - paolobarbolini:vecdeque-extend-trustedlen, r=the8472
Add VecDeque::extend from TrustedLen specialization

Continuation of #95904

Inspired by how [`VecDeque::copy_slice` works](c08b235a5c/library/alloc/src/collections/vec_deque/mod.rs (L437-L454)).

## Benchmarks

Before

```
test vec_deque::bench_extend_chained_bytes      ... bench:       1,026 ns/iter (+/- 17)
test vec_deque::bench_extend_chained_trustedlen ... bench:       1,024 ns/iter (+/- 40)
test vec_deque::bench_extend_trustedlen         ... bench:         637 ns/iter (+/- 693)
```

After

```
test vec_deque::bench_extend_chained_bytes      ... bench:         828 ns/iter (+/- 24)
test vec_deque::bench_extend_chained_trustedlen ... bench:          25 ns/iter (+/- 1)
test vec_deque::bench_extend_trustedlen         ... bench:          21 ns/iter (+/- 0)
```

## Why do it this way

https://rust.godbolt.org/z/15qY1fMYh

The Compiler Explorer example shows how "just" removing the capacity check, like the [`Vec` `TrustedLen` specialization](c08b235a5c/library/alloc/src/vec/spec_extend.rs (L22-L58)) does, wouldn't have been enough for `VecDeque`. `wrap_add` would still have greatly limited what LLVM could do while optimizing.

---

r? `@the8472`
2022-06-18 12:54:01 +00:00
Eduard-Mihai Burtescu
83545d3216 proc_macro/bridge: remove #[repr(C)] from non-ABI-relevant types. 2022-06-18 09:14:25 +00:00
bors
0182fd99af Auto merge of #98186 - mystor:tokenstream_as_vec_tt, r=eddyb
Batch proc_macro RPC for TokenStream iteration and combination operations

This is the first part of #86822, split off as requested in https://github.com/rust-lang/rust/pull/86822#pullrequestreview-1008655452. It reduces the number of RPC calls required for common operations such as iterating over and concatenating TokenStreams.
2022-06-18 07:37:14 +00:00
bors
ff86b27e7b Auto merge of #98178 - RalfJung:btree-alloc, r=thomcc
btree: avoid forcing the allocator to be a reference

The previous code forces the actual allocator used to be some `&A`. This generalizes the code to allow any `A: Copy`. If people truly want to use a reference, they can use `&A` themselves.

Fixes https://github.com/rust-lang/rust/issues/98176
2022-06-18 05:12:40 +00:00
Nika Layzell
df925fda9c review fixups 2022-06-17 22:10:07 -04:00
Ralf Jung
3a1e114120 comments explaining why we have and don't have ManuallyDrop 2022-06-17 16:23:51 -07:00
Paolo Barbolini
ce3b6f505e Expose iter::ByRefSized as unstable feature and use it 2022-06-18 00:03:54 +02:00
Paolo Barbolini
bc3fae4dc1 Add VecDeque::extend from TrustedLen specialization 2022-06-18 00:03:54 +02:00
Paolo Barbolini
ac2c21a623 Add VecDeque::extend TrustedLen benchmark 2022-06-17 23:41:03 +02:00
Aria Beingessner
1502713f99 Impl Termination for Infallible and then make the Result impls of Termination into a blanket
This allows things like `Result<ExitCode, E>` to 'just work'
2022-06-17 13:54:17 -04:00
Nika Layzell
af51424008 Move empty final TokenStream handling to server side of bridge 2022-06-17 11:07:42 -04:00
Dylan DPC
7eabfb5fa7
Rollup merge of #97844 - ChrisDenton:dont-panic, r=JohnTitor
Windows: No panic if function not (yet) available

In some situations (e.g. #97814) it is possible for required functions to be called before they've had a chance to be loaded. Therefore, we make it possible to recover from this situation simply by looking at error codes.

`@rustbot` label +O-windows
2022-06-17 12:21:48 +02:00
Dylan DPC
b516806774
Rollup merge of #95392 - Xuanwo:stablize_try_reserve_2, r=dtolnay
std: Stabilize feature try_reserve_2

This PR intends to stabilize feature `try_reserve_2`, closes https://github.com/rust-lang/rust/issues/91789

This PR will also replace the previous PR: https://github.com/rust-lang/rust/pull/95139
2022-06-17 12:21:46 +02:00
Ralf Jung
901cd3a844 btree: avoid forcing the allocator to be a reference 2022-06-16 22:07:10 -07:00
Nika Layzell
4d45af9e73 Try to reduce codegen complexity of TokenStream's FromIterator and Extend impls
This is an experimental patch to try to reduce the codegen complexity of
TokenStream's FromIterator and Extend implementations for downstream
crates, by moving the core logic into a helper type. This might help
improve build performance of crates which depend on proc_macro as
iterators are used less, and the compiler may take less time to do
things like attempt specializations or other iterator optimizations.

The change intentionally sacrifices some optimization opportunities,
such as using the specializations for collecting iterators derived from
Vec::into_iter() into Vec.

This is one of the simpler potential approaches to reducing the amount
of code generated in crates depending on proc_macro, so it seems worth
trying before other more-involved changes.
2022-06-17 00:42:26 -04:00
Nika Layzell
0a049fd30d proc_macro: reduce the number of messages required to create, extend, and iterate TokenStreams
This significantly reduces the cost of common interactions with TokenStream
when running with the CrossThread execution strategy, by reducing the number of
RPC calls required.
2022-06-17 00:42:26 -04:00
Nika Layzell
2b17219468 proc_macro: use macros to simplify aggregate Mark/Unmark definitions 2022-06-16 23:16:30 -04:00
bors
3cf1275ecc Auto merge of #98143 - cuviper:futex-rwlock-inline, r=thomcc
Add `#[inline]` to small fns of futex `RwLock`

The important methods like `read` and `write` were already inlined,
which can propagate all the way to inlining in user code, but these
small state functions were left behind as normal calls. They should
almost always be inlined as well, as they're just a few instructions.
2022-06-17 02:32:14 +00:00
Yuki Okushi
6ac93185f4
Rollup merge of #98169 - pierwill:dyn-disp, r=JohnTitor
Keyword docs: Link to wikipedia article for dynamic dispatch
2022-06-17 07:16:58 +09:00
Yuki Okushi
1f3023ca8a
Rollup merge of #98118 - steffahn:scoped-threads-nll-test, r=m-ou-se
Test NLL fix of bad lifetime inference for reference captured in closure.

This came up as a use-case for `thread::scope` API that only compiles successfully since `feature(nll)` got stabilized recently.

Closes #93203 which had been re-opened for tracking this very test case to be added.
2022-06-17 07:16:56 +09:00
Yuki Okushi
cf68fd7e8d
Rollup merge of #97675 - nvzqz:unsized-needs-drop, r=dtolnay
Make `std::mem::needs_drop` accept `?Sized`

This change attempts to make `needs_drop` work with types like `[u8]` and `str`.

This enables code in types like `Arc<T>` that was not possible before, such as https://github.com/rust-lang/rust/pull/97676.
2022-06-17 07:16:55 +09:00
Maybe Waffle
c1a2db3372 Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
Maybe Waffle
7c360dc117 Move/rename lazy::{OnceCell, Lazy} to cell::{OnceCell, LazyCell} 2022-06-16 19:53:59 +04:00
pierwill
dd0f5d8be0 Keyword docs: Link to wikipedia article for dynamic dispatch 2022-06-16 09:58:57 -05:00
bors
6ec3993ef4 Auto merge of #97842 - notriddle:notriddle/tuple-docs, r=jsha,GuillaumeGomez
Improve the tuple and unit trait docs

* Reduce duplicate impls; show only the `(T,)` and include a sentence saying that there exists ones up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

Here's the new version:

* <https://notriddle.com/notriddle-rustdoc-test/std/primitive.tuple.html>
* <https://notriddle.com/notriddle-rustdoc-test/std/primitive.unit.html>
2022-06-16 11:13:30 +00:00
Matthias Krüger
f4297b06e8
Rollup merge of #98125 - KarlWithK:entry_add_modify_doc, r=Dylan-DPC
Entry and_modify doc

This PR modifies the documentation for [HashMap](https://doc.rust-lang.org/std/collections/struct.HashMap.html#) and [BTreeMap](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html#) by introducing examples for `and_modify`. `and_modify` is a function that tends to give more idiomatic rust code when dealing with these data structures -- yet it lacked examples and was hidden away. This PR adds that and addresses #98122.

I've made some choices which I tried to explain in my commits. This is my first time contributing to rust, so hopefully, I made the right choices.
2022-06-16 09:10:21 +02:00
bors
1b9daa6964 Auto merge of #98103 - exrook:btreemap-alloc, r=Amanieu
BTreeMap: Support custom allocators (v1.5)

Related:
https://github.com/rust-lang/wg-allocators/issues/7
https://github.com/TimDiekmann/alloc-wg

Blocked on:
~~#77187~~
~~#78459~~
~~#95036~~

previous: #77438
2022-06-16 02:15:55 +00:00
Xuanwo
324286f101
std: Stabilize feature try_reserve_2
Signed-off-by: Xuanwo <github@xuanwo.io>
2022-06-16 09:30:34 +08:00
bors
5bc82c0b94 Auto merge of #98152 - JohnTitor:rollup-osr17j6, r=JohnTitor
Rollup of 7 pull requests

Successful merges:

 - #97202 (os str capacity documentation)
 - #97964 (Fix suggestions for `&a: T` parameters)
 - #98053 (Fix generic impl rustdoc json output)
 - #98059 (Inline `const_eval_select`)
 - #98092 (Fix sidebar items expand collapse)
 - #98119 (Refactor path segment parameter error)
 - #98135 (Add regression test for #93775)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-15 23:49:06 +00:00
Yuki Okushi
b91c4d5b45
Rollup merge of #98059 - tmiasko:inline-const-eval-select, r=Amanieu
Inline `const_eval_select`

To avoid circular link time dependency between core and compiler
builtins when building with `-Zshare-generics`.

r? ```@Amanieu```
2022-06-16 07:24:41 +09:00
Yuki Okushi
b37e4e043e
Rollup merge of #97202 - joshtriplett:os-str-capacity-documentation, r=dtolnay
os str capacity documentation

This is based on https://github.com/rust-lang/rust/pull/95394 , with expansion and consolidation
to address comments from `@dtolnay` and other `@rust-lang/libs-api` team members.
2022-06-16 07:24:38 +09:00
bors
b31f9cc22b Auto merge of #97178 - sunfishcode:ownedfd-and-dup, r=joshtriplett
Add a `BorrowedFd::try_clone_to_owned` and accompanying documentation

Add a `BorrowedFd::try_clone_to_owned`, which returns a new `OwnedFd` sharing the underlying file description. And similar for `BorrowedHandle` and `BorrowedSocket` on WIndows.

This is similar to the existing `OwnedFd::try_clone`, but it's named differently to reflect that it doesn't return `Result<Self, ...>`. I'm open to suggestions for better names.

Also, extend the `unix::io` documentation to mention that `dup` is permitted on `BorrowedFd`.

This was originally requsted [here](https://github.com/rust-lang/rust/issues/88564#issuecomment-910786081). At the time I wasn't sure whether it was desirable, but it does have uses and it helps clarify the API. The documentation previously didn't rule out using `dup` on a `BorrowedFd`, but the API only offered convenient ways to do it from an `OwnedFd`. With this patch, the API allows one to do `try_clone` on any type where it's permitted.
2022-06-15 21:08:08 +00:00
Josh Stone
78577096f6 Add #[inline] to small fns of futex RwLock
The important methods like `read` and `write` were already inlined,
which can propagate all the way to inlining in user code, but these
small state functions were left behind as normal calls. They should
almost always be inlined as well, as they're just a few instructions.
2022-06-15 10:48:52 -07:00
Dan Gohman
ee49d65fc3 Add the new stability attributes, for Windows. 2022-06-15 09:46:56 -07:00
Dan Gohman
007cbfd1db Revise the documentation for try_clone.
On Unix, describe these in terms of the underlying "file description". On
Windows, describe them in terms of the underlying "object".
2022-06-15 08:55:11 -07:00
Dan Gohman
5d0eae81ae Add BorrowedFd::try_clone_to_owned.
And `BorrowedHandle::try_clone_to_owned` and
`BorrowedSocket::try_clone_to_owned` on Windows.
2022-06-15 08:54:06 -07:00
Dan Gohman
eb37bbcebc Document that BorrowedFd may be used to do a dup. 2022-06-15 08:52:42 -07:00
bors
c3605f8c80 Auto merge of #95897 - AzureMarker:feature/horizon-std, r=nagisa
STD support for the Nintendo 3DS

Rustc already supports compiling for the Nintendo 3DS using the `armv6k-nintendo-3ds` target (Tier 3). Until now though, only `core` and `alloc` were supported. This PR adds standard library support for the Nintendo 3DS. A notable exclusion is `std::thread` support, which will come in a follow-up PR as it requires more complicated changes.

This has been a joint effort by `@Meziu,` `@ian-h-chamberlain,` myself, and prior work by `@rust3ds` members.

### Background

The Nintendo 3DS (Horizon OS) is a mostly-UNIX looking system, with the caveat that it does not come with a full libc implementation out of the box. On the homebrew side (I'm not under NDA), the libc interface is partially implemented by the [devkitPro](https://devkitpro.org/wiki/devkitPro_pacman) toolchain and a user library like [`libctru`](https://github.com/devkitPro/libctru). This is important because there are [some possible legal barriers](https://github.com/rust-lang/rust/pull/88529#issuecomment-919938396) to linking directly to a library that uses the underlying platform APIs, since they might be considered a trade secret or under NDA.

To get around this, the standard library impl for the 3DS does not directly depend on any platform-level APIs. Instead, it expects standard libc functions to be linked in. The implementation of these libc functions is left to the user. Some functions are provided by the devkitPro toolchain, but in our testing, we used the following to fill in the other functions:
- [`libctru`] - provides more basic APIs, such as `nanosleep`. Linked in by way of [`ctru-sys`](https://github.com/Meziu/ctru-rs/tree/master/ctru-sys).
- [`pthread-3ds`](https://github.com/Meziu/pthread-3ds) - provides pthread APIs for `std::thread`. Implemented using [`libctru`].
- [`linker-fix-3ds`](https://github.com/Meziu/rust-linker-fix-3ds) - fulfills some other missing libc APIs. Implemented using [`libctru`].

For more details, see the `src/doc/rustc/src/platform-support/armv6k-nintendo-3ds.md` file added in this PR.

### Notes
We've already upstreamed changes to the [`libc`] crate to support this PR, as well as the upcoming threading PR. These changes have all been released as of 0.2.121, so we bump the crate version in this PR.
Edit: After some rebases, the version bump has already been merged so it doesn't appear in this PR.

A lot of the changes in this PR are straightforward, and follow in the footsteps of the ESP-IDF target: https://github.com/rust-lang/rust/pull/87666.

The 3DS does not support user space process spawning, so these APIs are unimplemented (similar to ESP-IDF).

[`libctru`]: https://github.com/devkitPro/libctru
[`libc`]: https://github.com/rust-lang/libc
2022-06-15 14:21:28 +00:00
Frank Steffahn
eb14dd863a Test NLL fix of bad lifetime inference for reference captured in closure. 2022-06-15 11:54:59 +02:00
KarlWithK
791923aacb
change "1" to "c" to pass test
Incorrectly wrote "1" twice when writing test.
2022-06-15 03:19:22 -05:00
KarlWithK
cec72acdca
Add examples using add_modify to btree
Updated the btree's documentation to include two references to
add_modify.

The first is when the `Entry` API is mentioned at the beginning. With
the same reasoning as HashMap's documentation, I thought it would best
to keep `attack`, but show the `mana` example.

The second is with the `entry` function that is used for the `Entry`
API. The code example was a perfect use for `add_modify`, which is why
it was changed to reflect that.
2022-06-15 02:04:18 -05:00
KarlWithK
d3d22e1e66
Add examples using add_modify to HashMap
Updated the HashMap's documentation to include two references to
add_modify.

The first is when the `Entry` API is mentioned at the beginning. I was
hesitant to change the "attack" example (although I believe that it is
perfect example of where `add_modify` should be used) because both uses
work equally, but one is more idiomatic (`add_modify`).

The second is with the `entry` function that is used for the `Entry`
API. The code example was a perfect use for `add_modify`, which is why
it was changed to reflect that.
2022-06-15 01:41:56 -05:00