componet macro expasion has wierd errors when using progress as a prop name #3738
Answered
by
gbj
timon-schelling
asked this question in
Q&A
-
This component #[component]
fn Controls(progress: RwSignal<u32>) -> impl IntoView {
view! {
<input type="range" class="progress" min="0" max="100" value="0"/>
}
} produces compiler errors and I'm not sure if that's a bug, it is at least unexpected. error[E0308]: mismatched types
--> app/src/lib.rs:78:13
|
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| -------- ^^^^^^^^ expected `RwSignal<u32>`, found `progress`
| |
| arguments to this function are incorrect
|
= note: expected struct `leptos::prelude::RwSignal<u32>`
found struct `progress`
note: function defined here
--> app/src/lib.rs:78:4
|
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| ^^^^^^^^ -----------------------
error[E0308]: mismatched types
--> app/src/lib.rs:78:13
|
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| ^^^^^^^^ ------------- expected due to this
| |
| expected `RwSignal<u32>`, found `progress`
|
= note: expected struct `leptos::prelude::RwSignal<u32>`
found struct `progress`
error[E0308]: mismatched types
--> app/src/lib.rs:78:13
|
77 | #[component]
| ------------ this expression has type `(progress,)`
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| ^^^^^^^^ expected `(progress,)`, found `progress`
|
= note: expected tuple `(progress,)`
found struct `progress`
help: use a trailing comma to create a tuple with one element
|
78 | fn Controls((progress,): RwSignal<u32>) -> impl IntoView {
| + ++
error[E0308]: mismatched types
--> app/src/lib.rs:78:13
|
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| ^^^^^^^^ expected `(RwSignal<u32>,)`, found `progress`
|
= note: expected tuple `(leptos::prelude::RwSignal<u32>,)`
found struct `progress`
error[E0308]: mismatched types
--> app/src/lib.rs:78:13
|
77 | #[component]
| ------------ this expression has type `((leptos::prelude::RwSignal<u32>,),)`
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| ^^^^^^^^ expected `(RwSignal<u32>,)`, found `progress`
|
= note: expected tuple `(leptos::prelude::RwSignal<u32>,)`
found struct `progress`
error[E0609]: no field `0` on type `progress`
--> app/src/lib.rs:77:1
|
77 | #[component]
| ^^^^^^^^^^^^ unknown field
|
= note: this error originates in the derive macro `::leptos::typed_builder_macro::TypedBuilder` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0308]: mismatched types
--> app/src/lib.rs:78:13
|
78 | fn Controls(progress: RwSignal<u32>) -> impl IntoView {
| ^^^^^^^^ expected `RwSignal<u32>`, found `progress`
|
= note: expected struct `leptos::prelude::RwSignal<u32>`
found struct `progress` #[automatically_derived]
impl ControlsProps {
#[doc = "\n Create a builder for building `ControlsProps`.\n On the builder, call `.progress(...)` to set the values of the fields.\n Finally, call `.build()` to create the instance of `ControlsProps`.\n "]
#[allow(dead_code, clippy::default_trait_access)]
fn builder() -> ControlsPropsBuilder<((),)> {
ControlsPropsBuilder {
fields: ((),),
phantom: ::core::default::Default::default(),
}
}
}
#[must_use]
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, non_snake_case)]
struct ControlsPropsBuilder<TypedBuilderFields = ((),)> {
fields: TypedBuilderFields,
phantom: ::core::marker::PhantomData<()>,
}
#[automatically_derived]
impl<TypedBuilderFields> Clone for ControlsPropsBuilder<TypedBuilderFields>
where
TypedBuilderFields: Clone,
{
#[allow(clippy::default_trait_access)]
fn clone(&self) -> Self {
Self {
fields: self.fields.clone(),
phantom: ::core::default::Default::default(),
}
}
}
#[allow(dead_code, non_camel_case_types, missing_docs)]
#[automatically_derived]
impl ControlsPropsBuilder<((),)> {
#[doc = "**progress**: [`RwSignal<u32>`]"]
#[allow(clippy::used_underscore_binding, clippy::no_effect_underscore_binding)]
pub fn progress(self, progress: RwSignal<u32>) -> ControlsPropsBuilder<((RwSignal<u32>,),)> {
let progress = (progress,);
let ((),) = self.fields;
ControlsPropsBuilder {
fields: (progress,),
phantom: self.phantom,
}
}
}
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, non_snake_case)]
#[allow(clippy::exhaustive_enums)]
pub enum ControlsPropsBuilder_Error_Repeated_field_progress {}
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, missing_docs)]
#[automatically_derived]
impl ControlsPropsBuilder<((RwSignal<u32>,),)> {
#[deprecated(note = "Repeated field progress")]
#[doc = "**progress**: [`RwSignal<u32>`]"]
pub fn progress(
self,
_: ControlsPropsBuilder_Error_Repeated_field_progress,
) -> ControlsPropsBuilder<((RwSignal<u32>,),)> {
self
}
}
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, non_snake_case)]
#[allow(clippy::exhaustive_enums)]
pub enum ControlsPropsBuilder_Error_Missing_required_field_progress {}
#[doc(hidden)]
#[allow(dead_code, non_camel_case_types, missing_docs, clippy::panic)]
#[automatically_derived]
impl ControlsPropsBuilder<((),)> {
#[deprecated(note = "Missing required field progress")]
pub fn build(self, _: ControlsPropsBuilder_Error_Missing_required_field_progress) -> ! {
panic!()
}
}
#[allow(dead_code, non_camel_case_types, missing_docs)]
#[automatically_derived]
impl ControlsPropsBuilder<((RwSignal<u32>,),)> {
#[allow(
clippy::default_trait_access,
clippy::used_underscore_binding,
clippy::no_effect_underscore_binding
)]
pub fn build(self) -> ControlsProps {
let (progress,) = self.fields;
let progress = progress.0;
#[allow(deprecated)]
ControlsProps { progress }.into()
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
gbj
Mar 20, 2025
Replies: 1 comment 7 replies
-
Tried to reproduce with a fairly simple example but I don't get an error. Happy to try to help if you want to provide a more complete example. Here's what I had that was fine: use leptos::prelude::*;
#[component]
fn Controls(progress: RwSignal<u32>) -> impl IntoView {
view! {
<input type="range" class="progress" min="0" max="100" value="0"/>
}
}
#[component]
pub fn App() -> impl IntoView {
let foo = RwSignal::new(32u32);
view! {
<Controls progress=foo/>
}
} |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This appears to be what I would consider a somewhat odd Rust compiler behavior in which in-scope lowercased struct names can't be reused as function parameters?
Here's an example in plain, no-dependency, non-Leptos Rust, which also does not compile
I'd say I consider this fairly odd on the compiler's part, as lowercased struct names get a lint but not a compile error.
I have not encountered it before, otherwise. But I also think it's fairly rare to need to import event names from
ev
like this? Maybe I'm wrong.