From 4d9fa00fd58373f4ee19b6a45ab37e4601a8dd93 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 27 Nov 2020 21:18:39 -0600 Subject: [PATCH] feat: support underscore expressions --- src/expr.rs | 1 + src/utils.rs | 3 ++- tests/source/expr.rs | 10 ++++++++++ tests/target/expr.rs | 10 ++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/expr.rs b/src/expr.rs index 38543b70ae3..fe348bc6028 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -384,6 +384,7 @@ pub(crate) fn format_expr( } } ast::ExprKind::Await(_) => rewrite_chain(expr, context, shape), + ast::ExprKind::Underscore => Some("_".to_owned()), ast::ExprKind::Err => None, }; diff --git a/src/utils.rs b/src/utils.rs index 96d465608fa..bd419b2998b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -504,7 +504,8 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr | ast::ExprKind::Ret(..) | ast::ExprKind::Tup(..) | ast::ExprKind::Type(..) - | ast::ExprKind::Yield(None) => false, + | ast::ExprKind::Yield(None) + | ast::ExprKind::Underscore => false, } } diff --git a/tests/source/expr.rs b/tests/source/expr.rs index 8a6e6f1aa2b..21f8a4a4366 100644 --- a/tests/source/expr.rs +++ b/tests/source/expr.rs @@ -567,3 +567,13 @@ fn foo() { } .await; } + +fn underscore() { + _= 1; + _; + [ _,a,_ ] = [1, 2, 3]; + (a, _) = (8, 9); + TupleStruct( _, a) = TupleStruct(2, 2); + + let _ : usize = foo(_, _); +} diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 5d9e972066c..84df802bc70 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -659,3 +659,13 @@ fn foo() { } .await; } + +fn underscore() { + _ = 1; + _; + [_, a, _] = [1, 2, 3]; + (a, _) = (8, 9); + TupleStruct(_, a) = TupleStruct(2, 2); + + let _: usize = foo(_, _); +}