Skip to content

chore: Stop rust-analyzer from marking all #[hook] macros as inactive… - #4206

Merged
WorldSEnder merged 1 commit into
yewstack:masterfrom
sunjay:sunjay/fix-inactive-code
Aug 24, 2026
Merged

WorldSEnder merged 1 commit into
yewstack:masterfrom
sunjay:sunjay/fix-inactive-code

Conversation

@sunjay

@sunjay sunjay commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

This 1-line change adds #[allow(rust_analyzer::inactive_code)] to the
#[cfg(doctest)] copy of a hooked function that #[hook] emits alongside the
real implementation. A recent rust-analyzer change now diagnoses inactive
#[cfg] branches whose tokens trace back to user-written source, and since
that doctest-only copy reuses the original function spans verbatim, it makes
rust-analyzer grey out the hook's real body in the editor. The allow is scoped
to that inert copy only, so genuine #[cfg] usage inside a hook's own body is
still diagnosed normally.

Screenshot 2026-08-23 at 11 10 04 PM

This was tested by patching my local project. The inactive code warning goes away and the code is no longer greyed out.

For anyone experiencing this, a workaround in the meantime before this is merged and released is to add this to your lib.rs or main.rs:

#![allow(rust_analyzer::inactive_code)]

Checklist

  • I have reviewed my own code
  • I have added tests (N/A -- not testable because this is a rust-analyzer issue)

…_code

This change adds `#[allow(rust_analyzer::inactive_code)]` to the
`#[cfg(doctest)]` copy of a hooked function that `#[hook]` emits alongside the
real implementation.  A recent rust-analyzer change now diagnoses inactive
`#[cfg]` branches whose tokens trace back to user-written source, and since
that doctest-only copy reuses the original function spans verbatim, it makes
rust-analyzer grey out the hook's real body in the editor. The allow is scoped
to that inert copy only, so genuine `#[cfg]` usage inside a hook's own body is
still diagnosed normally.
@github-actions

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 8cd80ce):

https://yew-rs-api--pr4206-sunjay-fix-inactive-8cvskq0f.web.app

(expires Mon, 31 Aug 2026 04:34:21 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions

Copy link
Copy Markdown

Size Comparison

Details
examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 100.212 100.212 0 0.000%
boids 164.948 164.948 0 0.000%
communication_child_to_parent 93.720 93.720 0 0.000%
communication_grandchild_with_grandparent 106.001 106.001 0 0.000%
communication_grandparent_to_grandchild 102.322 102.322 0 0.000%
communication_parent_to_child 91.106 91.106 0 0.000%
contexts 106.311 106.311 0 0.000%
counter 86.277 86.277 0 0.000%
counter_functional 88.310 88.310 0 0.000%
dyn_create_destroy_apps 90.176 90.176 0 0.000%
file_upload 98.586 98.586 0 0.000%
function_delayed_input 94.622 94.622 0 0.000%
function_memory_game 168.592 168.592 0 0.000%
function_router 400.319 400.319 0 0.000%
function_todomvc 164.993 164.993 0 0.000%
futures 235.955 235.955 0 0.000%
game_of_life 100.629 100.629 0 0.000%
immutable 258.128 258.128 0 0.000%
inner_html 80.787 80.787 0 0.000%
js_callback 109.765 109.765 0 0.000%
keyed_list 176.351 176.351 0 0.000%
mount_point 84.200 84.200 0 0.000%
nested_list 112.724 112.724 0 0.000%
node_refs 91.782 91.782 0 0.000%
password_strength 1765.665 1765.665 0 0.000%
portals 93.605 93.605 0 0.000%
router 366.554 366.554 0 0.000%
suspense 113.940 113.940 0 0.000%
timer 88.523 88.523 0 0.000%
timer_functional 99.426 99.426 0 0.000%
todomvc 141.992 141.992 0 0.000%
two_apps 86.182 86.182 0 0.000%
web_worker_fib 136.497 136.497 0 0.000%
web_worker_prime 186.593 186.593 0 0.000%
webgl 82.935 82.935 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions

Copy link
Copy Markdown

Benchmark - SSR

Yew Master

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 302.559 303.100 302.765 0.167
Hello World 10 468.123 498.024 472.502 9.093
Function Router 10 30068.109 30550.721 30282.152 196.416
Concurrent Task 10 1005.634 1008.155 1007.276 0.785
Many Providers 10 1002.675 1050.175 1015.467 14.111

Pull Request

Details
Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 302.398 302.778 302.613 0.106
Hello World 10 465.774 489.477 469.259 7.196
Function Router 10 29807.880 30249.125 30037.170 136.614
Concurrent Task 10 1006.442 1008.037 1007.263 0.544
Many Providers 10 1010.056 1038.472 1025.594 10.801

@WorldSEnder WorldSEnder added ergonomics A-yew-macro Area: The yew-macro crate labels Aug 24, 2026

@WorldSEnder WorldSEnder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WorldSEnder
WorldSEnder merged commit 4cdec2d into yewstack:master Aug 24, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-yew-macro Area: The yew-macro crate ergonomics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants