Skip to content

Commit 9ee47f2

Browse files
committed
Add private fields for forward compatibility
1 parent 62894c6 commit 9ee47f2

File tree

9 files changed

+67
-27
lines changed

9 files changed

+67
-27
lines changed

futures-channel/src/mpsc/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ enum SendErrorKind {
166166

167167
/// The error type returned from [`try_next`](Receiver::try_next).
168168
pub struct TryRecvError {
169-
_inner: (),
169+
_priv: (),
170170
}
171171

172172
impl fmt::Display for SendError {
@@ -834,7 +834,7 @@ impl<T> Receiver<T> {
834834
Poll::Ready(msg) => {
835835
Ok(msg)
836836
},
837-
Poll::Pending => Err(TryRecvError { _inner: () }),
837+
Poll::Pending => Err(TryRecvError { _priv: () }),
838838
}
839839
}
840840

futures-channel/src/oneshot.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<T> Inner<T> {
249249
return Ok(Some(data));
250250
}
251251
}
252-
Err(Canceled)
252+
Err(Canceled { _priv: () })
253253
} else {
254254
Ok(None)
255255
}
@@ -290,7 +290,7 @@ impl<T> Inner<T> {
290290
return Poll::Ready(Ok(data));
291291
}
292292
}
293-
Poll::Ready(Err(Canceled))
293+
Poll::Ready(Err(Canceled { _priv: () }))
294294
} else {
295295
Poll::Pending
296296
}
@@ -377,8 +377,16 @@ impl<T> Drop for Sender<T> {
377377

378378
/// Error returned from a [`Receiver`](Receiver) when the corresponding
379379
/// [`Sender`](Sender) is dropped.
380-
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
381-
pub struct Canceled;
380+
#[derive(Clone, Copy, PartialEq, Eq)]
381+
pub struct Canceled {
382+
_priv: (),
383+
}
384+
385+
impl fmt::Debug for Canceled {
386+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
387+
f.debug_struct("Canceled").finish()
388+
}
389+
}
382390

383391
impl fmt::Display for Canceled {
384392
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

futures-core/src/task/spawn.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 19 additions & 5 deletions
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
}
@@ -65,3 +78,4 @@ impl Drop for Enter {
6578
});
6679
}
6780
}
81+

futures-util/src/future/abortable.rs

Lines changed: 13 additions & 4 deletions
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;
@@ -121,16 +122,24 @@ pub fn abortable<Fut>(future: Fut) -> (Abortable<Fut>, AbortHandle)
121122
}
122123

123124
/// Indicator that the `Abortable` future was aborted.
124-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
125-
pub struct Aborted;
125+
#[derive(Copy, Clone, Eq, PartialEq)]
126+
pub struct Aborted {
127+
_priv: (),
128+
}
129+
130+
impl fmt::Debug for Aborted {
131+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
132+
f.debug_tuple("Aborted").finish()
133+
}
134+
}
126135

127136
impl<Fut> Future for Abortable<Fut> where Fut: Future {
128137
type Output = Result<Fut::Output, Aborted>;
129138

130139
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
131140
// Check if the future has been aborted
132141
if self.inner.cancel.load(Ordering::Relaxed) {
133-
return Poll::Ready(Err(Aborted))
142+
return Poll::Ready(Err(Aborted { _priv: () }))
134143
}
135144

136145
// attempt to complete the future
@@ -146,7 +155,7 @@ impl<Fut> Future for Abortable<Fut> where Fut: Future {
146155
// Checking with `Relaxed` is sufficient because `register` introduces an
147156
// `AcqRel` barrier.
148157
if self.inner.cancel.load(Ordering::Relaxed) {
149-
return Poll::Ready(Err(Aborted))
158+
return Poll::Ready(Err(Aborted { _priv: () }))
150159
}
151160

152161
Poll::Pending

futures/tests/abortable.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures::channel::oneshot;
22
use futures::executor::block_on;
3-
use futures::future::{abortable, Aborted, FutureExt};
3+
use futures::future::{abortable, FutureExt};
44
use futures::task::{Context, Poll};
55
use futures_test::task::new_count_waker;
66

@@ -10,7 +10,7 @@ fn abortable_works() {
1010
let (abortable_rx, abort_handle) = abortable(a_rx);
1111

1212
abort_handle.abort();
13-
assert_eq!(Err(Aborted), block_on(abortable_rx));
13+
assert!(block_on(abortable_rx).is_err());
1414
}
1515

1616
#[test]
@@ -25,7 +25,10 @@ fn abortable_awakens() {
2525
assert_eq!(counter, 0);
2626
abort_handle.abort();
2727
assert_eq!(counter, 1);
28-
assert_eq!(Poll::Ready(Err(Aborted)), abortable_rx.poll_unpin(&mut cx));
28+
match abortable_rx.poll_unpin(&mut cx) {
29+
Poll::Ready(Err(_)) => {}
30+
_ => unreachable!()
31+
}
2932
}
3033

3134
#[test]

futures/tests/futures_unordered.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ fn iter_mut_cancel() {
137137
assert!(b_tx.is_canceled());
138138
assert!(c_tx.is_canceled());
139139

140-
assert_eq!(iter.next(), Some(Err(futures::channel::oneshot::Canceled)));
141-
assert_eq!(iter.next(), Some(Err(futures::channel::oneshot::Canceled)));
142-
assert_eq!(iter.next(), Some(Err(futures::channel::oneshot::Canceled)));
140+
assert!(iter.next().unwrap().is_err());
141+
assert!(iter.next().unwrap().is_err());
142+
assert!(iter.next().unwrap().is_err());
143143
assert_eq!(iter.next(), None);
144144
}
145145

futures/tests/oneshot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn oneshot_drop_tx1() {
4343
drop(tx1);
4444
rx1.map(move |result| tx2.send(result).unwrap()).run_in_background();
4545

46-
assert_eq!(Err(oneshot::Canceled), rx2.recv().unwrap());
46+
assert!(rx2.recv().unwrap().is_err());
4747
}
4848

4949
#[test]
@@ -55,7 +55,7 @@ fn oneshot_drop_tx2() {
5555
rx1.map(move |result| tx2.send(result).unwrap()).run_in_background();
5656
t.join().unwrap();
5757

58-
assert_eq!(Err(oneshot::Canceled), rx2.recv().unwrap());
58+
assert!(rx2.recv().unwrap().is_err());
5959
}
6060

6161
#[test]

futures/tests/ready_queue.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,19 @@ fn resolving_errors() {
5555

5656
drop(tx2);
5757

58-
assert_eq!(Poll::Ready(Some(Err(oneshot::Canceled))), queue.poll_next_unpin(cx));
58+
match queue.poll_next_unpin(cx) {
59+
Poll::Ready(Some(Err(_))) => {}
60+
_ => unreachable!(),
61+
}
5962
assert!(!queue.poll_next_unpin(cx).is_ready());
6063

6164
drop(tx1);
6265
tx3.send("world2").unwrap();
6366

64-
assert_eq!(Poll::Ready(Some(Err(oneshot::Canceled))), queue.poll_next_unpin(cx));
67+
match queue.poll_next_unpin(cx) {
68+
Poll::Ready(Some(Err(_))) => {}
69+
_ => unreachable!(),
70+
}
6571
assert_eq!(Poll::Ready(Some(Ok("world2"))), queue.poll_next_unpin(cx));
6672
assert_eq!(Poll::Ready(None), queue.poll_next_unpin(cx));
6773
}));

0 commit comments

Comments
 (0)