Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/yew-macro/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
clear = true
toolchain = "1.51"
command = "cargo"
args = ["test"]
# test target can be optionally specified like `cargo make test html_macro`,
args = ["test", "${@}"]
Comment on lines +5 to +6
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 find this useful in development


[tasks.test-overwrite]
extend = "test"
Expand Down
4 changes: 2 additions & 2 deletions packages/yew-macro/src/html_tree/html_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl ToTokens for HtmlComponent {

tokens.extend(quote_spanned! {ty.span()=>
{
#[allow(clippy::unit_arg)]
Copy link
Member Author

@Madoshakalaka Madoshakalaka Nov 21, 2021

Choose a reason for hiding this comment

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

Previously the now __yew_props was inlined in the new call. When there are no properties (e.g. html_nested!{<MyComponent/>}), #build_props would return MyComponent::Properties::builder().build() which is the unit type, triggering the unit arg warning.
Extracting a variable solves that.

::yew::virtual_dom::VChild::<#ty>::new(#build_props, #node_ref, #key)
let __yew_props = #build_props;
::yew::virtual_dom::VChild::<#ty>::new(__yew_props, #node_ref, #key)
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0412]: cannot find type `INVALID` in this scope
--> $DIR/generic-props-fail.rs:25:19
--> tests/function_component_attr/generic-props-fail.rs:25:19
|
20 | fn compile_fail() {
| - help: you might be missing a type parameter: `<INVALID>`
Expand All @@ -8,16 +8,24 @@ error[E0412]: cannot find type `INVALID` in this scope
| ^^^^^^^ not found in this scope

error[E0599]: no method named `build` found for struct `PropsBuilder<PropsBuilderStep_missing_required_prop_a>` in the current scope
--> $DIR/generic-props-fail.rs:22:14
--> tests/function_component_attr/generic-props-fail.rs:22:14
|
3 | #[derive(Clone, Properties, PartialEq)]
| ---------- method `build` not found for this
...
22 | html! { <Comp<Props> /> };
| ^^^^ method not found in `PropsBuilder<PropsBuilderStep_missing_required_prop_a>`

error[E0277]: the trait bound `MissingTypeBounds: yew::Properties` is not satisfied
--> tests/function_component_attr/generic-props-fail.rs:27:14
|
27 | html! { <Comp<MissingTypeBounds> /> };
| ^^^^ the trait `yew::Properties` is not implemented for `MissingTypeBounds`
|
= note: required because of the requirements on the impl of `FunctionProvider` for `comp<MissingTypeBounds>`

error[E0599]: the function or associated item `new` exists for struct `VChild<FunctionComponent<comp<MissingTypeBounds>>>`, but its trait bounds were not satisfied
--> $DIR/generic-props-fail.rs:27:14
--> tests/function_component_attr/generic-props-fail.rs:27:14
|
27 | html! { <Comp<MissingTypeBounds> /> };
| ^^^^ function or associated item cannot be called on `VChild<FunctionComponent<comp<MissingTypeBounds>>>` due to unsatisfied trait bounds
Expand All @@ -30,22 +38,14 @@ error[E0599]: the function or associated item `new` exists for struct `VChild<Fu
= note: the following trait bounds were not satisfied:
`FunctionComponent<comp<MissingTypeBounds>>: yew::Component`

error[E0277]: the trait bound `MissingTypeBounds: yew::Properties` is not satisfied
--> $DIR/generic-props-fail.rs:27:14
|
27 | html! { <Comp<MissingTypeBounds> /> };
| ^^^^ the trait `yew::Properties` is not implemented for `MissingTypeBounds`
|
= note: required because of the requirements on the impl of `FunctionProvider` for `comp<MissingTypeBounds>`

error[E0107]: missing generics for type alias `Comp`
--> $DIR/generic-props-fail.rs:30:14
--> tests/function_component_attr/generic-props-fail.rs:30:14
|
30 | html! { <Comp /> };
| ^^^^ expected 1 type argument
|
note: type alias defined here, with 1 type parameter: `P`
--> $DIR/generic-props-fail.rs:8:22
--> tests/function_component_attr/generic-props-fail.rs:8:22
|
8 | #[function_component(Comp)]
| ^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
error[E0277]: the trait bound `Unimplemented: yew::Component` is not satisfied
--> tests/html_macro/component-unimplemented-fail.rs:6:14
|
6 | html! { <Unimplemented /> };
| ^^^^^^^^^^^^^ the trait `yew::Component` is not implemented for `Unimplemented`

error[E0599]: the function or associated item `new` exists for struct `VChild<Unimplemented>`, but its trait bounds were not satisfied
--> $DIR/component-unimplemented-fail.rs:6:14
--> tests/html_macro/component-unimplemented-fail.rs:6:14
|
3 | struct Unimplemented;
| --------------------- doesn't satisfy `Unimplemented: yew::Component`
Expand All @@ -9,9 +15,3 @@ error[E0599]: the function or associated item `new` exists for struct `VChild<Un
|
= note: the following trait bounds were not satisfied:
`Unimplemented: yew::Component`

error[E0277]: the trait bound `Unimplemented: yew::Component` is not satisfied
--> $DIR/component-unimplemented-fail.rs:6:14
|
6 | html! { <Unimplemented /> };
| ^^^^^^^^^^^^^ the trait `yew::Component` is not implemented for `Unimplemented`
55 changes: 55 additions & 0 deletions packages/yew-macro/tests/html_macro/html-nested-pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#![no_implicit_prelude]

// Shadow primitives
#[allow(non_camel_case_types)]
pub struct bool;
#[allow(non_camel_case_types)]
pub struct char;
#[allow(non_camel_case_types)]
pub struct f32;
#[allow(non_camel_case_types)]
pub struct f64;
#[allow(non_camel_case_types)]
pub struct i128;
#[allow(non_camel_case_types)]
pub struct i16;
#[allow(non_camel_case_types)]
pub struct i32;
#[allow(non_camel_case_types)]
pub struct i64;
#[allow(non_camel_case_types)]
pub struct i8;
#[allow(non_camel_case_types)]
pub struct isize;
#[allow(non_camel_case_types)]
pub struct str;
#[allow(non_camel_case_types)]
pub struct u128;
#[allow(non_camel_case_types)]
pub struct u16;
#[allow(non_camel_case_types)]
pub struct u32;
#[allow(non_camel_case_types)]
pub struct u64;
#[allow(non_camel_case_types)]
pub struct u8;
#[allow(non_camel_case_types)]
pub struct usize;

pub struct MyComponent;
impl ::yew::Component for MyComponent {
type Message = ();
type Properties = ();
fn create(_ctx: &::yew::Context<Self>) -> Self {
::std::unimplemented!()
}
fn view(&self, _ctx: &::yew::Context<Self>) -> ::yew::Html {
::std::unimplemented!()
}
}

fn make_my_component()-> ::yew::virtual_dom::VChild<MyComponent>{
::yew::html_nested!{<MyComponent/>}
}

fn main(){}