1 #![deny(clippy::useless_conversion)]
3 fn test_generic<T: Copy>(val: T) -> T {
4 let _ = T::try_from(val).unwrap();
5 val.try_into().unwrap()
8 fn test_generic2<T: Copy + Into<i32> + Into<U>, U: From<T>>(val: T) {
10 let _: i32 = val.try_into().unwrap();
11 let _: U = val.try_into().unwrap();
12 let _ = U::try_from(val).unwrap();
17 test_generic2::<i32, i32>(10i32);
19 let _: String = "foo".try_into().unwrap();
20 let _: String = TryFrom::try_from("foo").unwrap();
21 let _ = String::try_from("foo").unwrap();
22 #[allow(clippy::useless_conversion)]
24 let _ = String::try_from("foo").unwrap();
25 let _: String = "foo".try_into().unwrap();
27 let _: String = "foo".to_string().try_into().unwrap();
28 let _: String = TryFrom::try_from("foo".to_string()).unwrap();
29 let _ = String::try_from("foo".to_string()).unwrap();
30 let _ = String::try_from(format!("A: {:04}", 123)).unwrap();
31 let _: String = format!("Hello {}", "world").try_into().unwrap();
32 let _: String = "".to_owned().try_into().unwrap();
33 let _: String = match String::from("_").try_into() {
37 // FIXME this is a false negative
38 #[allow(clippy::cmp_owned)]
39 if String::from("a") == TryInto::<String>::try_into(String::from("a")).unwrap() {}