idl: Fix using constant identifiers as generic arguments #3522
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Using constant identifiers as generic arguments results in a compile error during IDL generation as explained in #3520.
This is because constant identifiers are parsed as
GenericArgument::Type
(rather thanGenericArgument::Const
) in thesyn
library, as they are indistinguishable syntactically:https://github.com/dtolnay/syn/blob/bfa790b8e445dc67b7ab94d75adb1a92d6296c9a/src/path.rs#L113-L114
Summary of changes
Fix being unable to use constant identifiers as generic arguments by parsing generic arguments that look like a constant identifier as
IdlGenericArg::Const
rather thanIdlGenericArg::Type
.Currently this means we check if the identifier is longer than 1 letter and is fully uppercase. It's not perfect, but it should work as expected if the user follows Rust's naming conventions.
Fixes #3520