Skip to content

Commit 8fae813

Browse files
authored
Rollup merge of rust-lang#76274 - scottmcm:fix-76271, r=petrochenkov
Allow try blocks as the argument to return expressions Fixes rust-lang#76271 I don't think this needs to be edition-aware (phew) since `return try` in 2015 is also the start of an expression, just with a struct literal instead of a block (`return try { x: 4, y: 5 }`).
2 parents 8bda38e + 791f93c commit 8fae813

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/rustc_ast/src/token.rs

+1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub fn ident_can_begin_expr(name: Symbol, span: Span, is_raw: bool) -> bool {
173173
kw::Move,
174174
kw::Return,
175175
kw::True,
176+
kw::Try,
176177
kw::Unsafe,
177178
kw::While,
178179
kw::Yield,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// run-pass
2+
// compile-flags: --edition 2018
3+
4+
#![feature(try_blocks)]
5+
6+
fn issue_76271() -> Option<i32> {
7+
return try { 4 }
8+
}
9+
10+
fn main() {
11+
assert_eq!(issue_76271(), Some(4));
12+
}

0 commit comments

Comments
 (0)