Skip to content

Commit 009e6ce

Browse files
bors[bot]matklad
andauthored
Merge #10360
10360: headsup: matklad rewrites blocks grammar again :) r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents c51a3c7 + 2bf8192 commit 009e6ce

File tree

233 files changed

+11762
-11343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+11762
-11343
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir/src/semantics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<'db> SemanticsImpl<'db> {
698698
ast::ForExpr(it) => it.label(),
699699
ast::WhileExpr(it) => it.label(),
700700
ast::LoopExpr(it) => it.label(),
701-
ast::EffectExpr(it) => it.label(),
701+
ast::BlockExpr(it) => it.label(),
702702
_ => None,
703703
}
704704
};

crates/hir_def/src/attr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ fn inner_attributes(
524524
},
525525
ast::Fn(it) => {
526526
let body = it.body()?;
527-
(body.attrs(), ast::CommentIter::from_syntax_node(body.syntax()))
527+
let stmt_list = body.stmt_list()?;
528+
(stmt_list.attrs(), ast::CommentIter::from_syntax_node(body.syntax()))
528529
},
529530
ast::Impl(it) => {
530531
let assoc_item_list = it.assoc_item_list()?;

crates/hir_def/src/body/lower.rs

+17-23
Original file line numberDiff line numberDiff line change
@@ -245,43 +245,37 @@ impl ExprCollector<'_> {
245245

246246
self.alloc_expr(Expr::If { condition, then_branch, else_branch }, syntax_ptr)
247247
}
248-
ast::Expr::EffectExpr(e) => match e.effect() {
249-
ast::Effect::Try(_) => {
250-
let body = self.collect_block_opt(e.block_expr());
248+
ast::Expr::BlockExpr(e) => match e.modifier() {
249+
Some(ast::BlockModifier::Try(_)) => {
250+
let body = self.collect_block(e);
251251
self.alloc_expr(Expr::TryBlock { body }, syntax_ptr)
252252
}
253-
ast::Effect::Unsafe(_) => {
254-
let body = self.collect_block_opt(e.block_expr());
253+
Some(ast::BlockModifier::Unsafe(_)) => {
254+
let body = self.collect_block(e);
255255
self.alloc_expr(Expr::Unsafe { body }, syntax_ptr)
256256
}
257257
// FIXME: we need to record these effects somewhere...
258-
ast::Effect::Label(label) => {
258+
Some(ast::BlockModifier::Label(label)) => {
259259
let label = self.collect_label(label);
260-
match e.block_expr() {
261-
Some(block) => {
262-
let res = self.collect_block(block);
263-
match &mut self.body.exprs[res] {
264-
Expr::Block { label: block_label, .. } => {
265-
*block_label = Some(label);
266-
}
267-
_ => unreachable!(),
268-
}
269-
res
260+
let res = self.collect_block(e);
261+
match &mut self.body.exprs[res] {
262+
Expr::Block { label: block_label, .. } => {
263+
*block_label = Some(label);
270264
}
271-
None => self.missing_expr(),
265+
_ => unreachable!(),
272266
}
267+
res
273268
}
274-
// FIXME: we need to record these effects somewhere...
275-
ast::Effect::Async(_) => {
276-
let body = self.collect_block_opt(e.block_expr());
269+
Some(ast::BlockModifier::Async(_)) => {
270+
let body = self.collect_block(e);
277271
self.alloc_expr(Expr::Async { body }, syntax_ptr)
278272
}
279-
ast::Effect::Const(_) => {
280-
let body = self.collect_block_opt(e.block_expr());
273+
Some(ast::BlockModifier::Const(_)) => {
274+
let body = self.collect_block(e);
281275
self.alloc_expr(Expr::Const { body }, syntax_ptr)
282276
}
277+
None => self.collect_block(e),
283278
},
284-
ast::Expr::BlockExpr(e) => self.collect_block(e),
285279
ast::Expr::LoopExpr(e) => {
286280
let label = e.label().map(|label| self.collect_label(label));
287281
let body = self.collect_block_opt(e.loop_body());

crates/hir_expand/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ impl ExpandTo {
721721

722722
match parent.kind() {
723723
MACRO_ITEMS | SOURCE_FILE | ITEM_LIST => ExpandTo::Items,
724-
MACRO_STMTS | EXPR_STMT | BLOCK_EXPR => ExpandTo::Statements,
724+
MACRO_STMTS | EXPR_STMT | STMT_LIST => ExpandTo::Statements,
725725
MACRO_PAT => ExpandTo::Pattern,
726726
MACRO_TYPE => ExpandTo::Type,
727727

crates/hir_ty/src/tests/method_resolution.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -1083,30 +1083,30 @@ fn dyn_trait_super_trait_not_in_scope() {
10831083
fn method_resolution_foreign_opaque_type() {
10841084
check_infer(
10851085
r#"
1086-
extern "C" {
1087-
type S;
1088-
fn f() -> &'static S;
1089-
}
1086+
extern "C" {
1087+
type S;
1088+
fn f() -> &'static S;
1089+
}
10901090
1091-
impl S {
1092-
fn foo(&self) -> bool {
1093-
true
1094-
}
1095-
}
1091+
impl S {
1092+
fn foo(&self) -> bool {
1093+
true
1094+
}
1095+
}
10961096
1097-
fn test() {
1098-
let s = unsafe { f() };
1099-
s.foo();
1100-
}
1101-
"#,
1097+
fn test() {
1098+
let s = unsafe { f() };
1099+
s.foo();
1100+
}
1101+
"#,
11021102
expect![[r#"
11031103
75..79 'self': &S
11041104
89..109 '{ ... }': bool
11051105
99..103 'true': bool
11061106
123..167 '{ ...o(); }': ()
11071107
133..134 's': &S
11081108
137..151 'unsafe { f() }': &S
1109-
144..151 '{ f() }': &S
1109+
137..151 'unsafe { f() }': &S
11101110
146..147 'f': fn f() -> &S
11111111
146..149 'f()': &S
11121112
157..158 's': &S

crates/hir_ty/src/tests/simple.rs

+37-37
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ unsafe fn baz(u: MyUnion) {
352352
71..89 'MyUnio...o: 0 }': MyUnion
353353
86..87 '0': u32
354354
95..113 'unsafe...(u); }': ()
355-
102..113 '{ baz(u); }': ()
355+
95..113 'unsafe...(u); }': ()
356356
104..107 'baz': fn baz(MyUnion)
357357
104..110 'baz(u)': ()
358358
108..109 'u': MyUnion
359359
122..123 'u': MyUnion
360360
126..146 'MyUnio... 0.0 }': MyUnion
361361
141..144 '0.0': f32
362362
152..170 'unsafe...(u); }': ()
363-
159..170 '{ baz(u); }': ()
363+
152..170 'unsafe...(u); }': ()
364364
161..164 'baz': fn baz(MyUnion)
365365
161..167 'baz(u)': ()
366366
165..166 'u': MyUnion
@@ -1914,41 +1914,41 @@ fn fn_pointer_return() {
19141914
}
19151915

19161916
#[test]
1917-
fn effects_smoke_test() {
1917+
fn block_modifiers_smoke_test() {
19181918
check_infer(
19191919
r#"
1920-
//- minicore: future
1921-
async fn main() {
1922-
let x = unsafe { 92 };
1923-
let y = async { async { () }.await };
1924-
let z = try { () };
1925-
let w = const { 92 };
1926-
let t = 'a: { 92 };
1927-
}
1920+
//- minicore: future
1921+
async fn main() {
1922+
let x = unsafe { 92 };
1923+
let y = async { async { () }.await };
1924+
let z = try { () };
1925+
let w = const { 92 };
1926+
let t = 'a: { 92 };
1927+
}
19281928
"#,
19291929
expect![[r#"
19301930
16..162 '{ ...2 }; }': ()
19311931
26..27 'x': i32
19321932
30..43 'unsafe { 92 }': i32
1933-
37..43 '{ 92 }': i32
1933+
30..43 'unsafe { 92 }': i32
19341934
39..41 '92': i32
19351935
53..54 'y': impl Future<Output = ()>
1936+
57..85 'async ...wait }': ()
19361937
57..85 'async ...wait }': impl Future<Output = ()>
1937-
63..85 '{ asyn...wait }': ()
1938+
65..77 'async { () }': ()
19381939
65..77 'async { () }': impl Future<Output = ()>
19391940
65..83 'async ....await': ()
1940-
71..77 '{ () }': ()
19411941
73..75 '()': ()
19421942
95..96 'z': {unknown}
1943+
99..109 'try { () }': ()
19431944
99..109 'try { () }': {unknown}
1944-
103..109 '{ () }': ()
19451945
105..107 '()': ()
19461946
119..120 'w': i32
19471947
123..135 'const { 92 }': i32
1948-
129..135 '{ 92 }': i32
1948+
123..135 'const { 92 }': i32
19491949
131..133 '92': i32
19501950
145..146 't': i32
1951-
153..159 '{ 92 }': i32
1951+
149..159 ''a: { 92 }': i32
19521952
155..157 '92': i32
19531953
"#]],
19541954
)
@@ -2104,32 +2104,32 @@ fn infer_labelled_break_with_val() {
21042104
fn infer_labelled_block_break_with_val() {
21052105
check_infer(
21062106
r#"
2107-
fn default<T>() -> T { loop {} }
2108-
fn foo() {
2109-
let _x = 'outer: {
2110-
let inner = 'inner: {
2111-
let i = default();
2112-
if (break 'outer i) {
2113-
break 'inner 5i8;
2114-
} else if true {
2115-
break 'inner 6;
2116-
}
2117-
break 'inner 'innermost: { 0 };
2118-
42
2119-
};
2120-
break 'outer inner < 8;
2121-
};
2122-
}
2123-
"#,
2107+
fn default<T>() -> T { loop {} }
2108+
fn foo() {
2109+
let _x = 'outer: {
2110+
let inner = 'inner: {
2111+
let i = default();
2112+
if (break 'outer i) {
2113+
break 'inner 5i8;
2114+
} else if true {
2115+
break 'inner 6;
2116+
}
2117+
break 'inner 'innermost: { 0 };
2118+
42
2119+
};
2120+
break 'outer inner < 8;
2121+
};
2122+
}
2123+
"#,
21242124
expect![[r#"
21252125
21..32 '{ loop {} }': T
21262126
23..30 'loop {}': !
21272127
28..30 '{}': ()
21282128
42..381 '{ ... }; }': ()
21292129
52..54 '_x': bool
2130-
65..378 '{ ... }': bool
2130+
57..378 ''outer... }': bool
21312131
79..84 'inner': i8
2132-
95..339 '{ ... }': i8
2132+
87..339 ''inner... }': i8
21332133
113..114 'i': bool
21342134
117..124 'default': fn default<bool>() -> bool
21352135
117..126 'default()': bool
@@ -2145,7 +2145,7 @@ fn infer_labelled_block_break_with_val() {
21452145
241..255 'break 'inner 6': !
21462146
254..255 '6': i8
21472147
283..313 'break ... { 0 }': !
2148-
308..313 '{ 0 }': i8
2148+
296..313 ''inner... { 0 }': i8
21492149
310..311 '0': i8
21502150
327..329 '42': i8
21512151
349..371 'break ...er < 8': !

crates/ide/src/highlight_related.rs

+15-10
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ fn highlight_exit_points(
164164
match anc {
165165
ast::Fn(fn_) => hl(sema, fn_.body().map(ast::Expr::BlockExpr)),
166166
ast::ClosureExpr(closure) => hl(sema, closure.body()),
167-
ast::EffectExpr(effect) => if matches!(effect.effect(), ast::Effect::Async(_) | ast::Effect::Try(_)| ast::Effect::Const(_)) {
168-
hl(sema, effect.block_expr().map(ast::Expr::BlockExpr))
167+
ast::BlockExpr(block_expr) => if matches!(block_expr.modifier(), Some(ast::BlockModifier::Async(_) | ast::BlockModifier::Try(_)| ast::BlockModifier::Const(_))) {
168+
hl(sema, Some(block_expr.into()))
169169
} else {
170170
continue;
171171
},
@@ -180,7 +180,7 @@ fn highlight_break_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
180180
fn hl(
181181
token: Option<SyntaxToken>,
182182
label: Option<ast::Label>,
183-
body: Option<ast::BlockExpr>,
183+
body: Option<ast::StmtList>,
184184
) -> Option<Vec<HighlightedRange>> {
185185
let mut highlights = Vec::new();
186186
let range = cover_range(
@@ -204,7 +204,7 @@ fn highlight_break_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
204204
ast::LoopExpr(l) => l.label().and_then(|it| it.lifetime()),
205205
ast::ForExpr(f) => f.label().and_then(|it| it.lifetime()),
206206
ast::WhileExpr(w) => w.label().and_then(|it| it.lifetime()),
207-
ast::EffectExpr(b) => Some(b.label().and_then(|it| it.lifetime())?),
207+
ast::BlockExpr(b) => Some(b.label().and_then(|it| it.lifetime())?),
208208
_ => return None,
209209
}
210210
};
@@ -218,16 +218,16 @@ fn highlight_break_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
218218
for anc in token.ancestors().flat_map(ast::Expr::cast) {
219219
return match anc {
220220
ast::Expr::LoopExpr(l) if label_matches(l.label()) => {
221-
hl(l.loop_token(), l.label(), l.loop_body())
221+
hl(l.loop_token(), l.label(), l.loop_body().and_then(|it| it.stmt_list()))
222222
}
223223
ast::Expr::ForExpr(f) if label_matches(f.label()) => {
224-
hl(f.for_token(), f.label(), f.loop_body())
224+
hl(f.for_token(), f.label(), f.loop_body().and_then(|it| it.stmt_list()))
225225
}
226226
ast::Expr::WhileExpr(w) if label_matches(w.label()) => {
227-
hl(w.while_token(), w.label(), w.loop_body())
227+
hl(w.while_token(), w.label(), w.loop_body().and_then(|it| it.stmt_list()))
228228
}
229-
ast::Expr::EffectExpr(e) if e.label().is_some() && label_matches(e.label()) => {
230-
hl(None, e.label(), e.block_expr())
229+
ast::Expr::BlockExpr(e) if e.label().is_some() && label_matches(e.label()) => {
230+
hl(None, e.label(), e.stmt_list())
231231
}
232232
_ => continue,
233233
};
@@ -258,7 +258,12 @@ fn highlight_yield_points(token: SyntaxToken) -> Option<Vec<HighlightedRange>> {
258258
return match_ast! {
259259
match anc {
260260
ast::Fn(fn_) => hl(fn_.async_token(), fn_.body().map(ast::Expr::BlockExpr)),
261-
ast::EffectExpr(effect) => hl(effect.async_token(), effect.block_expr().map(ast::Expr::BlockExpr)),
261+
ast::BlockExpr(block_expr) => {
262+
if block_expr.async_token().is_none() {
263+
continue;
264+
}
265+
hl(block_expr.async_token(), Some(block_expr.into()))
266+
},
262267
ast::ClosureExpr(closure) => hl(closure.async_token(), closure.body()),
263268
_ => continue,
264269
}

crates/ide/src/hover/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ pub(super) fn try_expr(
8686
ast::Fn(fn_) => sema.to_def(&fn_)?.ret_type(sema.db),
8787
ast::Item(__) => return None,
8888
ast::ClosureExpr(closure) => sema.type_of_expr(&closure.body()?)?.original,
89-
ast::EffectExpr(effect) => if matches!(effect.effect(), ast::Effect::Async(_) | ast::Effect::Try(_)| ast::Effect::Const(_)) {
90-
sema.type_of_expr(&effect.block_expr()?.into())?.original
89+
ast::BlockExpr(block_expr) => if matches!(block_expr.modifier(), Some(ast::BlockModifier::Async(_) | ast::BlockModifier::Try(_)| ast::BlockModifier::Const(_))) {
90+
sema.type_of_expr(&block_expr.into())?.original
9191
} else {
9292
continue;
9393
},

crates/ide/src/join_lines.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ fn remove_newline(
212212
}
213213

214214
fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> {
215-
let block_expr = ast::BlockExpr::cast(token.parent()?)?;
215+
let block_expr = ast::BlockExpr::cast(token.ancestors().nth(1)?)?;
216216
if !block_expr.is_standalone() {
217217
return None;
218218
}

0 commit comments

Comments
 (0)