Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generic props structs #2746

Merged
merged 3 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>`
Comment on lines +27 to +28
Copy link
Member

Choose a reason for hiding this comment

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

Span should reference MissingTypeBounds here

|
= 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
Copy link
Member

Choose a reason for hiding this comment

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

This is a bad span. Can we do better?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree in principle, but don't want to block this PR with this. The errors were like this before, even before #2729 . This PR only affects the order in which errors are reported, since they emit from a non-const context again. Don't ask me why that changes the order of error reporting though, idk :)

Note that this bad span is only for field children. Not sure what's a better span here.

|
= 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() {}