.iter()
.filter(|arg| {
if is_unit(cx.typeck_results().expr_ty(arg)) && !is_unit_literal(arg) {
- !matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar))
+ match &arg.kind {
+ ExprKind::Block(..)
+ | ExprKind::Call(..)
+ | ExprKind::If(..)
+ | ExprKind::MethodCall(..) => true,
+ ExprKind::Match(..) => {
+ !matches!(&arg.kind, ExprKind::Match(.., MatchSource::TryDesugar))
+ },
+ _ => false,
+ }
} else {
false
}
None.or(Some(foo(2)));
// in this case, the suggestion can be inlined, no need for a surrounding block
// foo(()); foo(()) instead of { foo(()); foo(()) }
- foo(foo(()))
+ foo(foo(()));
+ foo(if true {
+ 1;
+ });
+ foo(match Some(1) {
+ Some(_) => {
+ 1;
+ },
+ None => {
+ 0;
+ },
+ });
}
fn ok() {
b.bar({ 1 });
b.bar(());
question_mark();
+ let named_unit_arg = ();
+ foo(named_unit_arg);
+ foo(if true { 1 } else { 0 });
+ foo(match Some(1) {
+ Some(_) => 1,
+ None => 0,
+ });
}
fn question_mark() -> Result<(), ()> {
error: passing a unit value to a function
--> $DIR/unit_arg.rs:62:5
|
-LL | foo(foo(()))
+LL | foo(foo(()));
| ^^^^^^^^^^^^
|
help: move the expression in front of the call and replace it with the unit literal `()`
|
LL | foo(());
-LL | foo(())
+LL | foo(());
+ |
+
+error: passing a unit value to a function
+ --> $DIR/unit_arg.rs:63:5
+ |
+LL | / foo(if true {
+LL | | 1;
+LL | | });
+ | |______^
+ |
+help: move the expression in front of the call and replace it with the unit literal `()`
+ |
+LL | if true {
+LL | 1;
+LL | };
+LL | foo(());
+ |
+
+error: passing a unit value to a function
+ --> $DIR/unit_arg.rs:66:5
|
+LL | / foo(match Some(1) {
+LL | | Some(_) => {
+LL | | 1;
+LL | | },
+... |
+LL | | },
+LL | | });
+ | |______^
+ |
+help: move the expression in front of the call and replace it with the unit literal `()`
+ |
+LL | match Some(1) {
+LL | Some(_) => {
+LL | 1;
+LL | },
+LL | None => {
+LL | 0;
+ ...
error: passing a unit value to a function
- --> $DIR/unit_arg.rs:95:5
+ --> $DIR/unit_arg.rs:113:5
|
LL | Some(foo(1))
| ^^^^^^^^^^^^
LL | Some(())
|
-error: aborting due to 10 previous errors
+error: aborting due to 12 previous errors