Skip to content

Commit

Permalink
Ensure cloned types impl ImplicitClone
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Nov 9, 2023
1 parent ff74446 commit 45682cc
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 35 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


[dev-dependencies]
yew = { version = "0.21" }
trybuild = "1"
rustversion = "1"
yew = { version = "0.21" }
implicit-clone = "0.4.6"
trybuild = "1"
rustversion = "1"
4 changes: 3 additions & 1 deletion src/autoprops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ impl Autoprops {
syn::FnArg::Typed(syn::PatType { pat, ty, .. })
if !matches!(**ty, syn::Type::Reference(_)) =>
{
Some(quote! { let #pat = ::std::clone::Clone::clone(#pat); })
Some(quote! {
let #pat = ::implicit_clone::ImplicitClone::implicit_clone(#pat);
})
}
_ => None,
})
Expand Down
3 changes: 3 additions & 0 deletions tests/function_component_attr/autoprops-fail.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use yew::prelude::*;
use yew::html::ImplicitClone;
use yew_autoprops::*;

#[autoprops]
Expand Down Expand Up @@ -47,6 +48,8 @@ fn TypeIsNotClone(stuff: NotClonable) -> Html {
#[derive(Clone)]
struct NotPartialEq(u32);

impl ImplicitClone for NotPartialEq {}

#[autoprops]
#[function_component]
fn TypeIsNotPartialEq(stuff: NotPartialEq) -> Html {
Expand Down
56 changes: 28 additions & 28 deletions tests/function_component_attr/autoprops-fail.stderr
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
error: function components can't accept a receiver
--> tests/function_component_attr/autoprops-fail.rs:6:23
--> tests/function_component_attr/autoprops-fail.rs:7:23
|
6 | fn CantAcceptReceiver(&self, b: bool) -> Html {
7 | fn CantAcceptReceiver(&self, b: bool) -> Html {
| ^^^^^

error: could not find #[function_component] attribute in function declaration (#[autoprops] must be placed *before* #[function_component])
--> tests/function_component_attr/autoprops-fail.rs:13:1
--> tests/function_component_attr/autoprops-fail.rs:14:1
|
13 | fn not_a_function_component(b: bool) -> Html {
14 | fn not_a_function_component(b: bool) -> Html {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: expected a reference to a `Properties` type (try: `&bool`)
--> tests/function_component_attr/autoprops-fail.rs:21:25
--> tests/function_component_attr/autoprops-fail.rs:22:25
|
21 | fn wrong_attrs_order(b: bool) -> Html {
22 | fn wrong_attrs_order(b: bool) -> Html {
| ^^^^

error: expected identifier, found keyword `let`
--> tests/function_component_attr/autoprops-fail.rs:28:22
--> tests/function_component_attr/autoprops-fail.rs:29:22
|
28 | #[function_component(let)]
29 | #[function_component(let)]
| ^^^

error: cannot use `_` as field name
--> tests/function_component_attr/autoprops-fail.rs:61:21
--> tests/function_component_attr/autoprops-fail.rs:64:21
|
61 | fn InvalidFieldName(_: u32) -> Html {
64 | fn InvalidFieldName(_: u32) -> Html {
| ^

error[E0412]: cannot find type `CompPrivateTest` in this scope
--> tests/function_component_attr/autoprops-fail.rs:83:22
--> tests/function_component_attr/autoprops-fail.rs:86:22
|
83 | let _ = html! { <CompPrivateTest /> };
86 | let _ = html! { <CompPrivateTest /> };
| ^^^^^^^^^^^^^^^ not found in this scope
|
note: struct `crate::private_module::CompPrivateTest` exists but is inaccessible
--> tests/function_component_attr/autoprops-fail.rs:69:5
--> tests/function_component_attr/autoprops-fail.rs:72:5
|
69 | #[::yew::function_component(CompPrivateTest)]
72 | #[::yew::function_component(CompPrivateTest)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not accessible
= note: this error originates in the attribute macro `::yew::function_component` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `NotClonable: Clone` is not satisfied
--> tests/function_component_attr/autoprops-fail.rs:40:19
error[E0277]: the trait bound `NotClonable: ImplicitClone` is not satisfied
--> tests/function_component_attr/autoprops-fail.rs:41:19
|
38 | #[autoprops]
39 | #[autoprops]
| ------------ required by a bound introduced by this call
39 | #[function_component]
40 | fn TypeIsNotClone(stuff: NotClonable) -> Html {
| ^^^^^ the trait `Clone` is not implemented for `NotClonable`
40 | #[function_component]
41 | fn TypeIsNotClone(stuff: NotClonable) -> Html {
| ^^^^^ expected an implementor of trait `ImplicitClone`
|
help: consider annotating `NotClonable` with `#[derive(Clone)]`
|
36 | #[derive(Clone)]
help: consider borrowing here
|
41 | fn TypeIsNotClone(&stuff: NotClonable) -> Html {
| +

error[E0369]: binary operation `==` cannot be applied to type `NotPartialEq`
--> tests/function_component_attr/autoprops-fail.rs:52:30
--> tests/function_component_attr/autoprops-fail.rs:55:30
|
52 | fn TypeIsNotPartialEq(stuff: NotPartialEq) -> Html {
55 | fn TypeIsNotPartialEq(stuff: NotPartialEq) -> Html {
| ^^^^^^^^^^^^
|
note: an implementation of `PartialEq<_>` might be missing for `NotPartialEq`
--> tests/function_component_attr/autoprops-fail.rs:48:1
--> tests/function_component_attr/autoprops-fail.rs:49:1
|
48 | struct NotPartialEq(u32);
49 | struct NotPartialEq(u32);
| ^^^^^^^^^^^^^^^^^^^ must implement `PartialEq<_>`
help: consider annotating `NotPartialEq` with `#[derive(PartialEq)]`
|
48 | #[derive(PartialEq)]
49 | #[derive(PartialEq)]
|
2 changes: 1 addition & 1 deletion tests/function_component_attr/autoprops-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn comp_single_generic<T>() -> ::yew::Html {
#[::yew::function_component(CompGenerics)]
fn comp_generics<T1, T2>(b: T1, a: &T2) -> ::yew::Html
where
T1: ::std::cmp::PartialEq + ::std::clone::Clone,
T1: ::std::cmp::PartialEq + ::implicit_clone::ImplicitClone,
T2: ::std::cmp::PartialEq,
{
let _: T1 = b;
Expand Down

0 comments on commit 45682cc

Please sign in to comment.