Yew: New event macros cause extremely confusing error message

Created on 24 May 2018  路  6Comments  路  Source: yewstack/yew

Description

I'm submitting a bug

When bumping to the latest commit (00e7a97) of yew, I get extremely confusing error messages of the form

   Compiling logobble-dataflow-page v0.1.0 (file:///home/aidanhs/Desktop/rust/logobble/dataflow-page)
error[E0277]: `[closure@src/lib.rs:207:82: 207:110 job_id:_]` doesn't implement `std::fmt::Display`
   --> src/lib.rs:206:57
    |
206 | /                                                         html!{
207 | |                                                             <div><button onclick=move |_| Msg::GetLog(job_id),  disabled={!job.is_destamped},>
208 | |                                                                 { format!("Job {}", job.id) }
209 | |                                                             </button></div>
210 | |                                                         }
    | |_________________________________________________________^ `[closure@src/lib.rs:207:82: 207:110 job_id:_]` cannot be formatted with the default formatter
    |
    = help: the trait `std::fmt::Display` is not implemented for `[closure@src/lib.rs:207:82: 207:110 job_id:_]`
    = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
    = note: required because of the requirements on the impl of `std::string::ToString` for `[closure@src/lib.rs:207:82: 207:110 job_id:_]`
    = note: required by `yew::macros::add_attribute`
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: Could not compile `logobble-dataflow-page`.

It appears this is because https://github.com/DenisKolodin/yew/pull/240 now auto-adds the move keyword.

This was clearly done deliberately, so just raising for visibility.

Most helpful comment

You are right! This affects 0.3 and it's a breaking-change. Error message looks terrible, but to support old and new styles I have to make macro very large that's why I decided to support a new one.

To update your templates from 0.3 to 0.4 you should change:

html! {
<input value=&self.name, oninput=move |e: InputData| Msg::UpdateEvent(idx, e.value), />
}

with:

html! {
<input value=&self.name, oninput=|e| Msg::UpdateEvent(idx, e.value), />
}

I prefer to derive types automatically where possible (especially in templates). And move modifier is useful, because a closure inside a template can't borrow the environment.

I like the idea to publish this changes soon, because I am in progress to upgrade the framework to actors model and I have a significant progress in this direction. We shouldn't overload 0.4 release with a lot of changes :ok_hand:

All 6 comments

I also encountered this today, but I don't think it is a bug, it is just a breaking change. It affects projects using yew 0.3.
I think we should publish 0.4 as soon as possible. This may help new commers, they will use the latest version (0.4) so they will not encounter confusing error like this. How do you think @DenisKolodin ?

You are right! This affects 0.3 and it's a breaking-change. Error message looks terrible, but to support old and new styles I have to make macro very large that's why I decided to support a new one.

To update your templates from 0.3 to 0.4 you should change:

html! {
<input value=&self.name, oninput=move |e: InputData| Msg::UpdateEvent(idx, e.value), />
}

with:

html! {
<input value=&self.name, oninput=|e| Msg::UpdateEvent(idx, e.value), />
}

I prefer to derive types automatically where possible (especially in templates). And move modifier is useful, because a closure inside a template can't borrow the environment.

I like the idea to publish this changes soon, because I am in progress to upgrade the framework to actors model and I have a significant progress in this direction. We shouldn't overload 0.4 release with a lot of changes :ok_hand:

@DenisKolodin I really prefer the new style :+1:

I think it would be good to include a changelog for such breaking changes in the future though (this breakage is in 0.4) :smile:

I think it would be good to include a changelog for such breaking changes in the future though (this breakage is in 0.4)

@vitiral Very good point! I'll put it in the changelog added with #272 :ok_hand:

Removed the magical event macro here: https://github.com/yewstack/yew/pull/782

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kellytk picture kellytk  路  4Comments

kellytk picture kellytk  路  3Comments

djahandarie picture djahandarie  路  3Comments

Boscop picture Boscop  路  5Comments

IngwiePhoenix picture IngwiePhoenix  路  4Comments