Skip to content

Commit 3543460

Browse files
scottmcmcalebcartwright
authored andcommitted
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.
1 parent f352f38 commit 3543460

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

tests/source/try_block.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// rustfmt-edition: 2018
2+
3+
fn main() -> Result<(), !> {
4+
let _x: Option<_> = try {
5+
4
6+
};
7+
8+
try {}
9+
}
10+
11+
fn baz() -> Option<i32> {
12+
if (1 == 1) {
13+
return try {
14+
5
15+
};
16+
}
17+
18+
// test
19+
let x: Option<()> = try {
20+
// try blocks are great
21+
};
22+
23+
let y: Option<i32> = try {
24+
6
25+
}; // comment
26+
27+
let x: Option<i32> = try { baz()?; baz()?; baz()?; 7 };
28+
29+
return None;
30+
}

tests/target/try_block.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// rustfmt-edition: 2018
2+
3+
fn main() -> Result<(), !> {
4+
let _x: Option<_> = try { 4 };
5+
6+
try {}
7+
}
8+
9+
fn baz() -> Option<i32> {
10+
if (1 == 1) {
11+
return try { 5 };
12+
}
13+
14+
// test
15+
let x: Option<()> = try {
16+
// try blocks are great
17+
};
18+
19+
let y: Option<i32> = try { 6 }; // comment
20+
21+
let x: Option<i32> = try {
22+
baz()?;
23+
baz()?;
24+
baz()?;
25+
7
26+
};
27+
28+
return None;
29+
}

0 commit comments

Comments
 (0)