-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the cases in which c_enum! will detect multiple declarations
The problem with the previous version here was that it failed to detect the most common error case: c_enum! { #[derive(SomeTrait)] pub enum A: u32 { X = 1 } #[derive(SomeTrait)] pub enum B: u32 { Y = 1 } } In that case you would get an error message saying "no rules expected the token `pub`" and the custom error message would not be emitted at all. The new version here splits the macro into two cases: - the normal one with the new impl block syntax, and, - the error case that has a struct definition followed by some extra stuff that is definitely not an impl block. We emit a custom error in the second case and pass the extra input to a helper macro so we also emit the regular "no rules expected the token `...`" error message that we were supposed to emit. This works well enough in practice. If you end up with some extra stuff after an impl block you will likely end up getting some spurious warnings or missing attributes but you're already getting an error in that case so things should mostly work out OK.
- Loading branch information
1 parent
d78cb0d
commit f794902
Showing
2 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters