Permit impl item to end with semicolon #118
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.
Writing signatures of a trait impl with a trailing semicolon is ubiquitous when discussing library APIs in Rust.
Despite being not compiler-accepted syntax, the notation is easily understandable to human Rust programmers.
Some examples in the wild:
Iterator::map_windows
(featureiter_map_windows
) rust-lang/rust#87155 (comment)In fact the notation serves an important role in API design discussions: talking about
impl Trait for SomeType;
makes no claim about how the methods ofTrait
are implemented, just thatTrait
is implemented. How it's implemented is unspecified. This is in contrast to someone having writtenimpl Trait for SomeType {}
which is legal syntax for an impl that inherits all default method implementations from the trait definition, which is most often not what the participant intended to communicate.Sadly, today the notation throws off tree-sitter. You can tell from GitHub's syntax highlighting in the links above. Notice how
impl
keywords after a semicolon aren't getting colored as keywords.Running tree-sitter on the trait impl signatures added in this PR to corpus/declarations.txt confirms that tree-sitter doesn't really have that much idea what is going on. Before:
This PR makes the
body
field ofimpl_item
optional, and will parse impl signatures with a trailing semicolon as having nobody
.