Add support for struct expressions#602
Conversation
|
This is a solid start, thanks! Please add And one question: should we add support for tuple structs with the |
I thought that it is supported today as a "function call" since the syntax is not any different, but maybe I am missing something |
|
... It's so obvious I wonder how I missed it. ^^' So yeah, just missing tests and docs. |
|
I have added UI tests, but I don't know if my choice of test cases is correct. I have also added a short mention to the book. |
|
CI failure is on nightly due to rust-lang/rust#138907 |
| @@ -0,0 +1,63 @@ | |||
| error: expected closing `}` of struct expression | |||
There was a problem hiding this comment.
That proves that we need to improve parsing error. Like if ..expr is followed by another field, emit an error about that directly.
| 18 | source = r#"{{ InnerCell { ..Default::default(), other: 24 } }}"#, | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: failed to parse template source |
There was a problem hiding this comment.
Hum, not sure if this case is useful.
| 24 | #[template(source = r#"some{{ InnerCell { }}thing"#, ext = "txt")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: expected closing `}` of struct expression |
| 28 | #[template(source = r#"some{{ InnerCell { foo }}thing"#, ext = "txt")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: expected closing `}` of struct expression |
There was a problem hiding this comment.
The error here should be that a value is missing after the field name.
| 32 | #[template(source = r#"some{{ InnerCell { foo: }}thing"#, ext = "txt")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: failed to parse template source |
There was a problem hiding this comment.
Not useful either.
| 36 | #[template(source = r#"some{{ InnerCell { foo: 32 }}thing"#, ext = "txt")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: failed to parse template source |
There was a problem hiding this comment.
Same. Although, there is no "working" test which checks if trailing comma is supported, please add one.
| 40 | #[template(source = r#"some{{ InnerCell { foo: 32, }}thing"#, ext = "txt")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: expected closing `}` of struct expression |
There was a problem hiding this comment.
Error message should be improved here: it should say that something is expected after ...
| 44 | #[template(source = r#"some{{ InnerCell { foo: 32, .. }}thing"#, ext = "txt")] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| error: failed to parse template source |
|
Code looks good, docs look good. Errors need improvements (thanks the tests to show us why and how hehe) and tests also need some improvements. The idea here is trying to ensure that the struct syntax is working and to check what happens in weird user input like:
Also need to check trailing commas like:
|
|
Thanks for the comments. I probably won't find time to move this forward in next two week, someday after that probably yes but I don't know when... If anyone wants to pick this up and finish it feel free to. |
|
Then I'll if you don't mind as I think it's a really nice addition. :) |
c1e3ce0 to
0071c49
Compare
|
I'm much happier with the error messages now. Also reverted the What do you think @Kijewski ? |
0071c49 to
0884148
Compare
|
(fixed the clippy warning too) |
0884148 to
334519e
Compare
|
Gonna merge. When @Kijewski has time and motivation to take a look, I'm sure a PR will follow. 😉 |
I have found some time to do it, so here it is.
fix #597