Fix too restrictive Clone bounds in props with generics#5451
Fix too restrictive Clone bounds in props with generics#5451ealmloff merged 3 commits intoDioxusLabs:mainfrom
Conversation
|
This looks like a subset of rust-lang/rust#26925 (comment). Unfortunately I don't think there is a general solution for this that handles all of these cases:
|
|
Indeed, Note that using a prop that doesn't implement Clone still gives the same error. For example: #[component]
pub fn Table<D: AsTable + PartialEq + 'static>(data: D) -> Element {
...
}still emits: So omitting those bounds from the generated Clone impl doesn't weaken any guarantees. This is similar to this PR: #3968 but applied to the I had a look at the failing test, but can't trigger that error locally, although I am on Windows. |
ealmloff
left a comment
There was a problem hiding this comment.
Thanks! this is different from the general perfect derive case since we know both already implement clone (via clone bound on props and owners always being clone) so my comment wasn't an issue. added some tests to make sure we don't require extra generic bounds in the future
Currently, if you use a generic in props, the generic must be bounded by
Cloneeven if it doesn't need to. For example:fails with:
But
Ddoes not need to beClonebecause I'm using it asReadSignal<D>, which has a Clone impl that does not requireDto be Clone. This is caused by the generatedTablePropsWithOwner<D>struct using#[derive(Clone)], which generates a Clone impl where all generics are bounded byClone(an unfortunate limitation of the standard derive).This PR replaces
#[derive(Clone)]with a Clone impl that doesn't add those bounds, fixing the above error.