about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/extra_unused_type_parameters.fixed12
-rw-r--r--tests/ui/extra_unused_type_parameters.rs12
-rw-r--r--tests/ui/extra_unused_type_parameters.stderr16
-rw-r--r--tests/ui/format_push_string.rs29
-rw-r--r--tests/ui/format_push_string.stderr37
-rw-r--r--tests/ui/mem_forget.rs3
-rw-r--r--tests/ui/mem_forget.stderr15
-rw-r--r--tests/ui/ptr_arg.rs33
-rw-r--r--tests/ui/ptr_arg.stderr60
-rw-r--r--tests/ui/type_repetition_in_bounds.rs24
-rw-r--r--tests/ui/type_repetition_in_bounds.stderr10
11 files changed, 218 insertions, 33 deletions
diff --git a/tests/ui/extra_unused_type_parameters.fixed b/tests/ui/extra_unused_type_parameters.fixed
index adcd1f6d407..03ac9abf498 100644
--- a/tests/ui/extra_unused_type_parameters.fixed
+++ b/tests/ui/extra_unused_type_parameters.fixed
@@ -1,8 +1,12 @@
 //@run-rustfix
+//@aux-build:proc_macros.rs
 
 #![allow(unused, clippy::needless_lifetimes)]
 #![warn(clippy::extra_unused_type_parameters)]
 
+extern crate proc_macros;
+use proc_macros::with_span;
+
 fn unused_ty(x: u8) {
     unimplemented!()
 }
@@ -102,4 +106,12 @@ mod issue10319 {
     }
 }
 
+with_span!(
+    span
+
+    fn should_not_lint<T>(x: u8) {
+        unimplemented!()
+    }
+);
+
 fn main() {}
diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs
index c4c5227ac91..731c89c18dc 100644
--- a/tests/ui/extra_unused_type_parameters.rs
+++ b/tests/ui/extra_unused_type_parameters.rs
@@ -1,8 +1,12 @@
 //@run-rustfix
+//@aux-build:proc_macros.rs
 
 #![allow(unused, clippy::needless_lifetimes)]
 #![warn(clippy::extra_unused_type_parameters)]
 
+extern crate proc_macros;
+use proc_macros::with_span;
+
 fn unused_ty<T>(x: u8) {
     unimplemented!()
 }
@@ -102,4 +106,12 @@ mod issue10319 {
     }
 }
 
+with_span!(
+    span
+
+    fn should_not_lint<T>(x: u8) {
+        unimplemented!()
+    }
+);
+
 fn main() {}
diff --git a/tests/ui/extra_unused_type_parameters.stderr b/tests/ui/extra_unused_type_parameters.stderr
index c042a5a2290..b5277d49861 100644
--- a/tests/ui/extra_unused_type_parameters.stderr
+++ b/tests/ui/extra_unused_type_parameters.stderr
@@ -1,5 +1,5 @@
 error: type parameter `T` goes unused in function definition
-  --> $DIR/extra_unused_type_parameters.rs:6:13
+  --> $DIR/extra_unused_type_parameters.rs:10:13
    |
 LL | fn unused_ty<T>(x: u8) {
    |             ^^^ help: consider removing the parameter
@@ -7,19 +7,19 @@ LL | fn unused_ty<T>(x: u8) {
    = note: `-D clippy::extra-unused-type-parameters` implied by `-D warnings`
 
 error: type parameters go unused in function definition: T, U
-  --> $DIR/extra_unused_type_parameters.rs:10:16
+  --> $DIR/extra_unused_type_parameters.rs:14:16
    |
 LL | fn unused_multi<T, U>(x: u8) {
    |                ^^^^^^ help: consider removing the parameters
 
 error: type parameter `T` goes unused in function definition
-  --> $DIR/extra_unused_type_parameters.rs:14:21
+  --> $DIR/extra_unused_type_parameters.rs:18:21
    |
 LL | fn unused_with_lt<'a, T>(x: &'a u8) {
    |                     ^^^ help: consider removing the parameter
 
 error: type parameters go unused in function definition: T, V
-  --> $DIR/extra_unused_type_parameters.rs:26:19
+  --> $DIR/extra_unused_type_parameters.rs:30:19
    |
 LL | fn unused_bounded<T: Default, U, V: Default>(x: U) {
    |                   ^^^^^^^^^^^^ ^^^^^^^^^^^^
@@ -31,7 +31,7 @@ LL + fn unused_bounded<U>(x: U) {
    |
 
 error: type parameters go unused in function definition: A, D, E
-  --> $DIR/extra_unused_type_parameters.rs:30:16
+  --> $DIR/extra_unused_type_parameters.rs:34:16
    |
 LL | fn some_unused<A, B, C, D: Iterator<Item = (B, C)>, E>(b: B, c: C) {
    |                ^^^    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,19 +43,19 @@ LL + fn some_unused<B, C>(b: B, c: C) {
    |
 
 error: type parameter `T` goes unused in function definition
-  --> $DIR/extra_unused_type_parameters.rs:55:22
+  --> $DIR/extra_unused_type_parameters.rs:59:22
    |
 LL |     fn unused_ty_impl<T>(&self) {
    |                      ^^^ help: consider removing the parameter
 
 error: type parameters go unused in function definition: A, B
-  --> $DIR/extra_unused_type_parameters.rs:77:17
+  --> $DIR/extra_unused_type_parameters.rs:81:17
    |
 LL | fn unused_opaque<A, B>(dummy: impl Default) {
    |                 ^^^^^^ help: consider removing the parameters
 
 error: type parameter `U` goes unused in function definition
-  --> $DIR/extra_unused_type_parameters.rs:90:56
+  --> $DIR/extra_unused_type_parameters.rs:94:56
    |
 LL |     fn unused_with_priv_trait_bound<T: private::Private, U>() {
    |                                                        ^^^ help: consider removing the parameter
diff --git a/tests/ui/format_push_string.rs b/tests/ui/format_push_string.rs
index 4db13d650eb..89423ffe1cf 100644
--- a/tests/ui/format_push_string.rs
+++ b/tests/ui/format_push_string.rs
@@ -5,3 +5,32 @@ fn main() {
     string += &format!("{:?}", 1234);
     string.push_str(&format!("{:?}", 5678));
 }
+
+mod issue9493 {
+    pub fn u8vec_to_hex(vector: &Vec<u8>, upper: bool) -> String {
+        let mut hex = String::with_capacity(vector.len() * 2);
+        for byte in vector {
+            hex += &(if upper {
+                format!("{byte:02X}")
+            } else {
+                format!("{byte:02x}")
+            });
+        }
+        hex
+    }
+
+    pub fn other_cases() {
+        let mut s = String::new();
+        // if let
+        s += &(if let Some(_a) = Some(1234) {
+            format!("{}", 1234)
+        } else {
+            format!("{}", 1234)
+        });
+        // match
+        s += &(match Some(1234) {
+            Some(_) => format!("{}", 1234),
+            None => format!("{}", 1234),
+        });
+    }
+}
diff --git a/tests/ui/format_push_string.stderr b/tests/ui/format_push_string.stderr
index d7be9a5f206..76762c4a1d1 100644
--- a/tests/ui/format_push_string.stderr
+++ b/tests/ui/format_push_string.stderr
@@ -15,5 +15,40 @@ LL |     string.push_str(&format!("{:?}", 5678));
    |
    = help: consider using `write!` to avoid the extra allocation
 
-error: aborting due to 2 previous errors
+error: `format!(..)` appended to existing `String`
+  --> $DIR/format_push_string.rs:13:13
+   |
+LL | /             hex += &(if upper {
+LL | |                 format!("{byte:02X}")
+LL | |             } else {
+LL | |                 format!("{byte:02x}")
+LL | |             });
+   | |______________^
+   |
+   = help: consider using `write!` to avoid the extra allocation
+
+error: `format!(..)` appended to existing `String`
+  --> $DIR/format_push_string.rs:25:9
+   |
+LL | /         s += &(if let Some(_a) = Some(1234) {
+LL | |             format!("{}", 1234)
+LL | |         } else {
+LL | |             format!("{}", 1234)
+LL | |         });
+   | |__________^
+   |
+   = help: consider using `write!` to avoid the extra allocation
+
+error: `format!(..)` appended to existing `String`
+  --> $DIR/format_push_string.rs:31:9
+   |
+LL | /         s += &(match Some(1234) {
+LL | |             Some(_) => format!("{}", 1234),
+LL | |             None => format!("{}", 1234),
+LL | |         });
+   | |__________^
+   |
+   = help: consider using `write!` to avoid the extra allocation
+
+error: aborting due to 5 previous errors
 
diff --git a/tests/ui/mem_forget.rs b/tests/ui/mem_forget.rs
index edb9d87d032..b6c8d9e53d8 100644
--- a/tests/ui/mem_forget.rs
+++ b/tests/ui/mem_forget.rs
@@ -19,5 +19,8 @@ fn main() {
     let eight: Vec<i32> = vec![8];
     forgetSomething(eight);
 
+    let string = String::new();
+    std::mem::forget(string);
+
     std::mem::forget(7);
 }
diff --git a/tests/ui/mem_forget.stderr b/tests/ui/mem_forget.stderr
index a90d8b1655d..8004b2aa8db 100644
--- a/tests/ui/mem_forget.stderr
+++ b/tests/ui/mem_forget.stderr
@@ -4,6 +4,7 @@ error: usage of `mem::forget` on `Drop` type
 LL |     memstuff::forget(six);
    |     ^^^^^^^^^^^^^^^^^^^^^
    |
+   = note: argument has type `std::sync::Arc<i32>`
    = note: `-D clippy::mem-forget` implied by `-D warnings`
 
 error: usage of `mem::forget` on `Drop` type
@@ -11,12 +12,24 @@ error: usage of `mem::forget` on `Drop` type
    |
 LL |     std::mem::forget(seven);
    |     ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: argument has type `std::rc::Rc<i32>`
 
 error: usage of `mem::forget` on `Drop` type
   --> $DIR/mem_forget.rs:20:5
    |
 LL |     forgetSomething(eight);
    |     ^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: argument has type `std::vec::Vec<i32>`
+
+error: usage of `mem::forget` on type with `Drop` fields
+  --> $DIR/mem_forget.rs:23:5
+   |
+LL |     std::mem::forget(string);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: argument has type `std::string::String`
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs
index 5f54101ca15..709f74ee6aa 100644
--- a/tests/ui/ptr_arg.rs
+++ b/tests/ui/ptr_arg.rs
@@ -1,5 +1,10 @@
 #![feature(lint_reasons)]
-#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
+#![allow(
+    unused,
+    clippy::many_single_char_names,
+    clippy::needless_lifetimes,
+    clippy::redundant_clone
+)]
 #![warn(clippy::ptr_arg)]
 
 use std::borrow::Cow;
@@ -235,3 +240,29 @@ fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
     takes_dyn(b);
     takes_dyn(c);
 }
+
+mod issue_9218 {
+    use std::borrow::Cow;
+
+    fn cow_non_elided_lifetime<'a>(input: &Cow<'a, str>) -> &'a str {
+        todo!()
+    }
+
+    // This one has an anonymous lifetime so it's not okay
+    fn cow_elided_lifetime<'a>(input: &'a Cow<str>) -> &'a str {
+        todo!()
+    }
+
+    // These two's return types don't use use 'a so it's not okay
+    fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str {
+        todo!()
+    }
+    fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
+        todo!()
+    }
+
+    // Inferred to be `&'a str`, afaik.
+    fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str {
+        todo!()
+    }
+}
diff --git a/tests/ui/ptr_arg.stderr b/tests/ui/ptr_arg.stderr
index 6b4de98ce88..d663b070b9c 100644
--- a/tests/ui/ptr_arg.stderr
+++ b/tests/ui/ptr_arg.stderr
@@ -1,5 +1,5 @@
 error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:8:14
+  --> $DIR/ptr_arg.rs:13:14
    |
 LL | fn do_vec(x: &Vec<i64>) {
    |              ^^^^^^^^^ help: change this to: `&[i64]`
@@ -7,43 +7,43 @@ LL | fn do_vec(x: &Vec<i64>) {
    = note: `-D clippy::ptr-arg` implied by `-D warnings`
 
 error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:12:18
+  --> $DIR/ptr_arg.rs:17:18
    |
 LL | fn do_vec_mut(x: &mut Vec<i64>) {
    |                  ^^^^^^^^^^^^^ help: change this to: `&mut [i64]`
 
 error: writing `&String` instead of `&str` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:16:14
+  --> $DIR/ptr_arg.rs:21:14
    |
 LL | fn do_str(x: &String) {
    |              ^^^^^^^ help: change this to: `&str`
 
 error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:20:18
+  --> $DIR/ptr_arg.rs:25:18
    |
 LL | fn do_str_mut(x: &mut String) {
    |                  ^^^^^^^^^^^ help: change this to: `&mut str`
 
 error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:24:15
+  --> $DIR/ptr_arg.rs:29:15
    |
 LL | fn do_path(x: &PathBuf) {
    |               ^^^^^^^^ help: change this to: `&Path`
 
 error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:28:19
+  --> $DIR/ptr_arg.rs:33:19
    |
 LL | fn do_path_mut(x: &mut PathBuf) {
    |                   ^^^^^^^^^^^^ help: change this to: `&mut Path`
 
 error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:36:18
+  --> $DIR/ptr_arg.rs:41:18
    |
 LL |     fn do_vec(x: &Vec<i64>);
    |                  ^^^^^^^^^ help: change this to: `&[i64]`
 
 error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:49:14
+  --> $DIR/ptr_arg.rs:54:14
    |
 LL | fn cloned(x: &Vec<u8>) -> Vec<u8> {
    |              ^^^^^^^^
@@ -60,7 +60,7 @@ LL ~     x.to_owned()
    |
 
 error: writing `&String` instead of `&str` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:58:18
+  --> $DIR/ptr_arg.rs:63:18
    |
 LL | fn str_cloned(x: &String) -> String {
    |                  ^^^^^^^
@@ -76,7 +76,7 @@ LL ~     x.to_owned()
    |
 
 error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:66:19
+  --> $DIR/ptr_arg.rs:71:19
    |
 LL | fn path_cloned(x: &PathBuf) -> PathBuf {
    |                   ^^^^^^^^
@@ -92,7 +92,7 @@ LL ~     x.to_path_buf()
    |
 
 error: writing `&String` instead of `&str` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:74:44
+  --> $DIR/ptr_arg.rs:79:44
    |
 LL | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
    |                                            ^^^^^^^
@@ -106,19 +106,19 @@ LL ~     let c = y;
    |
 
 error: using a reference to `Cow` is not recommended
-  --> $DIR/ptr_arg.rs:88:25
+  --> $DIR/ptr_arg.rs:93:25
    |
 LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
    |                         ^^^^^^^^^^^ help: change this to: `&[i32]`
 
 error: writing `&String` instead of `&str` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:117:66
+  --> $DIR/ptr_arg.rs:122:66
    |
 LL |     fn some_allowed(#[allow(clippy::ptr_arg)] _v: &Vec<u32>, _s: &String) {}
    |                                                                  ^^^^^^^ help: change this to: `&str`
 
 error: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:146:21
+  --> $DIR/ptr_arg.rs:151:21
    |
 LL |     fn foo_vec(vec: &Vec<u8>) {
    |                     ^^^^^^^^
@@ -131,7 +131,7 @@ LL ~         let _ = vec.to_owned().clone();
    |
 
 error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:151:23
+  --> $DIR/ptr_arg.rs:156:23
    |
 LL |     fn foo_path(path: &PathBuf) {
    |                       ^^^^^^^^
@@ -144,7 +144,7 @@ LL ~         let _ = path.to_path_buf().clone();
    |
 
 error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:156:21
+  --> $DIR/ptr_arg.rs:161:21
    |
 LL |     fn foo_str(str: &PathBuf) {
    |                     ^^^^^^^^
@@ -157,28 +157,46 @@ LL ~         let _ = str.to_path_buf().clone();
    |
 
 error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:162:29
+  --> $DIR/ptr_arg.rs:167:29
    |
 LL | fn mut_vec_slice_methods(v: &mut Vec<u32>) {
    |                             ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
 
 error: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:224:17
+  --> $DIR/ptr_arg.rs:229:17
    |
 LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
    |                 ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
 
 error: writing `&mut String` instead of `&mut str` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:224:35
+  --> $DIR/ptr_arg.rs:229:35
    |
 LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
    |                                   ^^^^^^^^^^^ help: change this to: `&mut str`
 
 error: writing `&mut PathBuf` instead of `&mut Path` involves a new object where a slice will do
-  --> $DIR/ptr_arg.rs:224:51
+  --> $DIR/ptr_arg.rs:229:51
    |
 LL | fn dyn_trait(a: &mut Vec<u32>, b: &mut String, c: &mut PathBuf) {
    |                                                   ^^^^^^^^^^^^ help: change this to: `&mut Path`
 
-error: aborting due to 20 previous errors
+error: using a reference to `Cow` is not recommended
+  --> $DIR/ptr_arg.rs:252:39
+   |
+LL |     fn cow_elided_lifetime<'a>(input: &'a Cow<str>) -> &'a str {
+   |                                       ^^^^^^^^^^^^ help: change this to: `&str`
+
+error: using a reference to `Cow` is not recommended
+  --> $DIR/ptr_arg.rs:257:36
+   |
+LL |     fn cow_bad_ret_ty_1<'a>(input: &'a Cow<'a, str>) -> &'static str {
+   |                                    ^^^^^^^^^^^^^^^^ help: change this to: `&str`
+
+error: using a reference to `Cow` is not recommended
+  --> $DIR/ptr_arg.rs:260:40
+   |
+LL |     fn cow_bad_ret_ty_2<'a, 'b>(input: &'a Cow<'a, str>) -> &'b str {
+   |                                        ^^^^^^^^^^^^^^^^ help: change this to: `&str`
+
+error: aborting due to 23 previous errors
 
diff --git a/tests/ui/type_repetition_in_bounds.rs b/tests/ui/type_repetition_in_bounds.rs
index 1d36f4b3c7b..874d97f7a46 100644
--- a/tests/ui/type_repetition_in_bounds.rs
+++ b/tests/ui/type_repetition_in_bounds.rs
@@ -110,4 +110,28 @@ where
 // This should not lint
 fn impl_trait(_: impl AsRef<str>, _: impl AsRef<str>) {}
 
+#[clippy::msrv = "1.14.0"]
+mod issue8772_fail {
+    pub trait Trait<X, Y, Z> {}
+
+    pub fn f<T: ?Sized, U>(arg: usize)
+    where
+        T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
+        U: Clone + Sync + 'static,
+    {
+    }
+}
+
+#[clippy::msrv = "1.15.0"]
+mod issue8772_pass {
+    pub trait Trait<X, Y, Z> {}
+
+    pub fn f<T: ?Sized, U>(arg: usize)
+    where
+        T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
+        U: Clone + Sync + 'static,
+    {
+    }
+}
+
 fn main() {}
diff --git a/tests/ui/type_repetition_in_bounds.stderr b/tests/ui/type_repetition_in_bounds.stderr
index 56867f75b07..54973c5bda5 100644
--- a/tests/ui/type_repetition_in_bounds.stderr
+++ b/tests/ui/type_repetition_in_bounds.stderr
@@ -35,5 +35,13 @@ LL |     T: ?Sized,
    |
    = help: consider combining the bounds: `T: Clone + ?Sized`
 
-error: aborting due to 4 previous errors
+error: this type has already been used as a bound predicate
+  --> $DIR/type_repetition_in_bounds.rs:131:9
+   |
+LL |         T: Trait<Option<usize>, Box<[String]>, bool> + 'static,
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: consider combining the bounds: `T: ?Sized + Trait<Option<usize>, Box<[String]>, bool>`
+
+error: aborting due to 5 previous errors