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(_, _); +}