From 278e8da33b779c422ef6e1913eabfd15e5dfe50d Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Mon, 12 Oct 2020 21:43:04 -0700 Subject: [PATCH] Add some basic tests for `try{}` expressions They failed to parse in rustfmt on me in https://github.com/rust-lang/rust/pull/77877, which looks like it's since been fixed, but I figured I'd send in some tests anyway. --- tests/source/try_block.rs | 30 ++++++++++++++++++++++++++++++ tests/target/try_block.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/source/try_block.rs create mode 100644 tests/target/try_block.rs 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; +}