@@ -67,7 +67,6 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
6767 preorder. skip_subtree ( ) ;
6868 continue ;
6969 }
70-
7170 // In some other situations, we can fix things by just appending some tokens.
7271 let end_range = TextRange :: empty ( node. text_range ( ) . end ( ) ) ;
7372 match_ast ! {
@@ -195,6 +194,69 @@ pub(crate) fn fixup_syntax(node: &SyntaxNode) -> SyntaxFixups {
195194 } ,
196195 // FIXME: foo::
197196 // FIXME: for, match etc.
197+ ast:: MatchExpr ( it) => {
198+ if it. expr( ) . is_none( ) {
199+ let match_token = match it. match_token( ) {
200+ Some ( t) => t,
201+ None => continue
202+ } ;
203+ append. insert( match_token. into( ) , vec![
204+ SyntheticToken {
205+ kind: SyntaxKind :: IDENT ,
206+ text: "__ra_fixup" . into( ) ,
207+ range: end_range,
208+ id: EMPTY_ID
209+ } ,
210+ ] ) ;
211+ }
212+ if it. match_arm_list( ) . is_none( ) {
213+ // No match arms
214+ append. insert( node. clone( ) . into( ) , vec![
215+ SyntheticToken {
216+ kind: SyntaxKind :: L_CURLY ,
217+ text: "{" . into( ) ,
218+ range: end_range,
219+ id: EMPTY_ID ,
220+ } ,
221+ SyntheticToken {
222+ kind: SyntaxKind :: UNDERSCORE ,
223+ text: "_" . into( ) ,
224+ range: end_range,
225+ id: EMPTY_ID
226+ } ,
227+ SyntheticToken {
228+ kind: SyntaxKind :: EQ ,
229+ text: "=" . into( ) ,
230+ range: end_range,
231+ id: EMPTY_ID
232+ } ,
233+ SyntheticToken {
234+ kind: SyntaxKind :: R_ANGLE ,
235+ text: ">" . into( ) ,
236+ range: end_range,
237+ id: EMPTY_ID
238+ } ,
239+ SyntheticToken {
240+ kind: SyntaxKind :: L_CURLY ,
241+ text: "{" . into( ) ,
242+ range: end_range,
243+ id: EMPTY_ID ,
244+ } ,
245+ SyntheticToken {
246+ kind: SyntaxKind :: R_CURLY ,
247+ text: "}" . into( ) ,
248+ range: end_range,
249+ id: EMPTY_ID ,
250+ } ,
251+ SyntheticToken {
252+ kind: SyntaxKind :: R_CURLY ,
253+ text: "}" . into( ) ,
254+ range: end_range,
255+ id: EMPTY_ID ,
256+ } ,
257+ ] ) ;
258+ }
259+ } ,
198260 _ => ( ) ,
199261 }
200262 }
@@ -287,6 +349,53 @@ mod tests {
287349 assert_eq ! ( tt. to_string( ) , original_as_tt. to_string( ) ) ;
288350 }
289351
352+
353+ #[ test]
354+ fn match_no_expr_no_arms ( ) {
355+ check (
356+ r#"
357+ fn foo() {
358+ match
359+ }
360+ "# ,
361+ expect ! [ [ r#"
362+ fn foo () {match __ra_fixup {_ => {}}}
363+ "# ] ] ,
364+ )
365+ }
366+
367+ #[ test]
368+ fn match_expr_no_arms ( ) {
369+ check (
370+ r#"
371+ fn foo() {
372+ match x {
373+
374+ }
375+ }
376+ "# ,
377+ expect ! [ [ r#"
378+ fn foo () {match x {}}
379+ "# ] ] ,
380+ )
381+ }
382+
383+ #[ test]
384+ fn match_no_expr ( ) {
385+ check (
386+ r#"
387+ fn foo() {
388+ match {
389+ _ => {}
390+ }
391+ }
392+ "# ,
393+ expect ! [ [ r#"
394+ fn foo () {match __ra_fixup {_ => {}}}
395+ "# ] ] ,
396+ )
397+ }
398+
290399 #[ test]
291400 fn incomplete_field_expr_1 ( ) {
292401 check (
0 commit comments