From 774a1e0028824ca6354b8079582c3b6a56b4a8a8 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Thu, 5 Jun 2025 18:31:46 +0200 Subject: [PATCH] feat: trait bound modifiers: ~const, async and ! (#9) Tracking issue: https://github.com/rust-lang/rust/issues/67792. This syntax is already supported by rustc stable, 2024 edition. Reviewed-on: https://codeberg.org/grammar-orchard/tree-sitter-rust-orchard/pulls/9 Co-authored-by: Antonin Delpeuch Co-committed-by: Antonin Delpeuch --- grammar.js | 7 ++++++- test/corpus/declarations.txt | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/grammar.js b/grammar.js index 1907a3a3..d660238f 100644 --- a/grammar.js +++ b/grammar.js @@ -529,7 +529,12 @@ module.exports = grammar({ trait_bounds: $ => seq( ':', sepBy1('+', choice( - $._type, + prec(1, seq( + optional("~const"), + optional("async"), + optional("!"), + $._type + )), $.lifetime, $.higher_ranked_trait_bound, )), diff --git a/test/corpus/declarations.txt b/test/corpus/declarations.txt index 77195e86..de9b13c0 100644 --- a/test/corpus/declarations.txt +++ b/test/corpus/declarations.txt @@ -1909,6 +1909,35 @@ impl> HasNodeId for T {} (type_identifier) (declaration_list))) +================================================================================ +Trait bounds with modifiers +================================================================================ + +impl Foo for Bar {} +impl Foo for Bar {} + +-------------------------------------------------------------------------------- + +(source_file + (impl_item + (type_parameters + (type_parameter + (type_identifier) + (trait_bounds + (type_identifier)))) + (type_identifier) + (type_identifier) + (declaration_list)) + (impl_item + (type_parameters + (type_parameter + (type_identifier) + (trait_bounds + (type_identifier)))) + (type_identifier) + (type_identifier) + (declaration_list))) + ================================================================================ Macro invocations inside trait declarations ================================================================================