Skip to content

Commit 2630bea

Browse files
committed
For lifetimes
1 parent 59f6ab6 commit 2630bea

File tree

4 files changed

+634
-2783
lines changed

4 files changed

+634
-2783
lines changed

community-rust-frontend/src/main/java/org/sonar/rust/RustGrammar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ private static void genericItem(LexerlessGrammarBuilder b) {
748748
LIFETIME_WHERE_CLAUSE_ITEM, TYPE_BOUND_CLAUSE_ITEM));
749749
b.rule(LIFETIME_WHERE_CLAUSE_ITEM).is(LIFETIME, SPC, RustPunctuator.COLON, SPC, LIFETIME_BOUNDS);
750750
b.rule(TYPE_BOUND_CLAUSE_ITEM).is(
751-
b.optional(FOR_LIFETIMES), TYPE, RustPunctuator.COLON, b.optional(TYPE_PARAM_BOUNDS));
751+
b.optional(FOR_LIFETIMES), SPC, TYPE, SPC, RustPunctuator.COLON, b.optional(TYPE_PARAM_BOUNDS));
752752

753753
b.rule(FOR_LIFETIMES).is(RustKeyword.KW_FOR, SPC, GENERIC_PARAMS);
754754

community-rust-frontend/src/test/java/org/sonar/rust/RustLexerTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ public void testTokens() {
6666

6767
@Test
6868
public void testParsing() {
69-
String sexpr = " let Some(f1) = pieces.next() else {\n" +
70-
" return Err(de::Error::invalid_length(0, &\"2\"));\n" +
71-
" };";
69+
String sexpr = "pub fn f<AF>() -> int32\n" +
70+
" where\n" +
71+
"\n" +
72+
" //for<'a> &'a AF: FieldOpsBounds<'a, F, AF>,\n" +
73+
" for<'a> AF: FieldOpsBounds<'a, F, AF>,\n" +
74+
"{\n" +
75+
" let modes = 42;\n" +
76+
" 42\n" +
77+
"}";
7278

7379
// Print out Ast node content for debugging purpose
7480

community-rust-frontend/src/test/java/org/sonar/rust/parser/types/TypeTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ public void testTraitObjectType() {
182182
;
183183
}
184184

185+
@Test
186+
public void testReferenceType() {
187+
assertThat(RustGrammar.create().build().rule(RustGrammar.REFERENCE_TYPE))
188+
.matches("&i32")
189+
.matches("&(i32, u8)")
190+
.matches("&Circle")
191+
.notMatches("&Circle{")
192+
.matches("&[u8]")
193+
.matches("&Token![#]")
194+
.matches("&'a i32")
195+
.matches("&mut Circle")
196+
.matches("&'b mut Circle")
197+
.matches("&'a AF")
198+
199+
200+
;
201+
}
202+
185203
@Test
186204
public void testType() {
187205
assertThat(RustGrammar.create().build().rule(RustGrammar.TYPE))
@@ -213,6 +231,8 @@ public void testType() {
213231
.matches("impl Future<Output = ()> + 'm")
214232
.matches("::Option<unsafe extern \"C\" fn(::c_int, *const ::c_char)>")
215233
.matches("::Option<unsafe extern \"C\" fn(::c_int, *const ::c_char, ...)>")
234+
.matches("&'a AF")
235+
216236

217237
;
218238
}

0 commit comments

Comments
 (0)