diff --git a/queries/rust/highlights.scm b/queries/rust/highlights.scm index db5e39828..c08912bea 100644 --- a/queries/rust/highlights.scm +++ b/queries/rust/highlights.scm @@ -211,13 +211,15 @@ [ "break" "continue" - "for" "in" "loop" "while" ] @repeat - +(impl_item + "for" @keyword) +(for_expression + "for" @repeat) ;;; Operators & Punctuation diff --git a/tests/query/highlights/rust/for.rs b/tests/query/highlights/rust/for.rs new file mode 100644 index 000000000..27f072847 --- /dev/null +++ b/tests/query/highlights/rust/for.rs @@ -0,0 +1,15 @@ +struct Foo; + +// Issue https://github.com/nvim-treesitter/nvim-treesitter/issues/3641 +// Distinguish between for in loop or impl_item +impl Drop for Foo { + // ^ @keyword + fn drop(&mut self) {} +} + +fn main() { + for i in 0..128 { + // <- @repeat + println!("{i}"); + } +}