Skip to content

Commit 4a28de4

Browse files
Only rewrite async closure for rust version before 1.85.0 (#3831)
* use_prepared_state with unit type is unlikely usage --------- Co-authored-by: Matt "Siyuan" Yan <mattsy1999@gmail.com>
1 parent e5b2cf3 commit 4a28de4

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

packages/yew-macro/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ quote = "1"
2222
syn = { version = "2", features = ["full", "extra-traits", "visit-mut"] }
2323
once_cell = "1"
2424
prettyplease = "0.2"
25+
rustversion = "1"
2526

2627
# testing
2728
[dev-dependencies]
28-
rustversion = "1"
2929
trybuild = "1"
3030
yew = { path = "../yew" }
3131

packages/yew-macro/src/use_prepared_state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl Parse for PreparedState {
5858
}
5959

6060
impl PreparedState {
61-
// Async closure is not stable, so we rewrite it to closure + async block
62-
#[cfg(not(nightly_yew))]
61+
// Async closure was not stable, so we rewrite it to closure + async block
62+
#[rustversion::before(1.85)]
6363
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
6464
use proc_macro2::Span;
6565
use syn::parse_quote;
@@ -95,7 +95,7 @@ impl PreparedState {
9595
closure
9696
}
9797

98-
#[cfg(nightly_yew)]
98+
#[rustversion::since(1.85)]
9999
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
100100
self.closure.clone()
101101
}

packages/yew/src/functional/hooks/use_prepared_state/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use feat_ssr::*;
4747
/// # { todo!() }
4848
/// ```
4949
///
50-
/// The first argument can also be an [async closure](https://github.com/rust-lang/rust/issues/62290).
50+
/// The first argument can also be an async closure
5151
///
5252
/// `let state = use_prepared_state!(async |deps| -> ReturnType { ... }, deps)?;`
5353
///
@@ -85,10 +85,6 @@ pub use feat_ssr::*;
8585
/// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This
8686
/// type is used during client side rendering to deserialize the state prepared on the server
8787
/// side.
88-
///
89-
/// Whilst async closure is an unstable feature, the procedural macro will rewrite this to a
90-
/// closure that returns an async block automatically. You can use this hook with async closure
91-
/// in stable Rust.
9288
pub use use_prepared_state_macro as use_prepared_state;
9389
// With SSR.
9490
#[doc(hidden)]

tools/benchmark-ssr/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ async fn bench_concurrent_task() -> Duration {
141141

142142
#[function_component]
143143
fn Comp() -> HtmlResult {
144-
let _state = use_prepared_state!((), async move |_| -> () {
144+
let _state = use_prepared_state!((), async move |_| -> usize {
145145
sleep(Duration::from_secs(1)).await;
146+
42
146147
})?;
147148

148149
Ok(Html::default())

0 commit comments

Comments
 (0)