264 Commits

Author SHA1 Message Date
Christian Schwarz
660f76fdca channel: Add recv (#2947) 2025-04-16 22:24:28 +09:00
Christian Schwarz
89e5d8b26c channel: Add try_recv and deprecate try_next (#2944) 2025-04-09 15:59:27 +09:00
tison
6f9a15f6e3 bump msrv to 1.68
Signed-off-by: tison <wander4096@gmail.com>
2025-04-07 22:46:27 +09:00
tison
4c940a0cda chore: replace all test usage of pin_mut (#2942)
Signed-off-by: tison <wander4096@gmail.com>
2025-04-05 18:44:15 +09:00
Taiki Endo
5285d05c3e Remove no longer necessary allowed lints 2025-01-25 14:23:33 +09:00
@brodycj - C. Jonathan Brody
036957bbcd Bump MSRV of utility crates to 1.63 (#2907) 2025-01-13 00:38:27 +09:00
Taiki Endo
4853d16b08 Use *::MAX associated constants 2024-03-09 03:29:54 +09:00
Taiki Endo
3488f46906 Ignore dead_code lint on Assert* traits
```
warning: trait `AssertSync` is never used
   --> futures-core/src/task/__internal/atomic_waker.rs:209:15
    |
209 |         trait AssertSync: Sync {}
    |               ^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: trait `AssertKinds` is never used
   --> futures-channel/src/mpsc/mod.rs:130:7
    |
130 | trait AssertKinds: Send + Sync + Clone {}
    |       ^^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: trait `AssertSendSync` is never used
  --> futures-executor/src/thread_pool.rs:48:7
   |
48 | trait AssertSendSync: Send + Sync {}
   |       ^^^^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: trait `AssertSend` is never used
  --> futures-channel/tests/mpsc.rs:13:7
   |
13 | trait AssertSend: Send {}
   |       ^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default
```
2024-02-26 23:26:11 +09:00
Taiki Endo
79785ec41d Always set #![no_std] and remove redundant imports
```
error: the item `Box` is imported redundantly
  --> futures-core/src/future.rs:89:9
   |
89 |     use alloc::boxed::Box;
   |         ^^^^^^^^^^^^^^^^^
  --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/prelude/mod.rs:115:13
   |
   = note: the item `Box` is already defined here
   |
   = note: `-D unused-imports` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unused_imports)]`

error: the item `Box` is imported redundantly
   --> futures-core/src/stream.rs:203:9
    |
203 |     use alloc::boxed::Box;
    |         ^^^^^^^^^^^^^^^^^
   --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/prelude/mod.rs:115:13
    |
    = note: the item `Box` is already defined here
```
2024-02-26 23:26:11 +09:00
Taiki Endo
6560b712f5 Remove unnecessary allowed lints 2023-12-24 22:49:03 +09:00
Taiki Endo
1e6e06cb9d Apply unsafe_op_in_unsafe_fn lint if available on MSRV 2023-12-24 22:49:03 +09:00
Taiki Endo
f84f363299 Use Self keyword instead of concrete type name 2023-12-24 22:49:03 +09:00
Taiki Endo
9e5fccf437 Use [lints] in Cargo.toml 2023-12-24 22:49:03 +09:00
Taiki Endo
970e0888df Use cfg(target_has_atomic) on no-std targets 2023-12-08 22:37:00 +09:00
Taiki Endo
e9bda1dca9 Fix rustdoc::redundant_explicit_links warning (#2769) 2023-08-23 10:57:10 +09:00
thement
0b2d34e607 Add len, is_empty methods for UnboundedSender (#2750)
- add `len`, `is_empty` methods to inspect how many messages are
  enqueued in the message queue.
- add test for `len` and `is_empty`

Co-authored-by: Jakub Horak <jakub.horak@ibawizard.net>
2023-07-25 21:40:09 +09:00
Taiki Endo
bdd0f826d6 Ignore clippy::needless_pass_by_ref_mut lint
```
warning: this argument is a mutable reference, but not used mutably
   --> futures-channel/src/oneshot.rs:154:33
    |
154 |     fn poll_canceled(&self, cx: &mut Context<'_>) -> Poll<()> {
    |                                 ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
    = note: `#[warn(clippy::needless_pass_by_ref_mut)]` on by default

warning: this argument is a mutable reference, but not used mutably
   --> futures-channel/src/oneshot.rs:256:24
    |
256 | ... recv(&self, cx: &mut Context<'_>) -> Poll<Result<T, Cancel...
    |                     ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut

warning: this argument is a mutable reference, but not used mutably
   --> futures-util/src/future/future/shared.rs:212:55
    |
212 | ... &mut usize, cx: &mut Context<'_>) {
    |                     ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
    = note: `#[warn(clippy::needless_pass_by_ref_mut)]` on by default

warning: this argument is a mutable reference, but not used mutably
   --> futures-util/src/stream/stream/flatten_unordered.rs:212:39
    |
212 | ..._waker(self_arc: &mut Arc<Self>, cx: &Context<'_>) {
    |                     ^^^^^^^^^^^^^^ help: consider changing to: `&Arc<Self>`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut

warning: this argument is a mutable reference, but not used mutably
  --> futures-util/src/compat/compat01as03.rs:36:36
   |
36 | ...>(&mut self, cx: &mut Context<'_>, f: impl FnOnce(&mut T) ->...
   |                     ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut

warning: this argument is a mutable reference, but not used mutably
   --> futures-util/src/compat/compat01as03.rs:199:36
    |
199 | ...>(&mut self, cx: &mut Context<'_>, f: impl FnOnce(&mut S) -...
    |                     ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut

warning: this argument is a mutable reference, but not used mutably
  --> futures-util/src/lock/bilock.rs:90:33
   |
90 | ..._lock(&self, cx: &mut Context<'_>) -> Poll<BiLockGuard<'_, T...
   |                     ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
   |
   = warning: changing this function will impact semver compatibility
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut

warning: this argument is a mutable reference, but not used mutably
   --> futures/tests/sink.rs:160:25
    |
160 |     fn check(&self, cx: &mut Context<'_>) -> bool {
    |                         ^^^^^^^^^^^^^^^^ help: consider changing to: `&Context<'_>`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
    = note: `#[warn(clippy::needless_pass_by_ref_mut)]` on by default
```
2023-07-20 01:08:45 +09:00
Taiki Endo
67b417d8a8 Ignore buggy clippy::arc_with_non_send_sync lint
```
error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
   --> futures-channel/src/mpsc/mod.rs:348:17
    |
348 |       let inner = Arc::new(BoundedInner {
    |  _________________^
349 | |         buffer,
350 | |         state: AtomicUsize::new(INIT_STATE),
351 | |         message_queue: Queue::new(),
...   |
354 | |         recv_task: AtomicWaker::new(),
355 | |     });
    | |______^
    |
    = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
    = note: `#[deny(clippy::arc_with_non_send_sync)]` on by default

error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
   --> futures-channel/src/mpsc/mod.rs:379:17
    |
379 |       let inner = Arc::new(UnboundedInner {
    |  _________________^
380 | |         state: AtomicUsize::new(INIT_STATE),
381 | |         message_queue: Queue::new(),
382 | |         num_senders: AtomicUsize::new(1),
383 | |         recv_task: AtomicWaker::new(),
384 | |     });
    | |______^
    |
    = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync

error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
   --> futures-channel/src/oneshot.rs:105:17
    |
105 |     let inner = Arc::new(Inner::new());
    |                 ^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync

error: could not compile `futures-channel` (lib) due to 3 previous errors

error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
   --> futures-util/src/future/future/shared.rs:101:28
    |
101 |         Self { inner: Some(Arc::new(inner)), waker_key: NULL_WAKER_KEY }
    |                            ^^^^^^^^^^^^^^^
    |
    = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
    = note: `#[deny(clippy::arc_with_non_send_sync)]` on by default

error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
   --> futures-util/src/stream/futures_unordered/mod.rs:131:34
    |
131 |           let ready_to_run_queue = Arc::new(ReadyToRunQueue {
    |  __________________________________^
132 | |             waker: AtomicWaker::new(),
133 | |             head: AtomicPtr::new(stub_ptr as *mut _),
134 | |             tail: UnsafeCell::new(stub_ptr),
135 | |             stub,
136 | |         });
    | |__________^
    |
    = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync

error: usage of `Arc<T>` where `T` is not `Send` or `Sync`
  --> futures-util/src/lock/bilock.rs:64:19
   |
64 |           let arc = Arc::new(Inner {
   |  ___________________^
65 | |             state: AtomicPtr::new(ptr::null_mut()),
66 | |             value: Some(UnsafeCell::new(t)),
67 | |         });
   | |__________^
   |
   = help: consider using `Rc<T>` instead or wrapping `T` in a std::sync type like `Mutex<T>`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
```
2023-07-11 02:33:09 +09:00
Taiki Endo
3fc74df38e Bump MSRV of utility crates to 1.56 (#2733)
syn 2.0 requires 1.56.
2023-03-31 01:42:21 +09:00
Stepan Koltsov
1436c05371 Stream::size_hint for mpsc channels (#2660) 2022-11-27 17:44:37 +09:00
daxpedda
769632c842 Remove Debug constraint for oneshot types (#2666) 2022-11-27 17:41:44 +09:00
daxpedda
be27d72f3b Custom Debug implementations for mpsc (#2667) 2022-11-27 17:41:25 +09:00
Taiki Endo
479a447847 Revert "Fix clippy::assertions_on_result_states warning"
This reverts commit 750fe3ee8a.
2022-08-14 21:57:18 +09:00
Taiki Endo
750fe3ee8a Fix clippy::assertions_on_result_states warning 2022-07-30 14:01:23 +09:00
Taiki Endo
37eb10444d Fix clippy::match_like_matches_macro warning
```
warning: match expression looks like `matches!` macro
   --> futures-channel/src/mpsc/mod.rs:195:9
    |
195 | /         match self.kind {
196 | |             SendErrorKind::Full => true,
197 | |             _ => false,
198 | |         }
    | |_________^ help: try this: `matches!(self.kind, SendErrorKind::Full)`
    |
    = note: `#[warn(clippy::match_like_matches_macro)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
   --> futures-channel/src/mpsc/mod.rs:203:9
    |
203 | /         match self.kind {
204 | |             SendErrorKind::Disconnected => true,
205 | |             _ => false,
206 | |         }
    | |_________^ help: try this: `matches!(self.kind, SendErrorKind::Disconnected)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-macro/src/select.rs:66:28
   |
66 |               let is_block = match expr {
   |  ____________________________^
67 | |                 Expr::Block(_) => true,
68 | |                 _ => false,
69 | |             };
   | |_____________^ help: try this: `matches!(expr, Expr::Block(_))`
   |
   = note: `#[warn(clippy::match_like_matches_macro)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/future/future/flatten.rs:32:9
   |
32 | /         match self {
33 | |             Self::Empty => true,
34 | |             _ => false,
35 | |         }
   | |_________^ help: try this: `matches!(self, Self::Empty)`
   |
   = note: `#[warn(clippy::match_like_matches_macro)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/future/future/flatten.rs:70:9
   |
70 | /         match self {
71 | |             Self::Empty => true,
72 | |             _ => false,
73 | |         }
   | |_________^ help: try this: `matches!(self, Self::Empty)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/future/try_future/try_flatten.rs:32:9
   |
32 | /         match self {
33 | |             Self::Empty => true,
34 | |             _ => false,
35 | |         }
   | |_________^ help: try this: `matches!(self, Self::Empty)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/future/try_future/try_flatten.rs:73:9
   |
73 | /         match self {
74 | |             Self::Empty => true,
75 | |             _ => false,
76 | |         }
   | |_________^ help: try this: `matches!(self, Self::Empty)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/future/try_future/try_flatten_err.rs:29:9
   |
29 | /         match self {
30 | |             Self::Empty => true,
31 | |             _ => false,
32 | |         }
   | |_________^ help: try this: `matches!(self, Self::Empty)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: if let .. else expression looks like `matches!` macro
  --> futures-util/src/stream/stream/cycle.rs:62:9
   |
62 | /         if let (0, Some(0)) = self.size_hint() {
63 | |             true
64 | |         } else {
65 | |             false
66 | |         }
   | |_________^ help: try this: `matches!(self.size_hint(), (0, Some(0)))`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
   --> futures-util/src/stream/select_with_strategy.rs:202:9
    |
202 | /         match self.internal_state {
203 | |             InternalState::BothFinished => true,
204 | |             _ => false,
205 | |         }
    | |_________^ help: try this: `matches!(self.internal_state, InternalState::BothFinished)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: if let .. else expression looks like `matches!` macro
  --> futures-util/src/stream/unfold.rs:84:9
   |
84 | /         if let UnfoldState::Empty = self.state {
85 | |             true
86 | |         } else {
87 | |             false
88 | |         }
   | |_________^ help: try this: `matches!(self.state, UnfoldState::Empty)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/unfold_state.rs:24:9
   |
24 | /         match self {
25 | |             Self::Empty => true,
26 | |             _ => false,
27 | |         }
   | |_________^ help: try this: `matches!(self, Self::Empty)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

warning: match expression looks like `matches!` macro
  --> futures-util/src/unfold_state.rs:31:9
   |
31 | /         match self {
32 | |             Self::Future { .. } => true,
33 | |             _ => false,
34 | |         }
   | |_________^ help: try this: `matches!(self, Self::Future { .. })`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro
```
2022-07-22 22:42:48 +09:00
Taiki Endo
f466d6131a Run more tests with Miri (#2624) 2022-07-22 22:10:05 +09:00
Taiki Endo
7c3e45f056 Update comments in build scripts 2022-02-06 15:11:06 +09:00
Taiki Endo
dea55a4c5f Clean up ci/no_atomic_cas.sh 2022-02-06 15:11:06 +09:00
Taiki Endo
cd1f29ac1c Remove unnecessarily allowed lints 2022-02-06 12:59:58 +09:00
Taiki Endo
0ac12808df Run Miri on CI 2022-01-13 05:34:57 +09:00
Taiki Endo
d0f07bdc6b Remove authors field from Cargo.toml (#2521)
https://rust-lang.github.io/rfcs/3052-optional-authors-field.html
2021-11-23 10:09:06 +09:00
Taiki Endo
9f73b8dcea Add rust-version field to Cargo.toml
https://doc.rust-lang.org/cargo/reference/manifest.html#the-rust-version-field
2021-11-23 09:54:21 +09:00
Taiki Endo
ad8af5dcea Bump MSRV of utility crates to 1.45 2021-11-23 09:54:21 +09:00
Taiki Endo
714797a942 Remove doc URL from Cargo.toml
https://doc.rust-lang.org/cargo/reference/manifest.html#the-documentation-field

> If no URL is specified in the manifest file, crates.io will
> automatically link your crate to the corresponding docs.rs page.
2021-11-23 09:05:40 +09:00
hi-rustin
3ccce33a14 Make clippy happy
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-11-21 18:00:52 +09:00
Taiki Endo
26493b5859 Ignore clippy::if_then_panic lint 2021-10-01 22:05:46 +09:00
Taiki Endo
00afc3b9a2 Fix typos (#2449) 2021-06-09 01:02:08 +09:00
Taiki Endo
5ed16261da Adjust lints (#2441) 2021-05-12 22:47:30 +09:00
Taiki Endo
f70e95f139 Remove cfg_target_has_atomic! macro (#2439) 2021-05-12 22:03:09 +09:00
Taiki Endo
6699d7ce90 Remove unneeded cfg-target-has-atomic feature 2021-05-08 01:06:59 +09:00
Taiki Endo
569106699d Format modules defined inside macros
`cargo fmt` cannot recognize modules defined inside macros.
2021-05-07 23:45:01 +09:00
Taiki Endo
9c107dbc06 Remove outdated comment 2021-05-07 21:43:33 +09:00
Taiki Endo
ccb0410746 Revert "add size_hint to mpsc receiver"
This reverts commit 0e4dc7da60.
2021-05-07 21:43:33 +09:00
ibraheemdev
0e4dc7da60 add size_hint to mpsc receiver 2021-05-07 20:27:08 +09:00
Geoffry Song
4124d8b85c Override Debug for oneshot::{Sender,Receiver}.
Prior to this diff, the Debug impl for oneshot channels printed something like:
```
Sender { inner: Inner { complete: false, data: Lock { locked: false, data: UnsafeCell }, rx_task: Lock { locked: false, data: UnsafeCell }, tx_task: Lock { locked: false, data: UnsafeCell } } }
```
which isn't very helpful. Instead, just print
`Sender { complete: false }` (or `true`, if the other end has dropped).

Note that the `T: Debug` bound is retained to allow for the possibility
of allowing slightly more interesting debug output in the future.
2021-05-07 11:14:25 +09:00
Taiki Endo
c180a3aacb Remove uses of unstable feature(cfg_target_has_atomic) 2021-05-06 20:12:23 +09:00
Jacob Hughes
dd019055ef Rustfmt all code
If this commit is showing up in your git blame, do the following:
git config blame.ignoreRevsFile .git-blame-ignore-revs
2021-04-10 15:23:29 +09:00
Stiopa Koltsov
2fa7babdf9 Add Receiver::try_next return value descriptions
Similar change applied to `UnboundedReceiver::try_next` a few commits ago.
2021-03-01 12:29:40 +09:00
Stiopa Koltsov
4d2ad0e9ce Allow calling UnboundedReceiver::try_next after None
Allow calling `UnboundedReceiver::try_next` and `Receiver::try_next`
after `None`: do not panic.

Not-panicking is equally safe, and does not have negative performance
implication.

It is irrelevant for `Stream` implementation to panic or not (because
`Stream` behavior is unspecified after `None`), but panicking in
`try_next` just complicates the interface: returned `Ok(None)` is
reasonable assumption to have.

Consider this use case: drain the queue on drop by performing
app-specific cleanup of queued messages.

The obvious implementation would be:

```
impl Drop for MyReceiverWrapper {
    fn drop(&mut self) {
        while let Ok(Some(m)) self.try_next() {
            cleanup(m);
        }
    }
}
```

Without this change, I cannot even say for sure how this code need
to be implemented to avoid panicking. E. g. is `is_closed` enough
or some additional checks need to be performed?
2021-03-01 12:06:19 +09:00
Stiopa Koltsov
d15ad36c89 Document results of UnboundedReceiver::try_next 2021-03-01 11:25:14 +09:00