Skip to content

Commit 07a8475

Browse files
committed
GRAM: Support exclusive ranges in patterns (.. in if let and match arms)
Inclusive ranges in patterns use '...' (possibly also '..=' in the future). Exclusive ranges in patterns use '..' This feature is currently unstable and can be enabled with #![feature(exclusive_range_pattern)]
1 parent e44cb24 commit 07a8475

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/main/grammars/RustParser.bnf

+2-2
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ Pat ::= PatWild
401401
| PatStruct
402402
| PatEnum
403403
| PatIdent
404-
| (PatConst !'...')
404+
| (PatConst !('..' | '...'))
405405
| PatRange
406406
| PatUniq
407407

@@ -427,7 +427,7 @@ private Pat_with_recover ::= Pat (',' | &(')' | ']' | '..'))
427427
private PatField_with_recover ::= PatField (',' | & '}')
428428

429429
PatConst ::= PathExpr | LitExpr | &('-' LitExpr) UnaryExpr
430-
PatRange ::= PatConst '...' PatConst { pin = 2 }
430+
PatRange ::= PatConst ('..' | '...') PatConst { pin = 2 }
431431

432432
PatTup ::= '(' SeqPat ')'
433433
PatVec ::= '[' SeqPat ']'

src/test/kotlin/org/rust/ide/formatter/RsFormatterTest.kt

+2
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,12 @@ class RsFormatterTest : RsFormatterTestBase() {
307307

308308
fun `test unary minus in range patterns`() = doTextTest("""
309309
fn main() {
310+
if let - 10 .. - 1 = - 8 {}
310311
if let - 10 ... - 1 = - 8 {}
311312
}
312313
""", """
313314
fn main() {
315+
if let -10..-1 = -8 {}
314316
if let -10...-1 = -8 {}
315317
}
316318
""")

src/test/kotlin/org/rust/lang/core/type/RsNumericLiteralTypeInferenceTest.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class RsNumericLiteralTypeInferenceTest : RsTypificationTestBase() {
414414
}
415415
""")
416416

417-
fun `test unify match pattern range`() = testExpr("""
417+
fun `test unify match pattern inclusive range`() = testExpr("""
418418
fn main() {
419419
match 0u8 {
420420
0...1 => {},
@@ -424,6 +424,16 @@ class RsNumericLiteralTypeInferenceTest : RsTypificationTestBase() {
424424
}
425425
""")
426426

427+
fun `test unify match pattern exclusive range`() = testExpr("""
428+
fn main() {
429+
match 0u8 {
430+
0..1 => {},
431+
//^ u8
432+
_ => {},
433+
};
434+
}
435+
""")
436+
427437
fun `test unify match pattern tuple`() = testExpr("""
428438
fn main() {
429439
match (0u8,) {

0 commit comments

Comments
 (0)