]> git.lizzy.rs Git - rust.git/blob - tests/ui/identity_conversion.rs
Merge pull request #3269 from rust-lang-nursery/relicense
[rust.git] / tests / ui / identity_conversion.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11 #![feature(tool_lints)]
12
13 #![deny(clippy::identity_conversion)]
14
15 fn test_generic<T: Copy>(val: T) -> T {
16     let _ = T::from(val);
17     val.into()
18 }
19
20 fn test_generic2<T: Copy + Into<i32> + Into<U>, U: From<T>>(val: T) {
21     // ok
22     let _: i32 = val.into();
23     let _: U = val.into();
24     let _ = U::from(val);
25 }
26
27 fn test_questionmark() -> Result<(), ()> {
28     {
29         let _: i32 = 0i32.into();
30         Ok(Ok(()))
31     }??;
32     Ok(())
33 }
34
35 fn main() {
36     test_generic(10i32);
37     test_generic2::<i32, i32>(10i32);
38     test_questionmark().unwrap();
39
40     let _: String = "foo".into();
41     let _: String = From::from("foo");
42     let _ = String::from("foo");
43     #[allow(clippy::identity_conversion)]
44     {
45         let _: String = "foo".into();
46         let _ = String::from("foo");
47         let _ = "".lines().into_iter();
48     }
49
50     let _: String = "foo".to_string().into();
51     let _: String = From::from("foo".to_string());
52     let _ = String::from("foo".to_string());
53     let _ = String::from(format!("A: {:04}", 123));
54     let _ = "".lines().into_iter();
55     let _ = vec![1, 2, 3].into_iter().into_iter();
56 }