-
-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Did you check existing issues?
- I have read all the tree-sitter docs if it relates to using the parser
- I have searched the existing issues of tree-sitter-rust
Tree-Sitter CLI Version, if relevant (output of tree-sitter --version
)
No response
Describe the bug
The parser incorrectly flags a valid piece of Rust code as a syntax error. The error seems to be specifically triggered when a variable named raw is used in a slice-and-compare context like &raw[0..4].
Renaming the variable to anything else (e.g., rww) makes the parsing error disappear. This suggests a bug in how the parser handles the identifier raw in this specific grammatical structure, likely treating it as a keyword by mistake.
Steps to Reproduce
Create a Rust file (test.rs) with the following minimal code containing two functions.
Steps To Reproduce/Bad Parse Tree
`// Minimal code to demonstrate the bug
const TAG: [u8; 4] = [0, 1, 2, 3];
// 1. This function fails to parse
fn check_fails(raw: &Vec) {
if &raw[0..4] != TAG {
// ...
}
}
// 2. This function parses correctly
fn check_works(rww: &Vec) {
if &rww[0..4] != TAG {
// ...
}
}`
Expected Behavior/Parse Tree
- File {
shebang: undefined
attrs: [] - items: [
- ItemConst {attrs, vis, const_token, ident, colon_token, ... +4}
- ItemFn {attrs, vis, sig, block}
- ItemFn {
attrs: []
vis: Visibility::Inherited {}- sig: Signature {constness, asyncness, unsafety, abi, fn_token, ... +6}
- block: Block {
- stmts: [1 element]
brace_token: Brace {
}
}
}
]
}
- stmts: [1 element]
Repro
// Example code that causes the issue
fn foo() {
// Code that fails to parse, or causes an error
}