fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

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