Skip to content

Commit 7b962d7

Browse files
Support interpolated block for try and async
1 parent 8164cdb commit 7b962d7

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

compiler/rustc_parse/src/parser/expr.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -3003,7 +3003,8 @@ impl<'a> Parser<'a> {
30033003
fn is_do_catch_block(&self) -> bool {
30043004
self.token.is_keyword(kw::Do)
30053005
&& self.is_keyword_ahead(1, &[kw::Catch])
3006-
&& self.look_ahead(2, |t| *t == token::OpenDelim(Delimiter::Brace))
3006+
&& self
3007+
.look_ahead(2, |t| *t == token::OpenDelim(Delimiter::Brace) || t.is_whole_block())
30073008
&& !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
30083009
}
30093010

@@ -3013,7 +3014,8 @@ impl<'a> Parser<'a> {
30133014

30143015
fn is_try_block(&self) -> bool {
30153016
self.token.is_keyword(kw::Try)
3016-
&& self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace))
3017+
&& self
3018+
.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace) || t.is_whole_block())
30173019
&& self.token.uninterpolated_span().at_least_rust_2018()
30183020
}
30193021

@@ -3032,10 +3034,14 @@ impl<'a> Parser<'a> {
30323034
&& ((
30333035
// `async move {`
30343036
self.is_keyword_ahead(1, &[kw::Move])
3035-
&& self.look_ahead(2, |t| *t == token::OpenDelim(Delimiter::Brace))
3037+
&& self.look_ahead(2, |t| {
3038+
*t == token::OpenDelim(Delimiter::Brace) || t.is_whole_block()
3039+
})
30363040
) || (
30373041
// `async {`
3038-
self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace))
3042+
self.look_ahead(1, |t| {
3043+
*t == token::OpenDelim(Delimiter::Brace) || t.is_whole_block()
3044+
})
30393045
))
30403046
}
30413047

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// check-pass
2+
// edition:2021
3+
4+
macro_rules! create_async {
5+
($body:block) => {
6+
async $body
7+
};
8+
}
9+
10+
async fn other() {}
11+
12+
fn main() {
13+
let y = create_async! {{
14+
other().await;
15+
}};
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// check-pass
2+
// edition:2021
3+
4+
#![feature(try_blocks)]
5+
6+
macro_rules! create_try {
7+
($body:block) => {
8+
try $body
9+
};
10+
}
11+
12+
fn main() {
13+
let x: Option<&str> = create_try! {{
14+
None?;
15+
"Hello world"
16+
}};
17+
18+
println!("{x:?}");
19+
}

0 commit comments

Comments
 (0)