remove panic docs for atomic load and stores#97590
remove panic docs for atomic load and stores#97590Takashiidobe wants to merge 2 commits intorust-lang:masterfrom
Conversation
|
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
rust/library/core/src/sync/atomic.rs Lines 2574 to 2575 in 0a43923 rust/library/core/src/sync/atomic.rs Lines 2588 to 2589 in 0a43923 |
Makes sense, that closes out this PR. I find it odd that the compiler gives you an error if you explicitly provide the wrong ordering as an Enum but not when the wrong ordering is provided as a variable. If I replace It would be nice to have the compiler catch that case too, but I see that |
Currently, the docs for loads and stores for Atomic types looks like this:
Load:
Store:
tl;dr, the docs indicate that storing with an ordering of
AcquireorAcqRelpanics at runtime, and loading with an ordering ofReleaseorAcqRelpanics at runtime.This hasn't been true since 1.56 landed this patch, making it so incorrect orderings on loads and stores are compile time errors now.
#84039
A minimum example here:
$ cat src/main.rs use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicUsize, Ordering}; fn main() { let atomic_usize = AtomicUsize::default(); atomic_usize.store(10, Ordering::Acquire); atomic_usize.store(20, Ordering::AcqRel); atomic_usize.load(Ordering::Release); atomic_usize.load(Ordering::AcqRel); let atomic_bool = AtomicBool::default(); atomic_bool.store(true, Ordering::Acquire); atomic_bool.store(false, Ordering::AcqRel); atomic_bool.load(Ordering::Release); atomic_bool.load(Ordering::AcqRel); let atomic_ptr = AtomicPtr::default(); let ten_ptr: *mut i32 = &mut 10; atomic_ptr.store(ten_ptr, Ordering::Acquire); atomic_ptr.store(ten_ptr, Ordering::AcqRel); atomic_ptr.load(Ordering::Release); atomic_ptr.load(Ordering::AcqRel); }On 1.55, the same program panics, indicating that the docs were correct at that point in time.
$ cargo run Compiling ordering v0.1.0 (/Users/takashi/Desktop/concurrency-problems/ordering) Finished dev [unoptimized + debuginfo] target(s) in 1.58s Running `target/debug/ordering` thread 'main' panicked at 'there is no such thing as an acquire store', /rustc/c8dfcfe046a7680554bf4eb612bad840e7631c4b/library/core/src/sync/atomic.rs:2342:24 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace