Make GrammarAST non-exhaustive.
#584
Merged
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.
Apologies in advance for the number of words I am likely to spill on this one line patch.
I seek to convince that we can reasonably add
#[non_exhaustive]tostruct GrammarAST,the short explanation is that we have
GrammarAST::new()and all the fields are pub so any usage ofShould be easily replaced by
GrammarAST::newand field access.The longer explanation I seek to explain that even
GrammarAST::new()is likely not useful function, in the sense that we could consider making itpub crate. Then I'll argue against that for future expansion.The key thing to note is that it does not appear there is anything tangible you can actually do anything with a
let ast = GrammarAST::new().The closest function we have to anything taking a
fn (GrammarAST) -> YaccGrammaris YaccGrammar::new_from_ast_with_validity_info however that doesn't take aGrammarASTbut aASTWithValidityInfo, and there currently isn't any way to construct those expet from a&streither.In this PR I didn't mark
newaspub crateprecisely because it seems like there might be a reasonable argumentthat we could add an
unsafe fn set_ast(&mut self, ast: GrammarAST)toASTWithValidityInfo. This might be useful as an alternative to the hack discussed in #484I.e. you could construct one
GrammarASTfrom a source file, clone it, changing the start rule and using the unsafe function.Lastly
GrammarASTisn'tEq, or anything limiting the chances people might be constructing one manually and comparing it to another.Edit: I should perhaps caveat this one with a: "unless I'm missing something completely obvious"