Commit graph

8288 commits

Author SHA1 Message Date
leocth
9c5ae20c59 forgot about the feature flag in the doctest 2022-06-26 10:49:05 +08:00
leocth
0df7364cdf temporarily remove tests because I'm not sure if we need them 2022-06-26 00:06:50 +08:00
leocth
7d5f236c3d Add feature gate #![atomic_bool_fetch_not] 2022-06-25 18:31:01 +08:00
leocth
dcfe92e193 add fetch_not method on AtomicBool 2022-06-25 11:19:08 +08:00
Michael Goulet
e749ba2061
Rollup merge of #98364 - RalfJung:arc-clone, r=Mark-Simulacrum
clarify Arc::clone overflow check comment

I had to read this twice to realize that this is explaining that the code is technically unsound, so move that into a dedicated paragraph and make the wording a bit more explicit.
2022-06-23 14:39:13 -07:00
Michael Goulet
262382ff37
Rollup merge of #96173 - jmaargh:jmaargh/with-capacity-doc-fix, r=Dylan-DPC
Fix documentation for  `with_capacity` and `reserve` families of methods

Fixes #95614

Documentation for the following methods
 - `with_capacity`
 - `with_capacity_in`
 - `with_capacity_and_hasher`
 - `reserve`
 - `reserve_exact`
 - `try_reserve`
 - `try_reserve_exact`

was inconsistent and often not entirely correct where they existed on the following types
- `Vec`
- `VecDeque`
- `String`
- `OsString`
- `PathBuf`
- `BinaryHeap`
- `HashSet`
- `HashMap`
- `BufWriter`
- `LineWriter`

since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked `BufReader`, but there the docs appear to be accurate as it appears to actually allocate the exact capacity).

Some effort was made to make the documentation more consistent between types as well.
2022-06-23 14:39:05 -07:00
Yuki Okushi
db64923b80
Rollup merge of #98363 - RalfJung:btree-test-ref-alloc, r=thomcc
remove use of &Alloc in btree tests

I missed these in https://github.com/rust-lang/rust/pull/98233.

r? ``@thomcc``
2022-06-22 15:16:17 +09:00
Yuki Okushi
25b84491f7
Rollup merge of #97516 - RalfJung:atomics, r=joshtriplett
clarify how Rust atomics correspond to C++ atomics

``@cbeuw`` noted in https://github.com/rust-lang/miri/pull/1963 that the correspondence between C++ atomics and Rust atomics is not quite as obvious as one might think, since in Rust I can use `get_mut` to treat previously non-atomic data as atomic. However, I think using C++20 `atomic_ref`, we can establish a suitable relation between the two -- or do you see problems with that ``@cbeuw?`` (I recall you said there was some issue, but it was deep inside that PR and Github makes it impossible to find...)

Cc ``@thomcc;`` not sure whom else to ping for atomic memory model things.
2022-06-22 15:16:11 +09:00
Yuki Okushi
897745bf67
Rollup merge of #96768 - m-ou-se:futex-fuchsia, r=tmandry
Use futex based thread parker on Fuchsia.
2022-06-22 15:16:09 +09:00
Ralf Jung
46b2454bad clarify Arc::clone overflow check comment 2022-06-21 21:14:03 -07:00
Ralf Jung
4768bfc6ef
hedge our bets
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-06-21 16:54:54 -07:00
Ralf Jung
1ca8b69e1c remove use of &Alloc in btree tests 2022-06-21 16:38:12 -07:00
Yuki Okushi
e5092425eb
Rollup merge of #98330 - conradludgate:io-slice-mut-docs, r=Dylan-DPC
update ioslice docs to use shared slices

I noticed that IoSlice docs were taking unnecessary mut slices, when they only accept shared slices
2022-06-21 20:08:17 +09:00
Yuki Okushi
18b01d5ea0
Rollup merge of #98313 - m-ou-se:fix-comments, r=joshtriplett
Remove lies in comments.

> does not have a const constructor

> pub const fn new() -> Self

🤔
2022-06-21 20:08:14 +09:00
Yuki Okushi
b20aff2b33
Rollup merge of #97269 - RalfJung:transmute, r=m-ou-se
adjust transmute const stabilization version

With 1.46, this became callable only in `const`/`static` items.

Only since 1.56 is this callable in `const fn`: [changelog](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1560-2021-10-21)

Also see [Zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/transmute.20const.20fn.20stabilization).
2022-06-21 20:08:08 +09:00
Yuki Okushi
84c17c200a
Rollup merge of #94033 - joshtriplett:documentation-is-running-better-go-catch-it, r=m-ou-se
Improve docs for `is_running` to explain use case
2022-06-21 20:08:07 +09:00
Mara Bos
ac38258dcc Use futex based thread parker on Fuchsia. 2022-06-21 11:49:59 +02:00
Conrad Ludgate
44dbd9808e update ioslice docs to use shared slices 2022-06-21 11:45:17 +02:00
bors
0887113991 Auto merge of #98307 - matthiaskrgr:rollup-rb3huha, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #98235 (Drop magic value 3 from code)
 - #98267 (Don't omit comma when suggesting wildcard arm after macro expr)
 - #98276 (Mention formatting macros when encountering `ArgumentV1` method in const)
 - #98296 (Add a link to the unstable book page on Generator doc comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-06-20 22:34:50 +00:00
Mara Bos
a171a6b7ec Remove lies in comments. 2022-06-20 23:02:21 +02:00
Josh Triplett
7098a714e8 Improve docs for is_running to explain use case 2022-06-20 13:42:49 -07:00
Matthias Krüger
dfa933d420
Rollup merge of #98296 - JohnTitor:generator-unstable-book-link, r=Dylan-DPC
Add a link to the unstable book page on Generator doc comment

This makes it easier to jump into the Generator section on the unstable book.

Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-06-20 20:13:12 +02:00
Matthias Krüger
5eb7238928
Rollup merge of #98276 - compiler-errors:const-format-macro, r=oli-obk
Mention formatting macros when encountering `ArgumentV1` method in const

Also open to just closing this if it's overkill. There are a lot of other distracting error messages around, so maybe it's not worth fixing just this one.

Fixes #93665
2022-06-20 20:13:11 +02:00
bors
5750a6aa27 Auto merge of #93765 - zhangyunhao116:heapsort, r=m-ou-se
Optimize heapsort

The new implementation is about 10% faster than the previous one(sorting random 1000 items).
2022-06-20 18:09:30 +00:00
Yuki Okushi
51cc665b33
Add a link to the unstable book page on Generator doc comment
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
2022-06-20 23:19:50 +09:00
Dylan DPC
ce1151c04c
Rollup merge of #97837 - sunfishcode:sunfishcode/proc-self-mem, r=m-ou-se
Document Rust's stance on `/proc/self/mem`

Add documentation to `std::os::unix::io` describing Rust's stance on
`/proc/self/mem`, treating it as an external entity which is outside
the scope of Rust's safety guarantees.
2022-06-20 14:56:40 +02:00
Dylan DPC
2807f28de5
Rollup merge of #97150 - ChrisDenton:stdio-create_pipe, r=m-ou-se
`Stdio::makes_pipe`

Wrappers around `std::process::Command` may want to be able to override pipe creation. However, [`std::process::Stdio`](https://doc.rust-lang.org/std/process/struct.Stdio.html) is opaque so there's no way to tell if `Command` was told to create new pipes or not.

This is in some ways a more generic (and cross-platform) alternative to #97149. However, unlike that feature, this comes with the price of the user needing to actually create their own pipes rather than reusing the std one. So I think it stands (or not) on its own.

# Example

```rust
#![feature(stdio_makes_pipe)]
use std::process::Stdio;

let io = Stdio::piped();
assert_eq!(io.makes_pipe(), true);
```
2022-06-20 14:56:39 +02:00
Dylan DPC
85f1de20e7
Rollup merge of #97149 - ChrisDenton:win_async_pipes, r=m-ou-se
Windows: `CommandExt::async_pipes`

Discussed in https://github.com/tokio-rs/tokio/issues/4670 was the need for third party crates to be able to force `process::Command::spawn` to create pipes as async.

This implements the suggestion for a `async_pipes` method that gives third party crates that option.

# Example:

```rust
use std::process::{Command, Stdio};

Command::new("cmd")
    .async_pipes(true)
    .stdin(Stdio::piped())
    .stdout(Stdio::piped())
    .stderr(Stdio::piped())
    .spawn()
    .unwrap();
```
2022-06-20 14:56:38 +02:00
Dylan DPC
625c929a9f
Rollup merge of #96719 - mbartlett21:patch-4, r=Dylan-DPC
Fix the generator example for `pin!()`

The previous generator example is not actually self-referential, since the reference is created after the yield.

CC #93178 (tracking issue)
2022-06-20 14:56:36 +02:00
Dylan DPC
7372bf88ee
Rollup merge of #96609 - ibraheemdev:arc-downcast-unchecked, r=m-ou-se
Add `{Arc, Rc}::downcast_unchecked`

Part of #90850.
2022-06-20 14:56:35 +02:00
Dylan DPC
99620ad721
Rollup merge of #94855 - m-ou-se:advance-slice-panic-docs, r=kennytm
Panic when advance_slices()'ing too far and update docs.

This updates advance_slices() to panic when advancing too far, like advance() already does. And updates the docs to say so.

See https://github.com/rust-lang/rust/issues/62726#issuecomment-1065253213
2022-06-20 14:56:34 +02:00
Dylan DPC
fd9ca0c25e
Rollup merge of #93080 - SkiFire13:itermut-as_mut_slice, r=m-ou-se
Implement `core::slice::IterMut::as_mut_slice` and `impl<T> AsMut<[T]> for IterMut<'_, T>`

As per [the zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/.60std.3A.3Aslice.3A.3AIterMut.3A.3Aas_mut_slice.60), the `AsMut` impl has been commented out, with a comment near the `#[unstable(...)]` to uncomment it when `as_mut_slice` gets stabilized.
2022-06-20 14:56:33 +02:00
Chris Denton
740a54c69b
Windows: CommandExt::async_pipes 2022-06-20 12:21:39 +01:00
Chris Denton
8b93147f7e
Stdio::make_pipe 2022-06-20 11:58:38 +01:00
zhangyunhao
98507f202d Optimize heapsort 2022-06-20 08:30:27 +00:00
Mara Bos
c867529461
Show #![feature] in example. 2022-06-20 10:00:55 +02:00
nils
2ead0d7457 Fix typo in HashMap::drain docs
It's a map, not a vector.
2022-06-20 09:17:08 +02:00
Michael Goulet
5373d738e8 Mention formatting macros when encountering ArgumentV1::new in const 2022-06-19 20:18:08 -07:00
Yuki Okushi
761f83f683
Rollup merge of #98257 - kadiwa4:into_future_doc_typos, r=Dylan-DPC
Fix typos in `IntoFuture` docs
2022-06-20 07:37:43 +09:00
Yuki Okushi
77316a4aaa
Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnay
Stabilize `Path::try_exists()` and improve doc

This stabilizes the `Path::try_exists()` method which returns
`Result<bool, io::Error>` instead of `bool` allowing handling of errors
unrelated to the file not existing. (e.g permission errors)

Along with the stabilization it also:

* Warns that the `exists()` method is error-prone and suggests to use
  the newly stabilized one.
* Suggests it instead of `metadata()` to handle errors.
* Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is
  completely safe fixed version of `exists()`.
* Renames the feature of still-unstable `std::fs::try_exists()` to
  `fs_try_exists` to avoid name conflict.

The tracking issue #83186 remains open to track `fs_try_exists`.
2022-06-20 07:37:41 +09:00
Yuki Okushi
9d4e08e725
Rollup merge of #95534 - jyn514:std-mem-copy, r=joshtriplett
Add `core::mem::copy` to complement `core::mem::drop`.

This is useful for combinators. I didn't add `clone` since you can already
use `Clone::clone` in its place; copy has no such corresponding function.
2022-06-20 07:37:40 +09:00
Joshua Nelson
9ac6277bad Add core::mem::copy to complement core::mem::drop.
This is useful for combinators. I didn't add `clone` since you can already
use `Clone::clone` in its place; copy has no such corresponding function.
2022-06-19 16:43:19 -05:00
jmaargh
95dc353006 Fix documentation for with_capacity and reserve families of methods
Documentation for the following methods

    with_capacity
    with_capacity_in
    with_capacity_and_hasher
    reserve
    reserve_exact
    try_reserve
    try_reserve_exact

was inconsistent and often not entirely correct where they existed on the following types

    Vec
    VecDeque
    String
    OsString
    PathBuf
    BinaryHeap
    HashSet
    HashMap
    BufWriter
    LineWriter

since the allocator is allowed to allocate more than the requested capacity in all such cases, and will frequently "allocate" much more in the case of zero-sized types (I also checked BufReader, but there the docs appear to be accurate as it appears to actually allocate the exact capacity).

Some effort was made to make the documentation more consistent between types as well.

Fix with_capacity* methods for Vec

Fix *reserve*  methods for Vec

Fix docs for *reserve* methods of VecDeque

Fix docs for String::with_capacity

Fix docs for *reserve* methods of String

Fix docs for OsString::with_capacity

Fix docs for *reserve* methods on OsString

Fix docs for with_capacity* methods on HashSet

Fix docs for *reserve methods of HashSet

Fix docs for with_capacity* methods of HashMap

Fix docs for *reserve methods on HashMap

Fix expect messages about OOM in doctests

Fix docs for BinaryHeap::with_capacity

Fix docs for *reserve* methods of BinaryHeap

Fix typos

Fix docs for with_capacity on BufWriter and LineWriter

Fix consistent use of `hasher` between `HashMap` and `HashSet`

Fix warning in doc test

Add test for capacity of vec with ZST

Fix doc test error
2022-06-19 20:46:49 +01:00
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
KaDiWa4
f0144aea74
typos in IntoFuture docs 2022-06-19 17:13:48 +02: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