]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/from_over_into.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / from_over_into.rs
1 //@run-rustfix
2
3 #![feature(type_alias_impl_trait)]
4 #![warn(clippy::from_over_into)]
5 #![allow(unused)]
6
7 // this should throw an error
8 struct StringWrapper(String);
9
10 impl Into<StringWrapper> for String {
11 fn into(self) -> StringWrapper {
12 StringWrapper(self)
13 }
14 }
15
16 struct SelfType(String);
17
18 impl Into<SelfType> for String {
19 fn into(self) -> SelfType {
20 SelfType(Self::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 Into<SelfKeywords> for X {
34 fn into(self) -> SelfKeywords {
35 let _ = Self;
36 let _ = Self::FOO;
37 let _: Self = self;
38
39 SelfKeywords
40 }
41 }
42
43 struct ExplicitPaths(bool);
44
45 impl core::convert::Into<bool> for crate::ExplicitPaths {
46 fn into(mut self) -> bool {
47 let in_closure = || self.0;
48
49 self.0 = false;
50 self.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 struct PathInExpansion;
64
65 impl Into<String> for PathInExpansion {
66 fn into(self) -> String {
67 // non self/Self paths in expansions are fine
68 panic!()
69 }
70 }
71
72 #[clippy::msrv = "1.40"]
73 fn msrv_1_40() {
74 struct FromOverInto<T>(Vec<T>);
75
76 impl<T> Into<FromOverInto<T>> for Vec<T> {
77 fn into(self) -> FromOverInto<T> {
78 FromOverInto(self)
79 }
80 }
81 }
82
83 #[clippy::msrv = "1.41"]
84 fn msrv_1_41() {
85 struct FromOverInto<T>(Vec<T>);
86
87 impl<T> Into<FromOverInto<T>> for Vec<T> {
88 fn into(self) -> FromOverInto<T> {
89 FromOverInto(self)
90 }
91 }
92 }
93
94 fn main() {}