Rust support for ellipses inside struct initialization and use lists#563
Merged
Fidget-Grep merged 2 commits intomainfrom Feb 13, 2026
Merged
Conversation
Contributor
Author
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Added two new grammar rules. One for
field_initializers of struct initialization, giving them an option to include ellipsis. One for_use_clauses of use statements, also giving them the options of being an ellipsis.Checklist
NOTES:
For anyone completely new to contributing to the Semgrep Ocaml repo (like me), here's what I learned:
testdirectory for each language, you can see this happening. In this PR I addedimport.rsandstruct.rscode snippets, and when you run./test-lang rustfrom thelangdirectory, the engine creates CST filesimport.rs.cstandstruct.rs.cst.test/corpusdirectory for each grammar (semgrep-rustin our case). The tests are stored in.txtfiles with titles and headers. Each test contains both an example Semgrep pattern and an AST (abstract syntax tree). When the test is run, the engine will turn the Semgrep pattern into a CST and then an AST, and then will check it against the provided AST for correctness.grammar.js. The Semgrep grammar builds on top of an existing grammar (from the tree-sitter project), which is also defined in agrammar.js. The grammar file I'm changing in this PR builds on top of thegrammar.jsfile inside thetree-sitter-rustsubmodule, and I referred to that as a reference to see how the grammar is defined and overwritten. Here's what my two additions are actually saying:field_initializercan be one of two things: the exact samefield_initializerdefined intree-sitter-rust/grammar.js, or an ellipsis._use_clausecan be any of the original options defined in_use_clausein the originaltree-sitter-rust/grammar.js, or an ellipsis.grammar.jsto change/expand the grammar, andsemgrep.txtto add new tests. Refer to these two files in other languages for examples on how to do what you want to do.