Skip to content

Commit 0140192

Browse files
author
Stjepan Glavina
committed
Fix rustdoc
1 parent 0ce95b5 commit 0140192

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
lines changed

src/fs/dir_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
use std::future::Future;
12
use std::path::Path;
23

34
use cfg_if::cfg_if;
45

5-
use crate::future::Future;
66
use crate::io;
77
use crate::task::blocking;
88

src/fs/open_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use std::future::Future;
12
use std::path::Path;
23

34
use cfg_if::cfg_if;
45

56
use crate::fs::File;
6-
use crate::future::Future;
77
use crate::io;
88
use crate::task::blocking;
99

src/future/future.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use crate::utils::extension_trait;
22

33
cfg_if::cfg_if! {
44
if #[cfg(feature = "docs")] {
5-
use crate::task::{Context, Poll};
65
use std::pin::Pin;
6+
use std::ops::{Deref, DerefMut};
7+
8+
use crate::task::{Context, Poll};
79
}
810
}
911

@@ -104,4 +106,40 @@ extension_trait! {
104106

105107
pub trait FutureExt: std::future::Future {
106108
}
109+
110+
impl<F: Future + Unpin + ?Sized> Future for Box<F> {
111+
type Output = F::Output;
112+
113+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
114+
unreachable!("this impl only appears in the rendered docs")
115+
}
116+
}
117+
118+
impl<F: Future + Unpin + ?Sized> Future for &mut F {
119+
type Output = F::Output;
120+
121+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
122+
unreachable!("this impl only appears in the rendered docs")
123+
}
124+
}
125+
126+
impl<P> Future for Pin<P>
127+
where
128+
P: DerefMut + Unpin,
129+
<P as Deref>::Target: Future,
130+
{
131+
type Output = <<P as Deref>::Target as Future>::Output;
132+
133+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
134+
unreachable!("this impl only appears in the rendered docs")
135+
}
136+
}
137+
138+
impl<F: Future> Future for std::panic::AssertUnwindSafe<F> {
139+
type Output = F::Output;
140+
141+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
142+
unreachable!("this impl only appears in the rendered docs")
143+
}
144+
}
107145
}

src/task/blocking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! A thread pool for running blocking functions asynchronously.
22
3+
use std::future::Future;
34
use std::sync::atomic::{AtomicU64, Ordering};
45
use std::thread;
56
use std::time::Duration;
67

78
use crossbeam_channel::{bounded, Receiver, Sender};
89
use lazy_static::lazy_static;
910

10-
use crate::future::Future;
1111
use crate::task::task::{JoinHandle, Tag};
1212
use crate::utils::abort_on_panic;
1313

src/task/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt;
2+
use std::future::Future;
23
use std::i64;
34
use std::mem;
45
use std::num::NonZeroU64;
@@ -7,7 +8,6 @@ use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
78
use std::sync::Arc;
89

910
use super::task_local;
10-
use crate::future::Future;
1111
use crate::task::{Context, Poll};
1212

1313
/// A handle to a task.

src/task/task_local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::cell::UnsafeCell;
22
use std::error::Error;
33
use std::fmt;
4+
use std::future::Future;
45
use std::sync::atomic::{AtomicUsize, Ordering};
56
use std::sync::Mutex;
67

78
use lazy_static::lazy_static;
89

910
use super::worker;
10-
use crate::future::Future;
1111
use crate::utils::abort_on_panic;
1212

1313
/// Declares task-local values.

src/utils.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn abort_on_panic<T>(f: impl FnOnce() -> T) -> T {
2020
t
2121
}
2222

23-
/// Defines an extension trait for a base trait from the `futures` crate.
23+
/// Defines an extension trait for a base trait.
2424
///
2525
/// In generated docs, the base trait will contain methods from the extension trait. In actual
2626
/// code, the base trait will be re-exported and the extension trait will be hidden. We then
@@ -35,7 +35,7 @@ macro_rules! extension_trait {
3535
// Interesting patterns:
3636
// - `$name`: trait name that gets rendered in the docs
3737
// - `$ext`: name of the hidden extension trait
38-
// - `$base`: base trait from the `futures` crate
38+
// - `$base`: base trait
3939
#[doc = $doc:tt]
4040
pub trait $name:ident {
4141
$($body_base:tt)*
@@ -87,13 +87,21 @@ macro_rules! extension_trait {
8787
};
8888

8989
// Parse the return type in an extension method.
90-
(@doc ($($head:tt)*) -> impl Future<Output = $out:ty> $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*) => {
91-
extension_trait!(@doc ($($head)* -> borrowed::ImplFuture<$($lt,)? $out>) $($tail)*);
90+
(@doc ($($head:tt)*) -> impl Future<Output = $out:ty> [$f:ty] $($tail:tt)*) => {
91+
extension_trait!(@doc ($($head)* -> owned::ImplFuture<$out>) $($tail)*);
9292
};
9393
(@ext ($($head:tt)*) -> impl Future<Output = $out:ty> $(+ $lt:lifetime)? [$f:ty] $($tail:tt)*) => {
9494
extension_trait!(@ext ($($head)* -> $f) $($tail)*);
9595
};
9696

97+
// Parse the return type in an extension method.
98+
(@doc ($($head:tt)*) -> impl Future<Output = $out:ty> + $lt:lifetime [$f:ty] $($tail:tt)*) => {
99+
extension_trait!(@doc ($($head)* -> borrowed::ImplFuture<$lt, $out>) $($tail)*);
100+
};
101+
(@ext ($($head:tt)*) -> impl Future<Output = $out:ty> + $lt:lifetime [$f:ty] $($tail:tt)*) => {
102+
extension_trait!(@ext ($($head)* -> $f) $($tail)*);
103+
};
104+
97105
// Parse a token.
98106
(@doc ($($head:tt)*) $token:tt $($tail:tt)*) => {
99107
extension_trait!(@doc ($($head)* $token) $($tail)*);

0 commit comments

Comments
 (0)