Skip to content

Commit

Permalink
Better diagnostic message.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed May 23, 2022
1 parent 7e12d61 commit b8267ef
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion packages/yew-macro/src/use_prepared_state.rs
Expand Up @@ -15,7 +15,9 @@ impl Parse for PreparedState {
// Reads a closure.
let closure: ExprClosure = input.parse()?;

input.parse::<Token![,]>()?;
input
.parse::<Token![,]>()
.map_err(|e| syn::Error::new(e.span(), "expected a second argument as dependency"))?;

let return_type = match &closure.output {
ReturnType::Default => {
Expand Down
4 changes: 3 additions & 1 deletion packages/yew-macro/src/use_transitive_state.rs
Expand Up @@ -15,7 +15,9 @@ impl Parse for TransitiveState {
// Reads a closure.
let closure: ExprClosure = input.parse()?;

input.parse::<Token![,]>()?;
input
.parse::<Token![,]>()
.map_err(|e| syn::Error::new(e.span(), "expected a second argument as dependency"))?;

let return_type = match &closure.output {
ReturnType::Default => {
Expand Down
Expand Up @@ -10,15 +10,15 @@ error: You must specify a return type for this closure. This is used when the cl
8 | use_prepared_state_with_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
error: expected a second argument as dependency
--> tests/hook_macro/use_prepared_state-fail.rs:10:5
|
10 | use_prepared_state_with_closure!(|_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_prepared_state_with_closure` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `,`
error: expected a second argument as dependency
--> tests/hook_macro/use_prepared_state-fail.rs:12:5
|
12 | use_prepared_state_with_closure!(async |_| -> u32 { todo!() })?;
Expand All @@ -38,15 +38,15 @@ error: You must specify a return type for this closure. This is used when the cl
21 | use_prepared_state_without_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
error: expected a second argument as dependency
--> tests/hook_macro/use_prepared_state-fail.rs:23:5
|
23 | use_prepared_state_without_closure!(|_| -> u32 { todo!() })?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `use_prepared_state_without_closure` (in Nightly builds, run with -Z macro-backtrace for more info)

error: expected `,`
error: expected a second argument as dependency
--> tests/hook_macro/use_prepared_state-fail.rs:25:5
|
25 | use_prepared_state_without_closure!(async |_| -> u32 { todo!() })?;
Expand Down
Expand Up @@ -10,7 +10,7 @@ error: You must specify a return type for this closure. This is used when the cl
8 | use_transitive_state_with_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
error: expected a second argument as dependency
--> tests/hook_macro/use_transitive_state-fail.rs:10:5
|
10 | use_transitive_state_with_closure!(|_| -> u32 { todo!() })?;
Expand All @@ -30,7 +30,7 @@ error: You must specify a return type for this closure. This is used when the cl
19 | use_transitive_state_without_closure!(|_| { todo!() }, 123)?;
| ^^^^^^^^^^^^^^^

error: expected `,`
error: expected a second argument as dependency
--> tests/hook_macro/use_transitive_state-fail.rs:21:5
|
21 | use_transitive_state_without_closure!(|_| -> u32 { todo!() })?;
Expand Down

0 comments on commit b8267ef

Please sign in to comment.