]> git.lizzy.rs Git - rust.git/blob - tests/ui/from_over_into.fixed
e66dc43b0473edcb17a13b2120552039b48675ef
[rust.git] / tests / ui / from_over_into.fixed
1 // run-rustfix
2
3 #![warn(clippy::from_over_into)]
4 #![allow(unused)]
5
6 // this should throw an error
7 struct StringWrapper(String);
8
9 impl From<String> for StringWrapper {
10     fn from(val: String) -> Self {
11         StringWrapper(val)
12     }
13 }
14
15 struct SelfType(String);
16
17 impl From<String> for SelfType {
18     fn from(val: String) -> Self {
19         SelfType(String::new())
20     }
21 }
22
23 #[derive(Default)]
24 struct X;
25
26 impl X {
27     const FOO: &'static str = "a";
28 }
29
30 struct SelfKeywords;
31
32 impl From<X> for SelfKeywords {
33     fn from(val: X) -> Self {
34         let _ = X::default();
35         let _ = X::FOO;
36         let _: X = val;
37
38         SelfKeywords
39     }
40 }
41
42 struct ExplicitPaths(bool);
43
44 impl core::convert::From<crate::ExplicitPaths> for bool {
45     fn from(mut val: crate::ExplicitPaths) -> Self {
46         let in_closure = || val.0;
47
48         val.0 = false;
49         val.0
50     }
51 }
52
53 // this is fine
54 struct A(String);
55
56 impl From<String> for A {
57     fn from(s: String) -> A {
58         A(s)
59     }
60 }
61
62 fn main() {}