-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Rename generate_solution_type!
such that it shows exactly the types
#8444
Comments
@coriolinus unassign if not suitable, I think it is a good way to get familiar with |
Sure, it seems suitable. The proposed syntax seems good to me. It's worth noting that last week there was a separate discussion (which I'm having trouble finding now) in which similar keyword-style generic arguments were proposed, and some people felt pretty strongly that they were confusingly different from standard Rust syntax. I'm not convinced that that's a strong reason not to use this syntax, but the PR will need to ensure that the macro's documentation contains both a description of what's going on and an example. |
The syntax here is pretty arbitrary and we can parse anything. Also, this will not be used extensivelty, so it need not be "valid rust". Important thing is to make sure while you are writing it, you won't mix |
Closes #8444. Just changes the parsing logic for that macro; does not change any emitted code. The associated types associated with the macro now require explicit, keyword-style declaration. **Old**: ```rust sp_npos_elections::generate_solution_type!( #[compact] pub struct TestCompact::<VoterIndex, TargetIndex, PerU16>(16) ); ``` **New**: ```rust sp_npos_elections::generate_solution_type!( #[compact] pub struct TestCompact::<VoterIndex = VoterIndex, CandidateIndex = TargetIndex, Accuracy = PerU16>(16) ); ```
* make types within `generate_solution_type` macro explicit Closes #8444. Just changes the parsing logic for that macro; does not change any emitted code. The associated types associated with the macro now require explicit, keyword-style declaration. **Old**: ```rust sp_npos_elections::generate_solution_type!( #[compact] pub struct TestCompact::<VoterIndex, TargetIndex, PerU16>(16) ); ``` **New**: ```rust sp_npos_elections::generate_solution_type!( #[compact] pub struct TestCompact::<VoterIndex = VoterIndex, CandidateIndex = TargetIndex, Accuracy = PerU16>(16) ); ``` * un-ignore doc-tests * use new form in bin/node/runtime/ * rename CandidateIndex -> TargetIndex * add tests demonstrating some potential compile failures
…#8447) * make types within `generate_solution_type` macro explicit Closes paritytech#8444. Just changes the parsing logic for that macro; does not change any emitted code. The associated types associated with the macro now require explicit, keyword-style declaration. **Old**: ```rust sp_npos_elections::generate_solution_type!( #[compact] pub struct TestCompact::<VoterIndex, TargetIndex, PerU16>(16) ); ``` **New**: ```rust sp_npos_elections::generate_solution_type!( #[compact] pub struct TestCompact::<VoterIndex = VoterIndex, CandidateIndex = TargetIndex, Accuracy = PerU16>(16) ); ``` * un-ignore doc-tests * use new form in bin/node/runtime/ * rename CandidateIndex -> TargetIndex * add tests demonstrating some potential compile failures
This is an example of a solution type generation:
The fact that I have to document it, and double check it is exactly showing the issue here. the syntax of the macro should be such that it clearly shows these. After all, the entire
::
and<_>
is fake and I am manually parsing it. Maybe something likeThe text was updated successfully, but these errors were encountered: