]> git.lizzy.rs Git - rust.git/blob - tests/ui/from_over_into.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / from_over_into.rs
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 Into<StringWrapper> for String {
10     fn into(self) -> StringWrapper {
11         StringWrapper(self)
12     }
13 }
14
15 struct SelfType(String);
16
17 impl Into<SelfType> for String {
18     fn into(self) -> SelfType {
19         SelfType(Self::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 Into<SelfKeywords> for X {
33     fn into(self) -> SelfKeywords {
34         let _ = Self::default();
35         let _ = Self::FOO;
36         let _: Self = self;
37
38         SelfKeywords
39     }
40 }
41
42 struct ExplicitPaths(bool);
43
44 impl core::convert::Into<bool> for crate::ExplicitPaths {
45     fn into(mut self) -> bool {
46         let in_closure = || self.0;
47
48         self.0 = false;
49         self.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() {}