Skip to content

Commit

Permalink
Fix generic props structs (#2746)
Browse files Browse the repository at this point in the history
* fixup of generic props structs

* fix build errors from msrv 1.57 on time crate

* build wasm-bindgen-cli with cargo +stable
  • Loading branch information
WorldSEnder committed Jun 23, 2022
1 parent 75bb903 commit cda74c4
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 81 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
# for wasm-bindgen-cli, always use stable rust
with:
toolchain: stable
profile: minimal

- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
Expand All @@ -153,7 +159,7 @@ jobs:
cargo fetch
fi
VERSION=`cargo pkgid --frozen wasm-bindgen | cut -d ":" -f 3`
cargo install --version $VERSION wasm-bindgen-cli
cargo +stable install --version $VERSION wasm-bindgen-cli
- name: Run tests - yew
run: |
Expand Down
1 change: 1 addition & 0 deletions examples/password_strength/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
[dependencies]
yew = { path = "../../packages/yew", features = ["csr"] }
zxcvbn = "2.2.1"
time = "=0.3.9" # remove version pin with msrv 1.60
js-sys = "0.3.46"
web-sys = { version = "0.3", features = ["Event","EventTarget","InputEvent"] }
wasm-bindgen = "0.2"
Expand Down
3 changes: 2 additions & 1 deletion packages/yew-macro/src/props/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ impl ComponentProps {
.collect();

quote_spanned! {props_ty.span()=>
const __YEW_PROPS_CHECK: () = {
#[allow(clippy::no_effect)]
if false {
let _ = |#props_ident: #props_ty| {
#check_children
#check_props
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
error[E0412]: cannot find type `INVALID` in this scope
--> tests/function_component_attr/generic-props-fail.rs:25:19
|
25 | html! { <Comp<INVALID> /> };
| ^^^^^^^ not found in this scope

error[E0412]: cannot find type `INVALID` in this scope
--> tests/function_component_attr/generic-props-fail.rs:25:19
|
Expand All @@ -13,34 +7,6 @@ error[E0412]: cannot find type `INVALID` in this scope
25 | html! { <Comp<INVALID> /> };
| ^^^^^^^ not found in this scope

error[E0277]: the trait bound `Comp<MissingTypeBounds>: yew::BaseComponent` is not satisfied
--> tests/function_component_attr/generic-props-fail.rs:27:14
|
27 | html! { <Comp<MissingTypeBounds> /> };
| ^^^^ the trait `yew::BaseComponent` is not implemented for `Comp<MissingTypeBounds>`
|
= help: the following implementations were found:
<Comp<P> as yew::BaseComponent>
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0107]: missing generics for struct `Comp`
--> tests/function_component_attr/generic-props-fail.rs:30:14
|
30 | html! { <Comp /> };
| ^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `P`
--> tests/function_component_attr/generic-props-fail.rs:8:22
|
8 | #[function_component(Comp)]
| ^^^^
9 | fn comp<P>(_props: &P) -> Html
| -
help: add missing generic argument
|
30 | html! { <Comp<P> /> };
| ~~~~~~~

error[E0277]: the trait bound `AssertAllProps: HasProp<a, _>` is not satisfied
--> tests/function_component_attr/generic-props-fail.rs:22:14
|
Expand All @@ -55,6 +21,16 @@ note: required because of the requirements on the impl of `HasAllProps<Props, (_
= note: required because of the requirements on the impl of `AllPropsFor<PropsBuilder, (_,)>` for `AssertAllProps`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `Comp<MissingTypeBounds>: yew::BaseComponent` is not satisfied
--> tests/function_component_attr/generic-props-fail.rs:27:14
|
27 | html! { <Comp<MissingTypeBounds> /> };
| ^^^^ the trait `yew::BaseComponent` is not implemented for `Comp<MissingTypeBounds>`
|
= help: the following implementations were found:
<Comp<P> as yew::BaseComponent>
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: the function or associated item `new` exists for struct `VChild<Comp<MissingTypeBounds>>`, but its trait bounds were not satisfied
--> tests/function_component_attr/generic-props-fail.rs:27:14
|
Expand Down Expand Up @@ -83,3 +59,21 @@ note: required by a bound in `Comp`
11 | P: Properties + PartialEq,
| ^^^^^^^^^^ required by this bound in `Comp`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0107]: missing generics for struct `Comp`
--> tests/function_component_attr/generic-props-fail.rs:30:14
|
30 | html! { <Comp /> };
| ^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `P`
--> tests/function_component_attr/generic-props-fail.rs:8:22
|
8 | #[function_component(Comp)]
| ^^^^
9 | fn comp<P>(_props: &P) -> Html
| -
help: add missing generic argument
|
30 | html! { <Comp<P> /> };
| ~~~~~~~
74 changes: 37 additions & 37 deletions packages/yew-macro/tests/html_macro/component-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ error[E0425]: cannot find value `props` in this scope
69 | html! { <Child value=1 ..props /> };
| ^^^^^ not found in this scope

error[E0308]: mismatched types
--> tests/html_macro/component-fail.rs:53:22
|
53 | html! { <Child ..p1 ..p2 /> };
| ----- ^^^^^^^ expected struct `ChildProperties`, found struct `std::ops::Range`
| |
| expected due to this
|
= note: expected struct `ChildProperties`
found struct `std::ops::Range<_>`

error[E0609]: no field `value` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:69:20
|
Expand All @@ -295,43 +306,6 @@ error[E0609]: no field `r#type` on type `ChildProperties`
|
= note: available fields are: `string`, `int`

error[E0609]: no field `unknown` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:74:20
|
74 | html! { <Child unknown="unknown" /> };
| ^^^^^^^ unknown field
|
= note: available fields are: `string`, `int`

error[E0609]: no field `children` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:87:14
|
87 | html! { <Child>{ "Not allowed" }</Child> };
| ^^^^^ unknown field
|
= note: available fields are: `string`, `int`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0609]: no field `children` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:94:10
|
94 | <Child ..ChildProperties { string: "hello".to_owned(), int: 5 }>
| ^^^^^ unknown field
|
= note: available fields are: `string`, `int`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> tests/html_macro/component-fail.rs:53:22
|
53 | html! { <Child ..p1 ..p2 /> };
| ----- ^^^^^^^ expected struct `ChildProperties`, found struct `std::ops::Range`
| |
| expected due to this
|
= note: expected struct `ChildProperties`
found struct `std::ops::Range<_>`

error[E0599]: no method named `r#type` found for struct `ChildPropertiesBuilder` in the current scope
--> tests/html_macro/component-fail.rs:71:20
|
Expand All @@ -341,6 +315,14 @@ error[E0599]: no method named `r#type` found for struct `ChildPropertiesBuilder`
71 | html! { <Child type=0 /> };
| ^^^^ method not found in `ChildPropertiesBuilder`

error[E0609]: no field `unknown` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:74:20
|
74 | html! { <Child unknown="unknown" /> };
| ^^^^^^^ unknown field
|
= note: available fields are: `string`, `int`

error[E0599]: no method named `unknown` found for struct `ChildPropertiesBuilder` in the current scope
--> tests/html_macro/component-fail.rs:74:20
|
Expand Down Expand Up @@ -408,6 +390,15 @@ note: required because of the requirements on the impl of `HasAllProps<ChildProp
= note: required because of the requirements on the impl of `AllPropsFor<ChildPropertiesBuilder, (_,)>` for `AssertAllProps`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0609]: no field `children` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:87:14
|
87 | html! { <Child>{ "Not allowed" }</Child> };
| ^^^^^ unknown field
|
= note: available fields are: `string`, `int`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no method named `children` found for struct `ChildPropertiesBuilder` in the current scope
--> tests/html_macro/component-fail.rs:87:14
|
Expand All @@ -419,6 +410,15 @@ error[E0599]: no method named `children` found for struct `ChildPropertiesBuilde
|
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0609]: no field `children` on type `ChildProperties`
--> tests/html_macro/component-fail.rs:94:10
|
94 | <Child ..ChildProperties { string: "hello".to_owned(), int: 5 }>
| ^^^^^ unknown field
|
= note: available fields are: `string`, `int`
= note: this error originates in the macro `html` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `AssertAllProps: HasProp<_ChildContainerProperties::children, _>` is not satisfied
--> tests/html_macro/component-fail.rs:99:14
|
Expand Down
16 changes: 8 additions & 8 deletions packages/yew-macro/tests/props_macro/props-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ error[E0609]: no field `fail` on type `Props`
|
= note: available fields are: `a`

error[E0609]: no field `does_not_exist` on type `Props`
--> tests/props_macro/props-fail.rs:15:25
|
15 | yew::props!(Props { does_not_exist });
| ^^^^^^^^^^^^^^ unknown field
|
= note: available fields are: `a`

error[E0599]: no method named `fail` found for struct `PropsBuilder` in the current scope
--> tests/props_macro/props-fail.rs:10:31
|
Expand All @@ -47,6 +39,14 @@ error[E0599]: no method named `fail` found for struct `PropsBuilder` in the curr
10 | yew::props!(Props { a: 5, fail: 10 });
| ^^^^ method not found in `PropsBuilder`

error[E0609]: no field `does_not_exist` on type `Props`
--> tests/props_macro/props-fail.rs:15:25
|
15 | yew::props!(Props { does_not_exist });
| ^^^^^^^^^^^^^^ unknown field
|
= note: available fields are: `a`

error[E0599]: no method named `does_not_exist` found for struct `PropsBuilder` in the current scope
--> tests/props_macro/props-fail.rs:15:25
|
Expand Down
9 changes: 9 additions & 0 deletions packages/yew-macro/tests/props_macro/props-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,13 @@ fn pass_build_prop() {
::yew::props!(BuildProp { build: 5 });
}

#[derive(::yew::Properties, ::std::cmp::PartialEq)]
struct GenericProps<T: ::std::cmp::PartialEq> {
item: T,
}

fn pass_generic_props<T: ::std::cmp::PartialEq>(the_item: T) {
::yew::props!(GenericProps<T> { item: the_item });
}

fn main() {}

1 comment on commit cda74c4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: cda74c4 Previous: 75bb903 Ratio
yew-struct-keyed 01_run1k 257.76599999999996 197.445 1.31
yew-struct-keyed 02_replace1k 255.9495 210.9265 1.21
yew-struct-keyed 03_update10th1k_x16 459.083 381.963 1.20
yew-struct-keyed 04_select1k 63.2075 67.2205 0.94
yew-struct-keyed 05_swap1k 99.751 95.391 1.05
yew-struct-keyed 06_remove-one-1k 34.5025 34.159000000000006 1.01
yew-struct-keyed 07_create10k 4121.818499999999 3472.1585 1.19
yew-struct-keyed 08_create1k-after1k_x2 603.499 462.481 1.30
yew-struct-keyed 09_clear1k_x8 270.89 202.455 1.34
yew-struct-keyed 21_ready-memory 1.4694786071777344 1.4694786071777344 1
yew-struct-keyed 22_run-memory 1.6627883911132812 1.6719017028808594 0.99
yew-struct-keyed 23_update5-memory 1.6987571716308594 1.6990013122558594 1.00
yew-struct-keyed 24_run5-memory 1.7159767150878906 1.717529296875 1.00
yew-struct-keyed 25_run-clear-memory 1.3301353454589844 1.328399658203125 1.00
yew-struct-keyed 31_startup-ci 1736.3159999999998 1736.908 1.00
yew-struct-keyed 32_startup-bt 52.604 34.092 1.54
yew-struct-keyed 33_startup-mainthreadcost 322.724 256.5160000000001 1.26
yew-struct-keyed 34_startup-totalbytes 332.2724609375 332.2724609375 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.