diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2020-09-02 23:39:50 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2020-09-02 23:39:50 -0700 |
| commit | 791f93c796f7b4f0346eee276baf6e31ed3c81ea (patch) | |
| tree | 43e0ba9fc304f896385ae8509f3546795760715b | |
| parent | 51f79b618d41b8319134827d92ccc674dab4aa32 (diff) | |
| download | rust-791f93c796f7b4f0346eee276baf6e31ed3c81ea.tar.gz rust-791f93c796f7b4f0346eee276baf6e31ed3c81ea.zip | |
Allow try blocks as the argument to return expressions
Fixes 76271
| -rw-r--r-- | compiler/rustc_ast/src/token.rs | 1 | ||||
| -rw-r--r-- | src/test/ui/try-block/try-block-in-return.rs | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index c6cc890b47f..f3da0ec130a 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 00000000000..a15bfeef1c1 --- /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<i32> { + return try { 4 } +} + +fn main() { + assert_eq!(issue_76271(), Some(4)); +} |
