Commit Graph

421 Commits

Author SHA1 Message Date
Sidney Cammeresi 04874be3a2 Adjust diagnostic items for mpmc/mpsc Receiver and Sender
`MpscReceiver` aligns with `MpscSender`.  The original name appears to
not actually have been in use, for better or worse.

Along the way, sprinkle the attribute onto `mpmc::Receiver` and
`mpmc::Sender` too.
2026-04-27 17:16:09 -07:00
Sidney Cammeresi 70fe8a6dc4 Add Sender diagnostic item for std::sync::mpsc::Sender
Similar to the existing `Receiver` item, it will be used in Clippy to
detect uses of `is_disconnected` that are racy.
2026-04-23 17:19:39 -07:00
Mark Rousskov f0827c67ca Apply replace-version-placeholder 2026-04-14 18:09:15 -04:00
Jonathan Brouwer 8d8dcf142a Rollup merge of #154929 - davidgauch:const-default-lazy, r=jhpratt
Add `const Default` impls for `LazyCell` and `LazyLock`

Follow up to these commits by @estebank https://github.com/rust-lang/rust/pull/134628 and https://github.com/rust-lang/rust/pull/151190.
Tracking issue https://github.com/rust-lang/rust/issues/143894.

cc @fmease @fee1-dead @oli-obk

This enables `static L: LazyLock<D> = Default::default()`  for any type `D: Default` which is safe as `D::default()` is only evaluated at runtime.
2026-04-13 20:20:02 +02:00
David Gauch c7c9117326 Add const Default impls for LazyCell and LazyLock 2026-04-06 23:53:29 -07:00
Laine Taffin Altman 5adc0312b8 core::sync: Rename Exclusive to SyncView 2026-04-06 18:00:21 -07:00
Jonathan Brouwer 08343b5707 Rollup merge of #153555 - asder8215:rwlock_docs, r=Mark-Simulacrum
Clarified docs in std::sync::RwLock + added test to ensure that max reader count is respected

This addresses the issue with the [`std::sync::RwLock` docs](https://doc.rust-lang.org/std/sync/struct.RwLock.html) in rust-lang/rust#115338. It centers around the following lines:

> An `RwLock` will allow any number of readers to acquire the lock as long as a writer is not holding the lock.

It's true that the `RwLock` in theory should allow any number of readers to acquire the lock when a writer is not holding it, but this may not be true in the implementation and could be os dependent. I decided to replace "any number of readers" to "multiple", so that it implies that more than 1 reader can acquire the lock, but you can't necessarily take away that this value is unbounded.

@rustbot label +A-docs
2026-04-04 17:19:09 +02:00
Mahdi Ali-Raihan 83a7a4ad74 Clarified docs in std::sync::RwLock and added a test that checks if we can reach max reader 2026-03-28 18:55:55 -04:00
Jonathan Brouwer 981f837e2d Rollup merge of #153170 - LevitatingBusinessMan:is_disconnected, r=Mark-Simulacrum
Add is_disconnected functions to mpsc and mpmc channels

Add `is_disconnected()` functions to the `Sender` and `Receiver` of both `mpmc` an `mpsc` channels.

```rust
std::sync::mpmc::Sender<T>::is_disconnected(&self) -> bool
std::sync::mpmc::Receiver<T>::is_disconnected(&self) -> bool

std::sync::mpsc::Sender<T>::is_disconnected(&self) -> bool
std::sync::mpsc::Receiver<T>::is_disconnected(&self) -> bool
```

The `mpsc` methods are locked behind the `mpsc_is_disconnected` feature gate, which has no tracking issue yet.

ACP: https://github.com/rust-lang/libs-team/issues/748
Tracking issue: https://github.com/rust-lang/rust/issues/153668
2026-03-19 13:42:33 +01:00
Jules Bertholet c5c1d94e6c Add From impls for wrapper types
- `From<T> for ThinBox<T>`
- `From<T> for UniqueRc<T>`
- `From<T> for UniqueArc<T>`
- `From<T: UnwindSafe> for AssertUnwindSafe<T>`
- `From<T> for LazyCell<T, F>`
- `From<T> for LazyLock<T, F>`
2026-03-14 22:09:35 -04:00
LevitatingBusinessMan (Rein Fernhout) ce2de643fc assign mpsc_is_disconnected issue 153668 2026-03-10 19:21:19 +01:00
LevitatingBusinessMan (Rein Fernhout) feef7b4eaf warn of possible race condition in channel is_disconnected doc 2026-02-28 19:52:50 +01:00
LevitatingBusinessMan (Rein Fernhout) 7adb9bac0c Add is_disconnected functions to mpsc and mpmc channels 2026-02-27 09:46:20 +01:00
Henner Zeller 27f97d7f71 RwLock: refine documentation to emphasize non-reentrancy guarantees
This addresses the need for clarification brought up in an issue.
Specifically, it notes that some implementations may choose to panic if
they detect deadlock situations during recursive locking attempts for
both `read()` and `write()` calls.

  * Provide an example highlighting that multiple read locks can be
    held across different threads simultaneously.
  * Remove the example that shows a situation that can potentially deadlock.
    (as demonstrated in the very same documentation a few paragraphs
    above)
  * Improve documentation regarding the possibility of panics during
    recursive read or write lock attempts.

Issues: Ambiguity in RwLock documentation about multiple read() calls...

Signed-off-by: Henner Zeller <h.zeller@acm.org>
2026-02-03 07:48:05 -08:00
Mark Rousskov bc611ce5f1 Replace version placeholders with 1.94 2026-01-20 21:17:10 -05:00
Connor Tsui 9ba5b5e7f7 add experimental oneshot channel
The `oneshot` channel is gated under the `oneshot_channel` feature.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2026-01-05 09:47:15 +11:00
Marijn Schouten b2e6e0374d mutex.rs: remove needless-maybe-unsized bounds 2026-01-03 11:17:29 +00:00
Jonathan Brouwer cc68f30960 Rollup merge of #149469 - tisonkun:mut-once, r=Mark-Simulacrum
Leverage &mut in OnceLock when possible

See comments inline.
2025-12-28 18:16:10 +01:00
Jacob Pratt 1c2dbcf33b Rollup merge of #150016 - usamoi:stabilize-lazy-get, r=jhpratt
stabilize `lazy_get`

closes https://github.com/rust-lang/rust/issues/129333
FCP is finished in https://github.com/rust-lang/rust/issues/129333#issuecomment-3477510482

```@rustbot``` modify labels: +T-libs-api
2025-12-24 02:52:58 -05:00
Matthias Krüger 7b92feb0df Rollup merge of #149812 - tisonkun:oncelock-const-default, r=Mark-Simulacrum
Add const default for OnceCell and OnceLock

cc rust-lang/rust#143894
2025-12-21 18:50:41 +01:00
David 7cf35566e3 document that mpmc channels deliver an item to (at most) one receiver 2025-12-15 14:09:13 +01:00
usamoi 141342c34f stabilize lazy_get 2025-12-15 18:57:33 +08:00
tison df38e1521d Add const default for OnceCell and OnceLock
Signed-off-by: tison <wander4096@gmail.com>
2025-12-09 20:38:47 +08:00
tison 5d8f2b8ebe Clarify edge cases for Barrier::new 2025-11-30 17:14:46 +08:00
tison 0e336684fd Leverage &mut in OnceLock when possible
Signed-off-by: tison <wander4096@gmail.com>
2025-11-30 10:42:42 +08:00
Urgau 0e8d1e1f8e Add #[rustc_should_not_be_called_on_const_items] to std methods 2025-11-22 14:48:35 +01:00
Connor Tsui 3d5a40809c update nonpoison::Condvar to take guards by reference
Since non-poisoning `Condvar` take non-poisoing `Mutex`es when
`wait`ing, we do not need to take by ownership since a poison error
cannot occur while we wait.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-31 15:53:33 -04:00
Josh Stone f25ca45fd1 Update CURRENT_RUSTC_VERSION post-bump
(cherry picked from commit 813072186c)
2025-10-28 13:22:00 -07:00
Connor Tsui 3a9c521285 move once module out of poison
Since `Once` will not have a non-poisoning variant, we remove it from
the `poison` module.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 11:43:39 -04:00
Connor Tsui 7b61403c50 reorganize library/std/src/sync/mod.rs file
Moves things around to make a bit more sense (plus prepare moving `once`
out of `poison`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 11:43:38 -04:00
Connor Tsui 0758e191d5 clean up some documentation
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 11:43:15 -04:00
Connor Tsui a61c8be269 rename once::ExclusiveState to OnceExclusiveState
It is a bit confusing when reading code that uses this type since it is
not immediately obvious that it is specific to `Once`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-10-17 10:57:39 -04:00
Matthias Krüger 8d6356b8d8 Rollup merge of #143191 - connortsui20:stabilize-rwlock-downgrade, r=tgross35
Stabilize `rwlock_downgrade` library feature

Tracking Issue: https://github.com/rust-lang/rust/issues/128203

Method to be stabilized:

```rust
impl<'a, T: ?Sized> RwLockWriteGuard<'a, T> {
    pub fn downgrade(s: Self) -> RwLockReadGuard<'a, T> {}
}
```

~~I would like to point out that my documentation comment is longer than ideal, but at the same time I don't really know how else to show why `downgrade` is actually necessary (instead of just unlocking and relocking). If anyone has ideas for making this more concise that would be great!~~ I have made the documentation a bit more clear.

Stabilization report: https://github.com/rust-lang/rust/issues/128203#issuecomment-3016682463
2025-10-15 23:41:00 +02:00
Camille Gillot 49922d5b96 Remove unreachable expression warning from std. 2025-10-11 20:50:21 +00:00
EFanZh ba42380142 Implement non-poisoning Mutex::with_mut, RwLock::with and RwLock::with_mut
ACP: https://github.com/rust-lang/libs-team/issues/497.
2025-10-04 17:16:00 +08:00
Peter Lyons Kehl 819f8b05b9 Mutex/RwLock/ReentrantLock::data_ptr to be const fn 2025-09-22 12:51:50 -07:00
Ralf Jung f21d3fbce9 fix Condvar::wait_timeout docs 2025-09-13 20:13:37 +02:00
Georg Semmler ef7b036458 Add suggestions 2025-09-10 07:55:03 +02:00
Georg Semmler 20d02258fc Make Barrier RefUnwindSafe again
This commit manually implements `RefUnwindSafe` for
`std::sync::Barrier` to fix 146087. This is a fix for a regression
indroduced by https://github.com/rust-lang/rust/commit/e95db591a4550e28ad92660b753ad85b89271882
2025-09-09 17:13:38 +02:00
Stuart Cook eda6dc9283 Rollup merge of #144651 - connortsui20:nonpoison_condvar, r=joboet
Implementation: `#[feature(nonpoison_condvar)]`

Tracking Issue: https://github.com/rust-lang/rust/issues/134645

This PR continues the effort made in https://github.com/rust-lang/rust/pull/144022 by adding the implementation of `nonpoison::condvar`.

Many of the changes here are similar to the changes made to implement `nonpoison::mutex`.

There are two other changes here. The first is that the `Barrier` implementation is migrated to use the `nonpoison::Condvar` instead of the `poison` variant. The second (which might be subject to some discussion) is that `WaitTimeoutResult` is moved up to `mod.rs`, as both `condvar` variants need that type (and I do not know if there is a better place to put it now).

### Related PRs

- `nonpoison_rwlock` implementation: https://github.com/rust-lang/rust/pull/144648
- `nonpoison_once` implementation: https://github.com/rust-lang/rust/pull/144653
2025-08-30 20:29:06 +10:00
Matthias Krüger 7879cbbbff Rollup merge of #145078 - minxuanz:riscv-cacheline, r=samueltardieu
Fix wrong cache line size of riscv64

see https://go-review.googlesource.com/c/go/+/526659,  All of riscv CPU using 64B for cache-line size.
2025-08-27 07:45:55 +02:00
Guillaume Gomez 9bb7d17d9a Rollup merge of #144373 - hkBst:remove-deprecated-1, r=jhpratt
remove deprecated Error::description in impls

[libs-api permission](https://github.com/rust-lang/libs-team/issues/615#issuecomment-3074045829)

r? `@cuviper`
or `@jhpratt`
2025-08-26 16:34:09 +02:00
Marijn Schouten 845311a065 remove deprecated Error::description in impls 2025-08-26 06:36:53 +00:00
Jacob Pratt d5340c26fa Rollup merge of #145307 - connortsui20:lazylock-poison-msg, r=Amanieu
Fix `LazyLock` poison panic message

Fixes the issue raised in https://github.com/rust-lang/rust/pull/144872#issuecomment-3151100248

r? ```@Amanieu```
2025-08-23 23:58:35 -04:00
Connor Tsui d210ce7dac fix visibility of private getters
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:39:39 -04:00
Connor Tsui b8ee38b79e move WaitTimeoutResult up to mod.rs
Since `WaitTimeoutResult` is poison-agnostic, we want to use the same
type for both variants of `Condvar`.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:20:47 -04:00
Connor Tsui a8163bd6f4 change Barrier implementation to use nonpoison::Condvar
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:20:46 -04:00
Connor Tsui eaf7fd2fed add nonpoison::condvar implementation
Adds the equivalent `nonpoison` types to the `poison::condvar` module.
These types and implementations are gated under the `nonpoison_condvar`
feature gate.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:17:30 -04:00
Connor Tsui 780319a75b stabilize unstable rwlock_downgrade feature
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
2025-08-23 09:01:38 -04:00
Jacob Pratt 2bd39222cd Rollup merge of #144648 - connortsui20:nonpoison_rwlock, r=Mark-Simulacrum
Implementation: `#[feature(nonpoison_rwlock)]`

Tracking Issue: https://github.com/rust-lang/rust/issues/134645

This PR continues the effort made in https://github.com/rust-lang/rust/pull/144022 by adding the implementation of `nonpoison::rwlock`.

Many of the changes here are similar to the changes made to implement `nonpoison::mutex`. The only real difference is that this PR includes a reorganizing of the existing `poison::rwlock` file that hopefully makes both variants more readable.

### Related PRs

- `nonpoison_condvar` implementation: https://github.com/rust-lang/rust/pull/144651
- `nonpoison_once` implementation: https://github.com/rust-lang/rust/pull/144653
2025-08-22 22:00:46 -04:00