Skip to content

Commit 97b4e66

Browse files
committed
fix: ambiguity with unit types
1 parent 24adbb7 commit 97b4e66

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

grammar.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ module.exports = grammar({
108108
[$.parameters, $.tuple_struct_pattern],
109109
[$.type_parameters, $.for_lifetimes],
110110
[$.array_expression],
111+
[$.visibility_modifier],
112+
[$.visibility_modifier, $.scoped_identifier, $.scoped_type_identifier],
111113
],
112114

113115
word: $ => $.identifier,
@@ -684,23 +686,22 @@ module.exports = grammar({
684686
optional($.string_literal),
685687
),
686688

687-
visibility_modifier: $ => prec.right(
688-
choice(
689-
$.crate,
690-
seq(
691-
'pub',
692-
optional(seq(
693-
'(',
694-
choice(
695-
$.self,
696-
$.super,
697-
$.crate,
698-
seq('in', $._path),
699-
),
700-
')',
701-
)),
702-
),
703-
)),
689+
visibility_modifier: $ => choice(
690+
$.crate,
691+
seq(
692+
'pub',
693+
optional(seq(
694+
'(',
695+
choice(
696+
$.self,
697+
$.super,
698+
$.crate,
699+
seq('in', $._path),
700+
),
701+
')',
702+
)),
703+
),
704+
),
704705

705706
// Section - Types
706707

test/corpus/declarations.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ struct Point {
607607
}
608608
struct Color(pub i32, i32, i32);
609609
struct Inches(i32);
610+
struct Empty(pub ());
610611

611612
--------------------------------------------------------------------------------
612613

@@ -649,7 +650,12 @@ struct Inches(i32);
649650
(struct_item
650651
(type_identifier)
651652
(ordered_field_declaration_list
652-
(primitive_type))))
653+
(primitive_type)))
654+
(struct_item
655+
(type_identifier)
656+
(ordered_field_declaration_list
657+
(visibility_modifier)
658+
(unit_type))))
653659

654660
================================================================================
655661
Unions

0 commit comments

Comments
 (0)