diff options
| author | Caleb Cartwright <caleb.cartwright@outlook.com> | 2020-11-27 21:18:39 -0600 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2020-11-28 17:41:21 -0600 |
| commit | 4d9fa00fd58373f4ee19b6a45ab37e4601a8dd93 (patch) | |
| tree | e65ec62f52738cdd4ad0c8414299aab00e6cad14 | |
| parent | 5c0673c371b4306e1e7fda8455af6fa3085a4627 (diff) | |
| download | rust-4d9fa00fd58373f4ee19b6a45ab37e4601a8dd93.tar.gz rust-4d9fa00fd58373f4ee19b6a45ab37e4601a8dd93.zip | |
feat: support underscore expressions
| -rw-r--r-- | src/expr.rs | 1 | ||||
| -rw-r--r-- | src/utils.rs | 3 | ||||
| -rw-r--r-- | tests/source/expr.rs | 10 | ||||
| -rw-r--r-- | tests/target/expr.rs | 10 |
4 files changed, 23 insertions, 1 deletions
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(_, _); +} |
