]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/unit_arg.rs
Addition `manual_map` test for `unsafe` blocks
[rust.git] / tests / ui / unit_arg.rs
index c15b0a50045565b691a751af079e54211030e052..535683729f686a965f7aab4618adae726a9c6aee 100644 (file)
@@ -1,6 +1,14 @@
-// run-rustfix
 #![warn(clippy::unit_arg)]
-#![allow(clippy::no_effect, unused_must_use)]
+#![allow(
+    clippy::no_effect,
+    unused_must_use,
+    unused_variables,
+    clippy::unused_unit,
+    clippy::unnecessary_wraps,
+    clippy::or_fun_call,
+    clippy::needless_question_mark,
+    clippy::self_named_constructors
+)]
 
 use std::fmt::Debug;
 
@@ -20,8 +28,31 @@ fn bar<T: Debug>(&self, t: T) {
     }
 }
 
+fn baz<T: Debug>(t: T) {
+    foo(t);
+}
+
+trait Tr {
+    type Args;
+    fn do_it(args: Self::Args);
+}
+
+struct A;
+impl Tr for A {
+    type Args = ();
+    fn do_it(_: Self::Args) {}
+}
+
+struct B;
+impl Tr for B {
+    type Args = <A as Tr>::Args;
+
+    fn do_it(args: Self::Args) {
+        A::do_it(args)
+    }
+}
+
 fn bad() {
-    foo({});
     foo({
         1;
     });
@@ -30,11 +61,30 @@ fn bad() {
         foo(1);
         foo(2);
     });
-    foo3({}, 2, 2);
     let b = Bar;
     b.bar({
         1;
     });
+    taking_multiple_units(foo(0), foo(1));
+    taking_multiple_units(foo(0), {
+        foo(1);
+        foo(2);
+    });
+    taking_multiple_units(
+        {
+            foo(0);
+            foo(1);
+        },
+        {
+            foo(2);
+            foo(3);
+        },
+    );
+    // here Some(foo(2)) isn't the top level statement expression, wrap the suggestion in a block
+    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(()));
 }
 
 fn ok() {
@@ -46,6 +96,10 @@ fn ok() {
     b.bar({ 1 });
     b.bar(());
     question_mark();
+    let named_unit_arg = ();
+    foo(named_unit_arg);
+    baz(());
+    B::do_it(());
 }
 
 fn question_mark() -> Result<(), ()> {
@@ -65,6 +119,13 @@ fn fallible() -> Result<(), i32> {
     }
 }
 
+#[allow(dead_code)]
+fn returning_expr() -> Option<()> {
+    Some(foo(1))
+}
+
+fn taking_multiple_units(a: (), b: ()) {}
+
 fn main() {
     bad();
     ok();