@@ -339,21 +339,28 @@ pub fn tail_only_block_expr(tail_expr: ast::Expr) -> ast::BlockExpr {
339339}
340340
341341/// Ideally this function wouldn't exist since it involves manual indenting.
342- /// It differs from `make::block_expr` by also supporting comments.
342+ /// It differs from `make::block_expr` by also supporting comments and whitespace .
343343///
344344/// FIXME: replace usages of this with the mutable syntax tree API
345- pub fn hacky_block_expr_with_comments (
345+ pub fn hacky_block_expr (
346346 elements : impl IntoIterator < Item = crate :: SyntaxElement > ,
347347 tail_expr : Option < ast:: Expr > ,
348348) -> ast:: BlockExpr {
349349 let mut buf = "{\n " . to_string ( ) ;
350350 for node_or_token in elements. into_iter ( ) {
351351 match node_or_token {
352352 rowan:: NodeOrToken :: Node ( n) => format_to ! ( buf, " {n}\n " ) ,
353- rowan:: NodeOrToken :: Token ( t) if t. kind ( ) == SyntaxKind :: COMMENT => {
354- format_to ! ( buf, " {t}\n " )
353+ rowan:: NodeOrToken :: Token ( t) => {
354+ let kind = t. kind ( ) ;
355+ if kind == SyntaxKind :: COMMENT {
356+ format_to ! ( buf, " {t}\n " )
357+ } else if kind == SyntaxKind :: WHITESPACE {
358+ let content = t. text ( ) . trim_matches ( |c| c != '\n' ) ;
359+ if content. len ( ) >= 1 {
360+ format_to ! ( buf, "{}" , & content[ 1 ..] )
361+ }
362+ }
355363 }
356- _ => ( ) ,
357364 }
358365 }
359366 if let Some ( tail_expr) = tail_expr {
0 commit comments