]> git.lizzy.rs Git - rust.git/blob - tests/ui/from_over_into.fixed
1cf49ca45f494d1eca6d0a02785ca04781747755
[rust.git] / tests / ui / from_over_into.fixed
1 // run-rustfix
2
3 #![feature(custom_inner_attributes)]
4 #![warn(clippy::from_over_into)]
5 #![allow(unused)]
6
7 // this should throw an error
8 struct StringWrapper(String);
9
10 impl From<String> for StringWrapper {
11     fn from(val: String) -> Self {
12         StringWrapper(val)
13     }
14 }
15
16 struct SelfType(String);
17
18 impl From<String> for SelfType {
19     fn from(val: String) -> Self {
20         SelfType(String::new())
21     }
22 }
23
24 #[derive(Default)]
25 struct X;
26
27 impl X {
28     const FOO: &'static str = "a";
29 }
30
31 struct SelfKeywords;
32
33 impl From<X> for SelfKeywords {
34     fn from(val: X) -> Self {
35         let _ = X::default();
36         let _ = X::FOO;
37         let _: X = val;
38
39         SelfKeywords
40     }
41 }
42
43 struct ExplicitPaths(bool);
44
45 impl core::convert::From<crate::ExplicitPaths> for bool {
46     fn from(mut val: crate::ExplicitPaths) -> Self {
47         let in_closure = || val.0;
48
49         val.0 = false;
50         val.0
51     }
52 }
53
54 // this is fine
55 struct A(String);
56
57 impl From<String> for A {
58     fn from(s: String) -> A {
59         A(s)
60     }
61 }
62
63 fn msrv_1_40() {
64     #![clippy::msrv = "1.40"]
65
66     struct FromOverInto<T>(Vec<T>);
67
68     impl<T> Into<FromOverInto<T>> for Vec<T> {
69         fn into(self) -> FromOverInto<T> {
70             FromOverInto(self)
71         }
72     }
73 }
74
75 fn msrv_1_41() {
76     #![clippy::msrv = "1.41"]
77
78     struct FromOverInto<T>(Vec<T>);
79
80     impl<T> From<Vec<T>> for FromOverInto<T> {
81         fn from(val: Vec<T>) -> Self {
82             FromOverInto(val)
83         }
84     }
85 }
86
87 fn main() {}