From 9ce02b4f60929233d484afbb556df8524f9dbd36 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 5 Jun 2025 16:30:43 +0200 Subject: [PATCH] feat: Support for `auto trait` (#7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tracking issue: https://github.com/rust-lang/rust/issues/13231 Stable rustc is already able to parse those. Reviewed-on: https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard/pulls/7 Co-authored-by: Antonin Delpeuch Co-committed-by: Antonin Delpeuch --- grammar.js | 3 ++- test/corpus/declarations.txt | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/grammar.js b/grammar.js index 1907a3a3..a754bf8c 100644 --- a/grammar.js +++ b/grammar.js @@ -238,7 +238,7 @@ module.exports = grammar({ alias(choice(...primitiveTypes), $.primitive_type), prec.right(repeat1(choice(...TOKEN_TREE_NON_SPECIAL_PUNCTUATION))), '\'', - 'as', 'async', 'await', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'gen', + 'as', 'async', 'auto', 'await', 'break', 'const', 'continue', 'default', 'enum', 'fn', 'for', 'gen', 'if', 'impl', 'let', 'loop', 'match', 'mod', 'pub', 'return', 'static', 'struct', 'trait', 'type', 'union', 'unsafe', 'use', 'where', 'while', ), @@ -509,6 +509,7 @@ module.exports = grammar({ trait_item: $ => seq( optional($.visibility_modifier), optional('unsafe'), + optional('auto'), 'trait', field('name', $._type_identifier), field('type_parameters', optional($.type_parameters)), diff --git a/test/corpus/declarations.txt b/test/corpus/declarations.txt index 77195e86..b6b72341 100644 --- a/test/corpus/declarations.txt +++ b/test/corpus/declarations.txt @@ -1706,7 +1706,7 @@ unsafe impl Trait for dyn (::std::any::Any) + Send { } (scoped_identifier (identifier)) (identifier)) - (type_identifier)))) + (type_identifier)))) (type_identifier)) (declaration_list))) @@ -1786,6 +1786,8 @@ pub trait Item: Clone + Eq + fmt::Debug { unsafe trait Foo { } +unsafe auto trait Bar { } + -------------------------------------------------------------------------------- (source_file @@ -1807,6 +1809,9 @@ unsafe trait Foo { } (scoped_type_identifier (identifier) (type_identifier))))) + (trait_item + (type_identifier) + (declaration_list)) (trait_item (type_identifier) (declaration_list)))