]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/unused_unit.rs
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
[rust.git] / tests / ui / unused_unit.rs
index 3930eecf1b744db2b78fdda498a97df8e4229045..e2c6afb020f5887dc175b3f8a832fb8293173637 100644 (file)
@@ -1,14 +1,4 @@
-// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// compile-pass
+// run-rustfix
 
 // The output for humans should just highlight the whole span without showing
 // the suggested replacement, but we also want to test that suggested
 // stripping away any starting or ending parenthesis characters—hence this
 // test of the JSON error format.
 
+#![feature(custom_inner_attributes)]
+#![rustfmt::skip]
 
 #![deny(clippy::unused_unit)]
-#![allow(clippy::needless_return)]
+#![allow(dead_code)]
 
 struct Unitter;
-
 impl Unitter {
-    // try to disorient the lint with multiple unit returns and newlines
-    pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
-        ()
+    #[allow(clippy::no_effect)]
+    pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) -> ()
     where G: Fn() -> () {
-        let _y: &Fn() -> () = &f;
+        let _y: &dyn Fn() -> () = &f;
         (); // this should not lint, as it's not in return type position
     }
 }
 
 impl Into<()> for Unitter {
+    #[rustfmt::skip]
     fn into(self) -> () {
         ()
     }
 }
 
+trait Trait {
+    fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
+    where
+        G: FnMut() -> (),
+        H: Fn() -> ();
+}
+
+impl Trait for Unitter {
+    fn redundant<F: FnOnce() -> (), G, H>(&self, _f: F, _g: G, _h: H)
+    where
+        G: FnMut() -> (),
+        H: Fn() -> () {}
+}
+
 fn return_unit() -> () { () }
 
+#[allow(clippy::needless_return)]
+#[allow(clippy::never_loop)]
+#[allow(clippy::unit_cmp)]
 fn main() {
     let u = Unitter;
     assert_eq!(u.get_unit(|| {}, return_unit), u.into());
@@ -49,3 +57,16 @@ fn main() {
     }
     return();
 }
+
+// https://github.com/rust-lang/rust-clippy/issues/4076
+fn foo() {
+    macro_rules! foo {
+        (recv($r:expr) -> $res:pat => $body:expr) => {
+            $body
+        }
+    }
+
+    foo! {
+        recv(rx) -> _x => ()
+    }
+}