From 7e12d6199a7d08fd13540a3134facb24facc05a4 Mon Sep 17 00:00:00 2001 From: Kaede Hoshikawa Date: Mon, 23 May 2022 22:06:46 +0900 Subject: [PATCH] Address reviews. --- .../hook_macro/use_prepared_state-fail.rs | 30 ++++++++++ .../hook_macro/use_prepared_state-fail.stderr | 55 +++++++++++++++++++ .../hook_macro/use_transitive_state-fail.rs | 26 +++++++++ .../use_transitive_state-fail.stderr | 39 +++++++++++++ packages/yew-macro/tests/hook_macro_test.rs | 7 +++ .../hooks/use_prepared_state/mod.rs | 10 ++-- .../hooks/use_transitive_state/mod.rs | 5 +- 7 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 packages/yew-macro/tests/hook_macro/use_prepared_state-fail.rs create mode 100644 packages/yew-macro/tests/hook_macro/use_prepared_state-fail.stderr create mode 100644 packages/yew-macro/tests/hook_macro/use_transitive_state-fail.rs create mode 100644 packages/yew-macro/tests/hook_macro/use_transitive_state-fail.stderr create mode 100644 packages/yew-macro/tests/hook_macro_test.rs diff --git a/packages/yew-macro/tests/hook_macro/use_prepared_state-fail.rs b/packages/yew-macro/tests/hook_macro/use_prepared_state-fail.rs new file mode 100644 index 00000000000..e12ee98fe64 --- /dev/null +++ b/packages/yew-macro/tests/hook_macro/use_prepared_state-fail.rs @@ -0,0 +1,30 @@ +use yew::prelude::*; +use yew_macro::{use_prepared_state_with_closure, use_prepared_state_without_closure}; + +#[function_component] +fn Comp() -> HtmlResult { + use_prepared_state_with_closure!(123)?; + + use_prepared_state_with_closure!(|_| { todo!() }, 123)?; + + use_prepared_state_with_closure!(|_| -> u32 { todo!() })?; + + use_prepared_state_with_closure!(async |_| -> u32 { todo!() })?; + + Ok(Html::default()) +} + +#[function_component] +fn Comp2() -> HtmlResult { + use_prepared_state_without_closure!(123)?; + + use_prepared_state_without_closure!(|_| { todo!() }, 123)?; + + use_prepared_state_without_closure!(|_| -> u32 { todo!() })?; + + use_prepared_state_without_closure!(async |_| -> u32 { todo!() })?; + + Ok(Html::default()) +} + +fn main() {} diff --git a/packages/yew-macro/tests/hook_macro/use_prepared_state-fail.stderr b/packages/yew-macro/tests/hook_macro/use_prepared_state-fail.stderr new file mode 100644 index 00000000000..6c0cffa5740 --- /dev/null +++ b/packages/yew-macro/tests/hook_macro/use_prepared_state-fail.stderr @@ -0,0 +1,55 @@ +error: expected `|` + --> tests/hook_macro/use_prepared_state-fail.rs:6:38 + | +6 | use_prepared_state_with_closure!(123)?; + | ^^^ + +error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle. + --> tests/hook_macro/use_prepared_state-fail.rs:8:38 + | +8 | use_prepared_state_with_closure!(|_| { todo!() }, 123)?; + | ^^^^^^^^^^^^^^^ + +error: expected `,` + --> tests/hook_macro/use_prepared_state-fail.rs:10:5 + | +10 | use_prepared_state_with_closure!(|_| -> u32 { todo!() })?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `use_prepared_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `,` + --> tests/hook_macro/use_prepared_state-fail.rs:12:5 + | +12 | use_prepared_state_with_closure!(async |_| -> u32 { todo!() })?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `use_prepared_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `|` + --> tests/hook_macro/use_prepared_state-fail.rs:19:41 + | +19 | use_prepared_state_without_closure!(123)?; + | ^^^ + +error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle. + --> tests/hook_macro/use_prepared_state-fail.rs:21:41 + | +21 | use_prepared_state_without_closure!(|_| { todo!() }, 123)?; + | ^^^^^^^^^^^^^^^ + +error: expected `,` + --> tests/hook_macro/use_prepared_state-fail.rs:23:5 + | +23 | use_prepared_state_without_closure!(|_| -> u32 { todo!() })?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `use_prepared_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `,` + --> tests/hook_macro/use_prepared_state-fail.rs:25:5 + | +25 | use_prepared_state_without_closure!(async |_| -> u32 { todo!() })?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `use_prepared_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/packages/yew-macro/tests/hook_macro/use_transitive_state-fail.rs b/packages/yew-macro/tests/hook_macro/use_transitive_state-fail.rs new file mode 100644 index 00000000000..113b0404ed3 --- /dev/null +++ b/packages/yew-macro/tests/hook_macro/use_transitive_state-fail.rs @@ -0,0 +1,26 @@ +use yew::prelude::*; +use yew_macro::{use_transitive_state_with_closure, use_transitive_state_without_closure}; + +#[function_component] +fn Comp() -> HtmlResult { + use_transitive_state_with_closure!(123)?; + + use_transitive_state_with_closure!(|_| { todo!() }, 123)?; + + use_transitive_state_with_closure!(|_| -> u32 { todo!() })?; + + Ok(Html::default()) +} + +#[function_component] +fn Comp2() -> HtmlResult { + use_transitive_state_without_closure!(123)?; + + use_transitive_state_without_closure!(|_| { todo!() }, 123)?; + + use_transitive_state_without_closure!(|_| -> u32 { todo!() })?; + + Ok(Html::default()) +} + +fn main() {} diff --git a/packages/yew-macro/tests/hook_macro/use_transitive_state-fail.stderr b/packages/yew-macro/tests/hook_macro/use_transitive_state-fail.stderr new file mode 100644 index 00000000000..7c3a14eddce --- /dev/null +++ b/packages/yew-macro/tests/hook_macro/use_transitive_state-fail.stderr @@ -0,0 +1,39 @@ +error: expected `|` + --> tests/hook_macro/use_transitive_state-fail.rs:6:40 + | +6 | use_transitive_state_with_closure!(123)?; + | ^^^ + +error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle. + --> tests/hook_macro/use_transitive_state-fail.rs:8:40 + | +8 | use_transitive_state_with_closure!(|_| { todo!() }, 123)?; + | ^^^^^^^^^^^^^^^ + +error: expected `,` + --> tests/hook_macro/use_transitive_state-fail.rs:10:5 + | +10 | use_transitive_state_with_closure!(|_| -> u32 { todo!() })?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `use_transitive_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: expected `|` + --> tests/hook_macro/use_transitive_state-fail.rs:17:43 + | +17 | use_transitive_state_without_closure!(123)?; + | ^^^ + +error: You must specify a return type for this closure. This is used when the closure is omitted from the client side rendering bundle. + --> tests/hook_macro/use_transitive_state-fail.rs:19:43 + | +19 | use_transitive_state_without_closure!(|_| { todo!() }, 123)?; + | ^^^^^^^^^^^^^^^ + +error: expected `,` + --> tests/hook_macro/use_transitive_state-fail.rs:21:5 + | +21 | use_transitive_state_without_closure!(|_| -> u32 { todo!() })?; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `use_transitive_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/packages/yew-macro/tests/hook_macro_test.rs b/packages/yew-macro/tests/hook_macro_test.rs new file mode 100644 index 00000000000..d860ad28821 --- /dev/null +++ b/packages/yew-macro/tests/hook_macro_test.rs @@ -0,0 +1,7 @@ +#[allow(dead_code)] +#[rustversion::attr(stable(1.56), test)] +fn tests() { + let t = trybuild::TestCases::new(); + t.pass("tests/hook_macro/*-pass.rs"); + t.compile_fail("tests/hook_macro/*-fail.rs"); +} diff --git a/packages/yew/src/functional/hooks/use_prepared_state/mod.rs b/packages/yew/src/functional/hooks/use_prepared_state/mod.rs index 20e3fd8e39e..c54f9de9f66 100644 --- a/packages/yew/src/functional/hooks/use_prepared_state/mod.rs +++ b/packages/yew/src/functional/hooks/use_prepared_state/mod.rs @@ -32,11 +32,12 @@ pub use feat_ssr::*; /// It has the following signature: /// /// ``` -/// # use yew::prelude::*; /// # use serde::de::DeserializeOwned; /// # use serde::Serialize; /// # use std::rc::Rc; -/// # use yew::suspense::SuspensionResult; +/// use yew::prelude::*; +/// use yew::suspense::SuspensionResult; +/// /// #[hook] /// pub fn use_prepared_state(f: F, deps: D) -> SuspensionResult>> /// where @@ -53,12 +54,13 @@ pub use feat_ssr::*; /// When accepting an async closure, it has the following signature: /// /// ``` -/// # use yew::prelude::*; /// # use serde::de::DeserializeOwned; /// # use serde::Serialize; -/// # use yew::suspense::SuspensionResult; /// # use std::rc::Rc; /// # use std::future::Future; +/// use yew::prelude::*; +/// use yew::suspense::SuspensionResult; +/// /// #[hook] /// pub fn use_prepared_state( /// f: F, diff --git a/packages/yew/src/functional/hooks/use_transitive_state/mod.rs b/packages/yew/src/functional/hooks/use_transitive_state/mod.rs index 0b2f3006158..f8ef487b5cb 100644 --- a/packages/yew/src/functional/hooks/use_transitive_state/mod.rs +++ b/packages/yew/src/functional/hooks/use_transitive_state/mod.rs @@ -32,11 +32,12 @@ pub use feat_ssr::*; /// It has the following function signature: /// /// ``` -/// # use yew::prelude::*; /// # use serde::de::DeserializeOwned; /// # use serde::Serialize; /// # use std::rc::Rc; -/// # use yew::suspense::SuspensionResult; +/// use yew::prelude::*; +/// use yew::suspense::SuspensionResult; +/// /// #[hook] /// pub fn use_transitive_state(f: F, deps: D) -> SuspensionResult>> /// where