Skip to content

Commit 91f002d

Browse files
Merge #209
209: add feature guards for unstable features r=yoshuawuyts a=yoshuawuyts Makes sure unstable features aren't accidentally usable without their corresponding flags. Thanks! Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com> Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
2 parents bfd7af8 + bd43490 commit 91f002d

File tree

8 files changed

+39
-14
lines changed

8 files changed

+39
-14
lines changed

Diff for: .travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ matrix:
5050
rust: nightly
5151
os: linux
5252
script:
53-
- cargo doc --features docs
53+
- cargo doc --features docs unstable
5454

5555
- name: book
5656
rust: nightly
@@ -64,4 +64,4 @@ matrix:
6464

6565
script:
6666
- cargo check --features unstable --all --benches --bins --examples --tests
67-
- cargo test --features unstable --all
67+
- cargo test --all --doc --features unstable

Diff for: src/future/timeout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::task::{Context, Poll};
2929
/// # Ok(()) }) }
3030
/// ```
3131
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
32+
#[cfg(any(feature = "unstable", feature = "docs"))]
3233
pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
3334
where
3435
F: Future<Output = T>,
@@ -69,6 +70,7 @@ impl<F: Future> Future for TimeoutFuture<F> {
6970

7071
/// An error returned when a future times out.
7172
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
73+
#[cfg(any(feature = "unstable", feature = "docs"))]
7274
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
7375
pub struct TimeoutError {
7476
_private: (),

Diff for: src/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,24 @@
4242
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
4343
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
4444

45+
use cfg_if::cfg_if;
46+
4547
pub mod fs;
4648
pub mod future;
4749
pub mod io;
4850
pub mod net;
4951
pub mod os;
5052
pub mod prelude;
51-
mod result;
5253
pub mod stream;
5354
pub mod sync;
5455
pub mod task;
55-
mod vec;
5656

57-
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
58-
#[cfg(feature = "unstable")]
59-
pub mod pin;
57+
cfg_if! {
58+
if #[cfg(any(feature = "unstable", feature = "docs"))] {
59+
pub mod pin;
60+
mod vec;
61+
mod result;
62+
}
63+
}
6064

6165
pub(crate) mod utils;

Diff for: src/stream/double_ended_stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::task::{Context, Poll};
1111
///
1212
/// [`Stream`]: trait.Stream.html
1313
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
14+
#[cfg(any(feature = "unstable", feature = "docs"))]
1415
pub trait DoubleEndedStream: Stream {
1516
/// Removes and returns an element from the end of the stream.
1617
///

Diff for: src/stream/from_stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::pin::Pin;
1111
///
1212
/// [`IntoStream`]: trait.IntoStream.html
1313
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
14+
#[cfg(any(feature = "unstable", feature = "docs"))]
1415
pub trait FromStream<T: Send> {
1516
/// Creates a value from a stream.
1617
///

Diff for: src/stream/into_stream.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use futures_core::stream::Stream;
1414
///
1515
/// [`FromStream`]: trait.FromStream.html
1616
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
17+
#[cfg(any(feature = "unstable", feature = "docs"))]
1718
pub trait IntoStream {
1819
/// The type of the elements being iterated over.
1920
type Item;

Diff for: src/stream/mod.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,26 @@
2121
//! # }) }
2222
//! ```
2323
24-
pub use double_ended_stream::DoubleEndedStream;
24+
use cfg_if::cfg_if;
25+
2526
pub use empty::{empty, Empty};
26-
pub use from_stream::FromStream;
27-
pub use into_stream::IntoStream;
2827
pub use once::{once, Once};
2928
pub use repeat::{repeat, Repeat};
3029
pub use stream::{Fuse, Scan, Stream, Take, Zip};
3130

32-
mod double_ended_stream;
3331
mod empty;
34-
mod from_stream;
35-
mod into_stream;
3632
mod once;
3733
mod repeat;
3834
mod stream;
35+
36+
cfg_if! {
37+
if #[cfg(any(feature = "unstable", feature = "docs"))] {
38+
mod double_ended_stream;
39+
mod from_stream;
40+
mod into_stream;
41+
42+
pub use double_ended_stream::DoubleEndedStream;
43+
pub use from_stream::FromStream;
44+
pub use into_stream::IntoStream;
45+
}
46+
}

Diff for: src/stream/stream/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ use min_by::MinByFuture;
5252
use next::NextFuture;
5353
use nth::NthFuture;
5454

55-
use super::from_stream::FromStream;
5655
use std::cmp::Ordering;
5756
use std::marker::PhantomData;
5857
use std::pin::Pin;
5958
use std::task::{Context, Poll};
6059

6160
use cfg_if::cfg_if;
6261

62+
cfg_if! {
63+
if #[cfg(any(feature = "unstable", feature = "docs"))] {
64+
use crate::stream::FromStream;
65+
}
66+
}
67+
6368
cfg_if! {
6469
if #[cfg(feature = "docs")] {
6570
#[doc(hidden)]
@@ -91,6 +96,7 @@ cfg_if! {
9196
($a:lifetime, $o:ty) => (DynFuture<$a, $o>);
9297
}
9398
} else {
99+
#[allow(unused_macros)]
94100
macro_rules! dyn_ret {
95101
($a:lifetime, $o:ty) => (Pin<Box<dyn core::future::Future<Output = $o> + Send + 'a>>)
96102
}
@@ -748,6 +754,8 @@ pub trait Stream {
748754
///
749755
/// [`stream`]: trait.Stream.html#tymethod.next
750756
#[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead (TODO)"]
757+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
758+
#[cfg(any(feature = "unstable", feature = "docs"))]
751759
fn collect<'a, B>(self) -> dyn_ret!('a, B)
752760
where
753761
Self: futures_core::stream::Stream + Sized + Send + 'a,

0 commit comments

Comments
 (0)