]> git.lizzy.rs Git - rust.git/blob - src/test/ui/methods/method-not-found-generic-arg-elision.rs
Override rustc version in ui and mir-opt tests to get stable hashes
[rust.git] / src / test / ui / methods / method-not-found-generic-arg-elision.rs
1 // Test for issue 81576
2 // Remove generic arguments if no method is found for all possible generic argument
3
4 use std::marker::PhantomData;
5
6 struct Wrapper2<'a, T, const C: usize> {
7     x: &'a T,
8 }
9
10 impl<'a, const C: usize> Wrapper2<'a, i8, C> {
11     fn method(&self) {}
12 }
13
14 impl<'a, const C: usize> Wrapper2<'a, i16, C> {
15     fn method(&self) {}
16 }
17
18 impl<'a, const C: usize> Wrapper2<'a, i32, C> {
19     fn method(&self) {}
20 }
21 struct Wrapper<T>(T);
22
23 impl Wrapper<i8> {
24     fn method(&self) {}
25 }
26
27 impl Wrapper<i16> {
28     fn method(&self) {}
29 }
30
31 impl Wrapper<i32> {
32     fn method(&self) {}
33 }
34
35 impl Wrapper<i64> {
36     fn method(&self) {}
37 }
38
39 impl Wrapper<u8> {
40     fn method(&self) {}
41 }
42
43 impl Wrapper<u16> {
44     fn method(&self) {}
45 }
46
47 struct Point<T> {
48     x: T,
49     y: T,
50 }
51
52 impl Point<f64> {
53     fn distance(&self) -> f64 {
54         self.x.hypot(self.y)
55     }
56 }
57
58 struct Other;
59
60 impl Other {
61     fn other(&self) {}
62 }
63
64 struct Struct<T>{
65     _phatom: PhantomData<T>
66 }
67
68 impl<T> Default for Struct<T> {
69     fn default() -> Self {
70         Self{ _phatom: PhantomData }
71     }
72 }
73
74 impl<T: Clone + Copy + PartialEq + Eq + PartialOrd + Ord> Struct<T> {
75     fn method(&self) {}
76 }
77
78 fn main() {
79     let point_f64 = Point{ x: 1_f64, y: 1_f64};
80     let d = point_f64.distance();
81     let point_i32 = Point{ x: 1_i32, y: 1_i32};
82     let d = point_i32.distance();
83     //~^ ERROR no method named `distance` found for struct `Point<i32>
84     let d = point_i32.other();
85     //~^ ERROR no method named `other` found for struct `Point
86     let v = vec![1_i32, 2, 3];
87     v.iter().map(|x| x * x).extend(std::iter::once(100));
88     //~^ ERROR no method named `extend` found for struct `Map
89     let wrapper = Wrapper(true);
90     wrapper.method();
91     //~^ ERROR no method named `method` found for struct `Wrapper<bool>
92     wrapper.other();
93     //~^ ERROR no method named `other` found for struct `Wrapper
94     let boolean = true;
95     let wrapper = Wrapper2::<'_, _, 3> {x: &boolean};
96     wrapper.method();
97     //~^ ERROR no method named `method` found for struct `Wrapper2<'_, bool, 3_usize>
98     wrapper.other();
99     //~^ ERROR no method named `other` found for struct `Wrapper2
100     let a = vec![1, 2, 3];
101     a.not_found();
102     //~^ ERROR no method named `not_found` found for struct `Vec
103     let s = Struct::<f64>::default();
104     s.method();
105     //~^ ERROR the method `method` exists for struct `Struct<f64>`, but its trait bounds were not satisfied
106 }