Skip to content

Commit f687686

Browse files
tisonkunorthur2
andauthored
fix: tighten oneshot memory ordering (#111)
Signed-off-by: tison <wander4096@gmail.com> Co-authored-by: orthur2 <orthur2@gmail.com>
1 parent 6866467 commit f687686

5 files changed

Lines changed: 373 additions & 140 deletions

File tree

‎mea/src/mpsc/bounded.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl<T> Clone for BoundedSender<T> {
8585
}
8686

8787
impl<T> fmt::Debug for BoundedSender<T> {
88-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
89-
fmt.debug_struct("BoundedSender").finish_non_exhaustive()
88+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
89+
f.debug_struct("BoundedSender").finish_non_exhaustive()
9090
}
9191
}
9292

@@ -227,8 +227,8 @@ pub struct BoundedReceiver<T> {
227227
unsafe impl<T: Send> Sync for BoundedReceiver<T> {}
228228

229229
impl<T> fmt::Debug for BoundedReceiver<T> {
230-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
231-
fmt.debug_struct("BoundedReceiver").finish_non_exhaustive()
230+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
231+
f.debug_struct("BoundedReceiver").finish_non_exhaustive()
232232
}
233233
}
234234

‎mea/src/mpsc/error.rs‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::any::type_name;
1516
use std::fmt;
1617

1718
/// An error returned when trying to send on a closed channel.
@@ -49,13 +50,13 @@ impl<T> SendError<T> {
4950

5051
impl<T> fmt::Display for SendError<T> {
5152
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52-
"sending on a closed channel".fmt(f)
53+
f.write_str("sending on a closed channel")
5354
}
5455
}
5556

5657
impl<T> fmt::Debug for SendError<T> {
5758
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58-
write!(f, "SendError<{}>(..)", stringify!(T))
59+
write!(f, "SendError<{}>(..)", type_name::<T>())
5960
}
6061
}
6162

@@ -88,21 +89,20 @@ impl<T> TrySendError<T> {
8889
}
8990

9091
impl<T> fmt::Display for TrySendError<T> {
91-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
92-
match self {
93-
TrySendError::Full(_) => "sending on a full channel".fmt(fmt),
94-
TrySendError::Disconnected(_) => "sending on a closed channel".fmt(fmt),
95-
}
92+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
93+
f.write_str(match self {
94+
TrySendError::Full(_) => "sending on a full channel",
95+
TrySendError::Disconnected(_) => "sending on a closed channel",
96+
})
9697
}
9798
}
9899

99100
impl<T> fmt::Debug for TrySendError<T> {
100-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
101+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
102+
let ty = type_name::<T>();
101103
match self {
102-
TrySendError::Full(_) => write!(fmt, "TrySendError<{}>::Full(..)", stringify!(T)),
103-
TrySendError::Disconnected(_) => {
104-
write!(fmt, "TrySendError<{}>::Disconnected(..)", stringify!(T))
105-
}
104+
TrySendError::Full(_) => write!(f, "TrySendError<{ty}>::Full(..)"),
105+
TrySendError::Disconnected(_) => write!(f, "TrySendError<{ty}>::Disconnected(..)"),
106106
}
107107
}
108108
}
@@ -117,8 +117,8 @@ pub enum RecvError {
117117
}
118118

119119
impl fmt::Display for RecvError {
120-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
121-
"receiving on a closed channel".fmt(fmt)
120+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
121+
f.write_str("receiving on a closed channel")
122122
}
123123
}
124124

@@ -135,11 +135,11 @@ pub enum TryRecvError {
135135
}
136136

137137
impl fmt::Display for TryRecvError {
138-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
139-
match *self {
140-
TryRecvError::Empty => "receiving on an empty channel".fmt(fmt),
141-
TryRecvError::Disconnected => "receiving on a closed channel".fmt(fmt),
142-
}
138+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139+
f.write_str(match self {
140+
TryRecvError::Empty => "receiving on an empty channel",
141+
TryRecvError::Disconnected => "receiving on a closed channel",
142+
})
143143
}
144144
}
145145

‎mea/src/mpsc/unbounded.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ impl<T> Clone for UnboundedSender<T> {
7979
}
8080

8181
impl<T> fmt::Debug for UnboundedSender<T> {
82-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
83-
fmt.debug_struct("UnboundedSender").finish_non_exhaustive()
82+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
83+
f.debug_struct("UnboundedSender").finish_non_exhaustive()
8484
}
8585
}
8686

@@ -139,9 +139,8 @@ pub struct UnboundedReceiver<T> {
139139
unsafe impl<T: Send> Sync for UnboundedReceiver<T> {}
140140

141141
impl<T> fmt::Debug for UnboundedReceiver<T> {
142-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
143-
fmt.debug_struct("UnboundedReceiver")
144-
.finish_non_exhaustive()
142+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
143+
f.debug_struct("UnboundedReceiver").finish_non_exhaustive()
145144
}
146145
}
147146

0 commit comments

Comments
 (0)