forked from rust-lang/rustfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some basic tests for
try{}
expressions
They failed to parse in rustfmt on me in rust-lang/rust#77877, which looks like it's since been fixed, but I figured I'd send in some tests anyway.
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// rustfmt-edition: 2018 | ||
|
||
fn main() -> Result<(), !> { | ||
let _x: Option<_> = try { | ||
4 | ||
}; | ||
|
||
try {} | ||
} | ||
|
||
fn baz() -> Option<i32> { | ||
if (1 == 1) { | ||
return try { | ||
5 | ||
}; | ||
} | ||
|
||
// test | ||
let x: Option<()> = try { | ||
// try blocks are great | ||
}; | ||
|
||
let y: Option<i32> = try { | ||
6 | ||
}; // comment | ||
|
||
let x: Option<i32> = try { baz()?; baz()?; baz()?; 7 }; | ||
|
||
return None; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// rustfmt-edition: 2018 | ||
|
||
fn main() -> Result<(), !> { | ||
let _x: Option<_> = try { 4 }; | ||
|
||
try {} | ||
} | ||
|
||
fn baz() -> Option<i32> { | ||
if (1 == 1) { | ||
return try { 5 }; | ||
} | ||
|
||
// test | ||
let x: Option<()> = try { | ||
// try blocks are great | ||
}; | ||
|
||
let y: Option<i32> = try { 6 }; // comment | ||
|
||
let x: Option<i32> = try { | ||
baz()?; | ||
baz()?; | ||
baz()?; | ||
7 | ||
}; | ||
|
||
return None; | ||
} |