File tree Expand file tree Collapse file tree
yew-macro/tests/hook_attr Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #![ deny( unused_must_use) ]
2+
3+ use yew:: prelude:: * ;
4+
5+ fn not_a_hook ( ) {
6+ use_effect_with ( ( ) , |_| { } ) ;
7+ }
8+
9+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: unused implementer of `Hook` that must be used
2+ --> tests/hook_attr/hook-must-use-fail.rs:6:5
3+ |
4+ 6 | use_effect_with((), |_| {});
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+ |
7+ = note: hooks do nothing unless called inside a `#[hook]` or `#[component]` function
8+ note: the lint level is defined here
9+ --> tests/hook_attr/hook-must-use-fail.rs:1:9
10+ |
11+ 1 | #![deny(unused_must_use)]
12+ | ^^^^^^^^^^^^^^^
Original file line number Diff line number Diff line change 1+ #![ deny( unused_must_use) ]
2+
3+ use yew:: prelude:: * ;
4+
5+ #[ hook]
6+ fn use_my_effect ( ) {
7+ use_effect_with ( ( ) , |_| { } ) ;
8+ }
9+
10+ #[ component]
11+ fn Comp ( ) -> Html {
12+ use_effect_with ( ( ) , |_| { } ) ;
13+ use_my_effect ( ) ;
14+ html ! { }
15+ }
16+
17+ fn main ( ) { }
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ use crate::functional::HookContext;
2828/// Hooks are defined via the [`#[hook]`](crate::functional::hook) macro. It provides rewrites to
2929/// hook invocations and ensures that hooks can only be called at the top-level of a function
3030/// component or a hook. Please refer to its documentation on how to implement hooks.
31+ #[ must_use = "hooks do nothing unless called inside a `#[hook]` or `#[component]` function" ]
3132pub trait Hook {
3233 /// The return type when a hook is run.
3334 type Output ;
You can’t perform that action at this time.
0 commit comments