File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,40 @@ fn test_join() {
64
64
} ) ;
65
65
}
66
66
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
+
67
101
fn block_on ( fut : impl Future ) {
68
102
struct Waker ;
69
103
impl Wake for Waker {
Original file line number Diff line number Diff line change 49
49
#![ feature( str_internals) ]
50
50
#![ feature( test) ]
51
51
#![ feature( trusted_len) ]
52
+ #![ feature( try_blocks) ]
52
53
#![ feature( try_trait_v2) ]
53
54
#![ feature( slice_internals) ]
54
55
#![ feature( slice_partition_dedup) ]
You can’t perform that action at this time.
0 commit comments