summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/from_over_into.rs
blob: 965f4d5d7859ee47484ccc12da79112bbc743fad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// run-rustfix

#![feature(type_alias_impl_trait)]
#![warn(clippy::from_over_into)]
#![allow(unused)]

// this should throw an error
struct StringWrapper(String);

impl Into<StringWrapper> for String {
    fn into(self) -> StringWrapper {
        StringWrapper(self)
    }
}

struct SelfType(String);

impl Into<SelfType> for String {
    fn into(self) -> SelfType {
        SelfType(Self::new())
    }
}

#[derive(Default)]
struct X;

impl X {
    const FOO: &'static str = "a";
}

struct SelfKeywords;

impl Into<SelfKeywords> for X {
    fn into(self) -> SelfKeywords {
        let _ = Self::default();
        let _ = Self::FOO;
        let _: Self = self;

        SelfKeywords
    }
}

struct ExplicitPaths(bool);

impl core::convert::Into<bool> for crate::ExplicitPaths {
    fn into(mut self) -> bool {
        let in_closure = || self.0;

        self.0 = false;
        self.0
    }
}

// this is fine
struct A(String);

impl From<String> for A {
    fn from(s: String) -> A {
        A(s)
    }
}

#[clippy::msrv = "1.40"]
fn msrv_1_40() {
    struct FromOverInto<T>(Vec<T>);

    impl<T> Into<FromOverInto<T>> for Vec<T> {
        fn into(self) -> FromOverInto<T> {
            FromOverInto(self)
        }
    }
}

#[clippy::msrv = "1.41"]
fn msrv_1_41() {
    struct FromOverInto<T>(Vec<T>);

    impl<T> Into<FromOverInto<T>> for Vec<T> {
        fn into(self) -> FromOverInto<T> {
            FromOverInto(self)
        }
    }
}

type Opaque = impl Sized;
struct IntoOpaque;
impl Into<Opaque> for IntoOpaque {
    fn into(self) -> Opaque {}
}

fn main() {}