leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
16.41k stars 656 forks source link

[0.7] `#[component]` attribute doesn't work with `clippy::must_use_candidate` #3172

Open zroug opened 4 weeks ago

zroug commented 4 weeks ago

Describe the bug

Leptos 0.7.0-rc0 #[component] attribute is incompatible with the clippy::must_use_candidate lint.

Leptos Dependencies

leptos = { version = "0.7.0-rc0", features = ["nightly", "experimental-islands"] }
leptos_axum = { version = "0.7.0-rc0", optional = true }
leptos_router = { version = "0.7.0-rc0", features = ["nightly"] }

To Reproduce Steps to reproduce the behavior:

  1. Enable the clippy::must_use_candidate lint.
  2. Create a component with the #[component] attribute.

Expected behavior There should be no Clippy warning. There are at least three ways to achieve this:

  1. Add the #[must_use] attribute to the component function. (My preferred option.)
  2. Suppress the lint by adding #[allow(clippy::must_use_candidate)] to the component function.
  3. Do not prevent the warning, but pass the #[must_use] attribute to the generated component function if the user adds the attribute manually.
gbj commented 4 weeks ago

A PR for Option 3 is welcome (passing through a user-provided attribute), but it probably shouldn't be special-cased; the component macro should likely just pass through most or all attributes to the __NameOfComponent function that is used to improve rust-analyzer support.