diff --git a/tests/source/try_block.rs b/tests/source/try_block.rs new file mode 100644 index 00000000000..2e8d61f7e66 --- /dev/null +++ b/tests/source/try_block.rs @@ -0,0 +1,30 @@ +// rustfmt-edition: 2018 + +fn main() -> Result<(), !> { + let _x: Option<_> = try { + 4 + }; + + try {} +} + +fn baz() -> Option { + if (1 == 1) { + return try { + 5 + }; + } + + // test + let x: Option<()> = try { + // try blocks are great + }; + + let y: Option = try { + 6 + }; // comment + + let x: Option = try { baz()?; baz()?; baz()?; 7 }; + + return None; +} diff --git a/tests/target/try_block.rs b/tests/target/try_block.rs new file mode 100644 index 00000000000..19a3f3e1487 --- /dev/null +++ b/tests/target/try_block.rs @@ -0,0 +1,29 @@ +// rustfmt-edition: 2018 + +fn main() -> Result<(), !> { + let _x: Option<_> = try { 4 }; + + try {} +} + +fn baz() -> Option { + if (1 == 1) { + return try { 5 }; + } + + // test + let x: Option<()> = try { + // try blocks are great + }; + + let y: Option = try { 6 }; // comment + + let x: Option = try { + baz()?; + baz()?; + baz()?; + 7 + }; + + return None; +}