Skip to content

Commit 9b18cc0

Browse files
feat: support underscore expressions
1 parent affbbe4 commit 9b18cc0

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/formatting/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ pub(crate) fn format_expr(
439439
}
440440
}
441441
ast::ExprKind::Await(_) => rewrite_chain(expr, context, shape),
442+
ast::ExprKind::Underscore => Some("_".to_owned()),
442443
ast::ExprKind::Err => None,
443444
};
444445

src/formatting/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,8 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
524524
| ast::ExprKind::Ret(..)
525525
| ast::ExprKind::Tup(..)
526526
| ast::ExprKind::Type(..)
527-
| ast::ExprKind::Yield(None) => false,
527+
| ast::ExprKind::Yield(None)
528+
| ast::ExprKind::Underscore => false,
528529
}
529530
}
530531

tests/source/expr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,13 @@ fn foo() {
567567
}
568568
.await;
569569
}
570+
571+
fn underscore() {
572+
_= 1;
573+
_;
574+
[ _,a,_ ] = [1, 2, 3];
575+
(a, _) = (8, 9);
576+
TupleStruct( _, a) = TupleStruct(2, 2);
577+
578+
let _ : usize = foo(_, _);
579+
}

tests/target/expr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,13 @@ fn foo() {
661661
}
662662
.await;
663663
}
664+
665+
fn underscore() {
666+
_ = 1;
667+
_;
668+
[_, a, _] = [1, 2, 3];
669+
(a, _) = (8, 9);
670+
TupleStruct(_, a) = TupleStruct(2, 2);
671+
672+
let _: usize = foo(_, _);
673+
}

0 commit comments

Comments
 (0)