chore: Stop rust-analyzer from marking all #[hook] macros as inactive… - #4206
Merged
Merged
Conversation
…_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.
|
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 🌎 |
Size ComparisonDetails
✅ None of the examples has changed their size significantly. |
Benchmark - SSRYew MasterDetails
Pull RequestDetails
|
WorldSEnder
approved these changes
Aug 24, 2026
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
This 1-line change adds
#[allow(rust_analyzer::inactive_code)]to the#[cfg(doctest)]copy of a hooked function that#[hook]emits alongside thereal implementation. A recent rust-analyzer change now diagnoses inactive
#[cfg]branches whose tokens trace back to user-written source, and sincethat 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 isstill diagnosed normally.
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