Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

add support for Q_LISTMODEL with only one member #16

Closed
fneddy opened this issue Oct 14, 2016 · 3 comments
Closed

add support for Q_LISTMODEL with only one member #16

fneddy opened this issue Oct 14, 2016 · 3 comments
Assignees
Labels

Comments

@fneddy
Copy link
Contributor

fneddy commented Oct 14, 2016

currently it is not possible to create a Q_LISTMODEL! with only one member:

Q_LISTMODEL!{
    pub QTestModel {
        name: String,
    }
}
error: expected one of `,` or `@`, found `)`
  --> <qml macros>:22:26
   |
22 | | ( $ ( $ rolename ) , * ) | {
   |                          ^

error: expected pattern, found `{`
  --> <qml macros>:22:30
   |
22 | | ( $ ( $ rolename ) , * ) | {
   |                              ^

error: expected expression, found statement (`let`)
  --> <qml macros>:23:1
   |
23 | let mut vec = Vec :: new (  ) ; $ ( vec . push ( $ rolename . into (  ) ) ; )
   | ^^^
   |
   = note: variable declaration using `let` is a statement

error: expected one of `,`, `->`, `.`, `<`, `?`, `break`, `continue`, `for`, `if`, `loop`, `match`, `move`, `return`, `unsafe`, `while`, or an operator, found `let`
  --> <qml macros>:23:1
   |
23 | let mut vec = Vec :: new (  ) ; $ ( vec . push ( $ rolename . into (  ) ) ; )
   | ^^^

error: expected one of `->`, `.`, `;`, `<`, `?`, `break`, `continue`, `for`, `if`, `loop`, `match`, `move`, `return`, `unsafe`, `while`, `}`, or an operator, found `let`
  --> <qml macros>:23:1
   |
23 | let mut vec = Vec :: new (  ) ; $ ( vec . push ( $ rolename . into (  ) ) ; )
   | ^^^

error: expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `)`
  --> <qml macros>:24:9
   |
24 | * vec } ) . collect :: < Vec < Vec < QVariant >> > (  ) ) }
   |         ^

error: Could not compile `z-machine`.

To learn more, run the command again with --verbose.
@fneddy
Copy link
Contributor Author

fneddy commented Oct 17, 2016

this happens here. The macro parser somehow does not like the expand in the tuple with only one element $($rolename),* but strangely this $($rolename,)* expands without a problem, through it generates invalid rust code.

@White-Oak
Copy link
Owner

Yes, I stumbled upon the same, it's a strange issue, I found the somehow simmilar point here in docs if you Ctrl-F for impl<A> Clone for (A,) where A: Clone you'll see that the tuple with one element requires (A,) a comma.
I'll ask around

@White-Oak
Copy link
Owner

Ah, that's because Rust can't unserstand if (expr) is a braced expression or a tuple.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants