tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
338 stars 96 forks source link

bug: error on const generics #228

Open matthiaskrgr opened 2 months ago

matthiaskrgr commented 2 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

the issued code looks ok on first glance, maybe just don't emit an error? code compile s fine.

Steps To Reproduce/Bad Parse Tree

source_file [0, 0] - [4, 0] struct_item [0, 0] - [3, 1] visibility_modifier [0, 0] - [0, 3] name: type_identifier [0, 11] - [0, 15] type_parameters: type_parameters [0, 15] - [0, 45] constrained_type_parameter [0, 16] - [0, 24] left: type_identifier [0, 16] - [0, 17] bounds: trait_bounds [0, 17] - [0, 24] type_identifier [0, 19] - [0, 24] const_parameter [0, 26] - [0, 40] name: identifier [0, 32] - [0, 33] type: primitive_type [0, 35] - [0, 40] ERROR [0, 41] - [0, 44] integer_literal [0, 43] - [0, 44] body: field_declaration_list [0, 46] - [3, 1] field_declaration [1, 4] - [1, 16] name: field_identifier [1, 4] - [1, 8] type: array_type [1, 10] - [1, 16] element: type_identifier [1, 11] - [1, 12] length: identifier [1, 14] - [1, 15] field_declaration [2, 4] - [2, 14] name: field_identifier [2, 4] - [2, 9] type: array_type [2, 11] - [2, 14] element: type_identifier [2, 12] - [2, 13]

Expected Behavior/Parse Tree

source_file [0, 0] - [4, 0] struct_item [0, 0] - [3, 1] visibility_modifier [0, 0] - [0, 3] name: type_identifier [0, 11] - [0, 15] type_parameters: type_parameters [0, 15] - [0, 45] constrained_type_parameter [0, 16] - [0, 24] left: type_identifier [0, 16] - [0, 17] bounds: trait_bounds [0, 17] - [0, 24] type_identifier [0, 19] - [0, 24] const_parameter [0, 26] - [0, 40] name: identifier [0, 32] - [0, 33] type: primitive_type [0, 35] - [0, 40] integer_literal [0, 43] - [0, 44] body: field_declaration_list [0, 46] - [3, 1] field_declaration [1, 4] - [1, 16] name: field_identifier [1, 4] - [1, 8] type: array_type [1, 10] - [1, 16] element: type_identifier [1, 11] - [1, 12] length: identifier [1, 14] - [1, 15] field_declaration [2, 4] - [2, 14] name: field_identifier [2, 4] - [2, 9] type: array_type [2, 11] - [2, 14] element: type_identifier [2, 12] - [2, 13]

Repro

pub struct Loaf<T: Sized, const N: usize = 1> {
    head: [T; N],
    slice: [T],
}