DioxusLabs / DioxusLabs/dioxus
#[component] macro complains about unnecessary phantom with generics
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
There's a bug in the `component` macro expansion causing issues with unused generics on the props struct even though the generic is used within the body of the component.
```rust
#[component]
fn VersionSelectItem(to: Route) -> Element {
let full_version = R::full_version();
let short_version = R::short_version();
rsx! {
Link { to,
div { class: "flex flex-row items-center hover:bg-gray-100 dark:hover:bg-ghdarkmetal py-2 gap-2 px-2",
span { class: "row-span-3", "⭐️" }
div { class: "flex flex-col",
span { class: "text-gray-700 dark:text-gray-100 font-semibold",
"Version {short_version}"
}
span { class: "row-span-2 col-span-2", "{full_version}" }
}
div { class: "flex-1" }
span { "✅" }
}
}
}
}
```
Error:
```
14:06:02 [cargo] error[E0392]: type parameter `R` is never used
--> src/components/learn.rs:106:22
|
106 | fn VersionSelectItem(to: Route) -> Element {
| ^ unused type parameter
|
= help: consider removing `R`, referring to it in a field, or using a marker such as `PhantomData`
14:06:02 [cargo] error[E0283]: type annotations needed
--> src/components/learn.rs:106:4
|
106 | fn VersionSelectItem(to: Route) -> Element {
| ^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `R` declared on the struct `VersionSelectItemProps`
|
= note: cannot satisfy `_: docs::AnyBookRoute`
= help: the following types implement trait `docs::AnyBookRoute`:
router_05::BookRoute
router_06::BookRoute
note: required by a bound in `VersionSelectItemProps`
--> src/components/learn.rs:106:25
|
106 | fn VersionSelectItem(to: Route) -> Element {
| ^^^^^^^^^^^^ required by this bound in `VersionSelectItemProps`
14:06:02 [cargo] error[E0283]: type annotations needed
--> src/components/learn.rs:105:1
|
105 | #[component]
| ^ cannot infer type
|
= note: cannot satisfy `_: docs::AnyBookRoute`
= help: the following types implement trait `docs::AnyBookRoute`:
router_05::BookRoute
router_06::BookRoute
note: required by a bound in `VersionSelectItemProps`
--> src/components/learn.rs:106:25
|
106 | fn VersionSelectItem(to: Route) -> Element {
| ^^^^^^^^^^^^ required by this bound in `VersionSelectItemProps`
= note: this error originates in the derive macro `Clone` which comes from the expansion of the attribute macro `component` (in Nightly builds, run with -Z macro-backtrace for more info)
```
**Environment:**
- Dioxus version: `main`
- Rust version:
- OS info:
- App platform:
**Questionnaire**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.