Skip to content

Commit f92053d

Browse files
committed
Merge branch 'master' into yew-link
2 parents 2c61622 + 195730d commit f92053d

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
| ^^^^^^^^^^^^^^^
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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() {}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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"]
3132
pub trait Hook {
3233
/// The return type when a hook is run.
3334
type Output;

0 commit comments

Comments
 (0)