From 791f93c796f7b4f0346eee276baf6e31ed3c81ea Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Wed, 2 Sep 2020 23:39:50 -0700 Subject: [PATCH] Allow try blocks as the argument to return expressions Fixes 76271 --- compiler/rustc_ast/src/token.rs | 1 + src/test/ui/try-block/try-block-in-return.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/test/ui/try-block/try-block-in-return.rs diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index c6cc890b47f79..f3da0ec130a52 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -173,6 +173,7 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool { kw::Move, kw::Return, kw::True, + kw::Try, kw::Unsafe, kw::While, kw::Yield, diff --git a/src/test/ui/try-block/try-block-in-return.rs b/src/test/ui/try-block/try-block-in-return.rs new file mode 100644 index 0000000000000..a15bfeef1c12d --- /dev/null +++ b/src/test/ui/try-block/try-block-in-return.rs @@ -0,0 +1,12 @@ +// run-pass +// compile-flags: --edition 2018 + +#![feature(try_blocks)] + +fn issue_76271() -> Option { + return try { 4 } +} + +fn main() { + assert_eq!(issue_76271(), Some(4)); +}