Skip to content

Commit 4d9fa00

Browse files
feat: support underscore expressions
1 parent 5c0673c commit 4d9fa00

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ pub(crate) fn format_expr(
384384
}
385385
}
386386
ast::ExprKind::Await(_) => rewrite_chain(expr, context, shape),
387+
ast::ExprKind::Underscore => Some("_".to_owned()),
387388
ast::ExprKind::Err => None,
388389
};
389390

src/utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
504504
| ast::ExprKind::Ret(..)
505505
| ast::ExprKind::Tup(..)
506506
| ast::ExprKind::Type(..)
507-
| ast::ExprKind::Yield(None) => false,
507+
| ast::ExprKind::Yield(None)
508+
| ast::ExprKind::Underscore => false,
508509
}
509510
}
510511

tests/source/expr.rs

+10
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

+10
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,13 @@ fn foo() {
659659
}
660660
.await;
661661
}
662+
663+
fn underscore() {
664+
_ = 1;
665+
_;
666+
[_, a, _] = [1, 2, 3];
667+
(a, _) = (8, 9);
668+
TupleStruct(_, a) = TupleStruct(2, 2);
669+
670+
let _: usize = foo(_, _);
671+
}

0 commit comments

Comments
 (0)