fix: add #[must_use] to Hook trait to warn on invalid placement#4052
Open
Madoshakalaka wants to merge 1 commit intomasterfrom
Open
fix: add #[must_use] to Hook trait to warn on invalid placement#4052Madoshakalaka wants to merge 1 commit intomasterfrom
Madoshakalaka wants to merge 1 commit intomasterfrom
Conversation
Benchmark - coreYew MasterPull Request |
|
Visit the preview URL for this PR (updated for commit 119a329): https://yew-rs-api--pr4052-hook-must-use-we8m29ma.web.app (expires Fri, 13 Mar 2026 13:47:57 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
Member
Author
|
@gjgiezeman thanks for the report. |
Member
Author
|
@kirillsemyonkin I tried your suggestion of adding an invisible parameter but couldn't quite make it work. Then I realized adding a |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes the silent failure described in #4045: hooks called from plain functions (without
#[hook]or#[component]) return animpl Hookvalue that gets dropped without ever executing. This is especially harmful for unit-returning hooks likeuse_effect_with, where there is no type mismatch to catch the mistake.Adding
#[must_use]to theHooktrait causes the compiler to emit a warning when a hook's return value is unused, with a message directing users to annotate their function with#[hook]or#[component].Hooks inside
#[hook]or#[component]are unaffected because the macro rewrites calls toHook::run(...), which consumes the value.Checklist