Skip to content

Commit ace37ad

Browse files
taiki-ecramertj
authored andcommitted
Clean up error types
1 parent 4613193 commit ace37ad

File tree

6 files changed

+42
-29
lines changed

6 files changed

+42
-29
lines changed

futures-channel/src/mpsc/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@
8181
use futures_core::stream::{FusedStream, Stream};
8282
use futures_core::task::{Context, Poll, Waker};
8383
use futures_core::task::__internal::AtomicWaker;
84-
use std::any::Any;
85-
use std::error::Error;
8684
use std::fmt;
8785
use std::pin::Pin;
8886
use std::sync::{Arc, Mutex};
@@ -166,7 +164,7 @@ enum SendErrorKind {
166164

167165
/// The error type returned from [`try_next`](Receiver::try_next).
168166
pub struct TryRecvError {
169-
_inner: (),
167+
_priv: (),
170168
}
171169

172170
impl fmt::Display for SendError {
@@ -179,7 +177,7 @@ impl fmt::Display for SendError {
179177
}
180178
}
181179

182-
impl Error for SendError {}
180+
impl std::error::Error for SendError {}
183181

184182
impl SendError {
185183
/// Returns true if this error is a result of the channel being full.
@@ -217,7 +215,7 @@ impl<T> fmt::Display for TrySendError<T> {
217215
}
218216
}
219217

220-
impl<T: Any> Error for TrySendError<T> {}
218+
impl<T: core::any::Any> std::error::Error for TrySendError<T> {}
221219

222220
impl<T> TrySendError<T> {
223221
/// Returns true if this error is a result of the channel being full.
@@ -254,7 +252,7 @@ impl fmt::Display for TryRecvError {
254252
}
255253
}
256254

257-
impl Error for TryRecvError {}
255+
impl std::error::Error for TryRecvError {}
258256

259257
#[derive(Debug)]
260258
struct Inner<T> {
@@ -834,7 +832,7 @@ impl<T> Receiver<T> {
834832
Poll::Ready(msg) => {
835833
Ok(msg)
836834
},
837-
Poll::Pending => Err(TryRecvError { _inner: () }),
835+
Poll::Pending => Err(TryRecvError { _priv: () }),
838836
}
839837
}
840838

futures-core/src/task/spawn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub trait LocalSpawn {
5555

5656
/// An error that occurred during spawning.
5757
pub struct SpawnError {
58-
_hidden: (),
58+
_priv: (),
5959
}
6060

6161
impl fmt::Debug for SpawnError {
@@ -78,7 +78,7 @@ impl std::error::Error for SpawnError {}
7878
impl SpawnError {
7979
/// Spawning failed because the executor has been shut down.
8080
pub fn shutdown() -> Self {
81-
Self { _hidden: () }
81+
Self { _priv: () }
8282
}
8383

8484
/// Check whether spawning failed to the executor being shut down.

futures-executor/src/enter.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,29 @@ thread_local!(static ENTERED: Cell<bool> = Cell::new(false));
77
///
88
/// For more details, see [`enter` documentation](enter()).
99
pub struct Enter {
10-
_a: ()
10+
_priv: (),
1111
}
1212

1313
/// An error returned by `enter` if an execution scope has already been
1414
/// entered.
15-
#[derive(Debug)]
1615
pub struct EnterError {
17-
_a: (),
16+
_priv: (),
1817
}
1918

19+
impl fmt::Debug for EnterError {
20+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21+
f.debug_struct("EnterError").finish()
22+
}
23+
}
24+
25+
impl fmt::Display for EnterError {
26+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27+
write!(f, "an execution scope has already been entered")
28+
}
29+
}
30+
31+
impl std::error::Error for EnterError {}
32+
2033
/// Marks the current thread as being within the dynamic extent of an
2134
/// executor.
2235
///
@@ -42,11 +55,11 @@ pub struct EnterError {
4255
pub fn enter() -> Result<Enter, EnterError> {
4356
ENTERED.with(|c| {
4457
if c.get() {
45-
Err(EnterError { _a: () })
58+
Err(EnterError { _priv: () })
4659
} else {
4760
c.set(true);
4861

49-
Ok(Enter { _a: () })
62+
Ok(Enter { _priv: () })
5063
}
5164
})
5265
}

futures-util/src/future/abortable.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::task::AtomicWaker;
22
use futures_core::future::Future;
33
use futures_core::task::{Context, Poll};
44
use pin_utils::unsafe_pinned;
5+
use core::fmt;
56
use core::pin::Pin;
67
use core::sync::atomic::{AtomicBool, Ordering};
78
use alloc::sync::Arc;
@@ -124,6 +125,15 @@ pub fn abortable<Fut>(future: Fut) -> (Abortable<Fut>, AbortHandle)
124125
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
125126
pub struct Aborted;
126127

128+
impl fmt::Display for Aborted {
129+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
130+
write!(f, "`Abortable` future has been aborted")
131+
}
132+
}
133+
134+
#[cfg(feature = "std")]
135+
impl std::error::Error for Aborted {}
136+
127137
impl<Fut> Future for Abortable<Fut> where Fut: Future {
128138
type Output = Result<Fut::Output, Aborted>;
129139

futures-util/src/lock/bilock.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ use core::sync::atomic::AtomicUsize;
1111
use core::sync::atomic::Ordering::SeqCst;
1212
use alloc::boxed::Box;
1313
use alloc::sync::Arc;
14-
#[cfg(feature = "std")]
15-
use std::any::Any;
16-
#[cfg(feature = "std")]
17-
use std::error::Error;
1814

1915
/// A type of futures-powered synchronization primitive which is a mutex between
2016
/// two possible owners.
@@ -218,7 +214,7 @@ impl<T> fmt::Display for ReuniteError<T> {
218214
}
219215

220216
#[cfg(feature = "std")]
221-
impl<T: Any> Error for ReuniteError<T> {}
217+
impl<T: core::any::Any> std::error::Error for ReuniteError<T> {}
222218

223219
/// Returned RAII guard from the `poll_lock` method.
224220
///

futures-util/src/stream/split.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ use futures_core::task::{Context, Poll};
33
use futures_sink::Sink;
44
use core::fmt;
55
use core::pin::Pin;
6-
#[cfg(feature = "std")]
7-
use std::any::Any;
8-
#[cfg(feature = "std")]
9-
use std::error::Error;
106

117
use crate::lock::BiLock;
128

@@ -47,12 +43,12 @@ fn SplitSink<S: Sink<Item>, Item>(lock: BiLock<S>) -> SplitSink<S, Item> {
4743
/// A `Sink` part of the split pair
4844
#[derive(Debug)]
4945
#[must_use = "sinks do nothing unless polled"]
50-
pub struct SplitSink<S: Sink<Item>, Item> {
46+
pub struct SplitSink<S, Item> {
5147
lock: BiLock<S>,
5248
slot: Option<Item>,
5349
}
5450

55-
impl<S: Sink<Item>, Item> Unpin for SplitSink<S, Item> {}
51+
impl<S, Item> Unpin for SplitSink<S, Item> {}
5652

5753
impl<S: Sink<Item> + Unpin, Item> SplitSink<S, Item> {
5854
/// Attempts to put the two "halves" of a split `Stream + Sink` back
@@ -112,21 +108,21 @@ pub(super) fn split<S: Stream + Sink<Item>, Item>(s: S) -> (SplitSink<S, Item>,
112108

113109
/// Error indicating a `SplitSink<S>` and `SplitStream<S>` were not two halves
114110
/// of a `Stream + Split`, and thus could not be `reunite`d.
115-
pub struct ReuniteError<T: Sink<Item>, Item>(pub SplitSink<T, Item>, pub SplitStream<T>);
111+
pub struct ReuniteError<T, Item>(pub SplitSink<T, Item>, pub SplitStream<T>);
116112

117-
impl<T: Sink<Item>, Item> fmt::Debug for ReuniteError<T, Item> {
113+
impl<T, Item> fmt::Debug for ReuniteError<T, Item> {
118114
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
119115
f.debug_tuple("ReuniteError")
120116
.field(&"...")
121117
.finish()
122118
}
123119
}
124120

125-
impl<T: Sink<Item>, Item> fmt::Display for ReuniteError<T, Item> {
121+
impl<T, Item> fmt::Display for ReuniteError<T, Item> {
126122
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
127123
write!(f, "tried to reunite a SplitStream and SplitSink that don't form a pair")
128124
}
129125
}
130126

131127
#[cfg(feature = "std")]
132-
impl<T: Any + Sink<Item>, Item> Error for ReuniteError<T, Item> {}
128+
impl<T: core::any::Any, Item> std::error::Error for ReuniteError<T, Item> {}

0 commit comments

Comments
 (0)