]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/needless_pass_by_value.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / needless_pass_by_value.rs
index 783386fab019c95997a73f9fbc3dc4e44efc11df..d79ad86b1948caa3eff6b7516b2b9f4ec6d2a453 100644 (file)
@@ -1,10 +1,17 @@
-#![feature(tool_lints)]
-
 #![warn(clippy::needless_pass_by_value)]
-#![allow(dead_code, clippy::single_match, clippy::if_let_redundant_pattern_matching, clippy::many_single_char_names, clippy::option_option)]
+#![allow(dead_code)]
+#![allow(
+    clippy::option_option,
+    clippy::redundant_clone,
+    clippy::redundant_pattern_matching,
+    clippy::single_match,
+    clippy::uninlined_format_args
+)]
 
 use std::borrow::Borrow;
+use std::collections::HashSet;
 use std::convert::AsRef;
+use std::mem::MaybeUninit;
 
 // `v` should be warned
 // `w`, `x` and `y` are allowed (moved or mutated)
@@ -82,24 +89,19 @@ fn issue_2114(s: String, t: String, u: Vec<i32>, v: Vec<i32>) {
 
 impl<T: Serialize, U> S<T, U> {
     fn foo(
-        self, // taking `self` by value is always allowed
+        self,
+        // taking `self` by value is always allowed
         s: String,
         t: String,
     ) -> usize {
         s.len() + t.capacity()
     }
 
-    fn bar(
-        _t: T, // Ok, since `&T: Serialize` too
+    fn bar(_t: T, // Ok, since `&T: Serialize` too
     ) {
     }
 
-    fn baz(
-        &self,
-        _u: U,
-        _s: Self,
-    ) {
-    }
+    fn baz(&self, _u: U, _s: Self) {}
 }
 
 trait FalsePositive {
@@ -110,9 +112,11 @@ fn visit_string(s: String) {
 }
 
 // shouldn't warn on extern funcs
-extern "C" fn ext(x: String) -> usize { x.len() }
+extern "C" fn ext(x: MaybeUninit<usize>) -> usize {
+    unsafe { x.assume_init() }
+}
 
-// whitelist RangeArgument
+// exempt RangeArgument
 fn range<T: ::std::ops::RangeBounds<usize>>(range: T) {
     let _ = range.start_bound();
 }
@@ -134,4 +138,24 @@ fn test_destructure_copy(x: CopyWrapper, y: CopyWrapper, z: CopyWrapper) {
     println!("{}", t);
 }
 
-fn main() {}
+// The following 3 lines should not cause an ICE. See #2831
+trait Bar<'a, A> {}
+impl<'b, T> Bar<'b, T> for T {}
+fn some_fun<'b, S: Bar<'b, ()>>(_item: S) {}
+
+// Also this should not cause an ICE. See #2831
+trait Club<'a, A> {}
+impl<T> Club<'static, T> for T {}
+fn more_fun(_item: impl Club<'static, i32>) {}
+
+fn is_sync<T>(_: T)
+where
+    T: Sync,
+{
+}
+
+fn main() {
+    // This should not cause an ICE either
+    // https://github.com/rust-lang/rust-clippy/issues/3144
+    is_sync(HashSet::<usize>::new());
+}