Skip to content

Commit f8dc13d

Browse files
Add tests asserting the function-like semantics of join!()
1 parent e277a98 commit f8dc13d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

library/core/tests/future.rs

+34
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,40 @@ fn test_join() {
6464
});
6565
}
6666

67+
/// Tests that `join!(…)` behaves "like a function": evaluating its arguments
68+
/// before applying any of its own logic.
69+
///
70+
/// _e.g._, `join!(async_fn(&borrowed), …)` does not consume `borrowed`;
71+
/// and `join!(opt_fut?, …)` does let that `?` refer to the callsite scope.
72+
mod test_join_function_like_value_arg_semantics {
73+
use super::*;
74+
75+
async fn async_fn(_: impl Sized) {}
76+
77+
// no need to _run_ this test, just to compile it.
78+
fn _join_does_not_unnecessarily_move_mentioned_bindings() {
79+
let not_copy = vec![()];
80+
let _ = join!(async_fn(&not_copy)); // should not move `not_copy`
81+
let _ = not_copy; // OK
82+
}
83+
84+
#[test]
85+
fn join_lets_control_flow_effects_such_as_try_flow_through() {
86+
let maybe_fut = None;
87+
if false {
88+
*&mut { maybe_fut } = Some(async {});
89+
loop {}
90+
}
91+
assert!(Option::is_none(&try { join!(maybe_fut?, async { unreachable!() }) }));
92+
}
93+
94+
#[test]
95+
fn join_is_able_to_handle_temporaries() {
96+
let _ = join!(async_fn(&String::from("temporary")));
97+
let () = block_on(join!(async_fn(&String::from("temporary"))));
98+
}
99+
}
100+
67101
fn block_on(fut: impl Future) {
68102
struct Waker;
69103
impl Wake for Waker {

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#![feature(str_internals)]
5050
#![feature(test)]
5151
#![feature(trusted_len)]
52+
#![feature(try_blocks)]
5253
#![feature(try_trait_v2)]
5354
#![feature(slice_internals)]
5455
#![feature(slice_partition_dedup)]

0 commit comments

Comments
 (0)