blob: 538eeadae0836ff80d794727141959a2be39f4c9 [file] [log] [blame]
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:171// Test for issue 81576
2// Remove generic arguments if no method is found for all possible generic argument
3
Aliénore Bouttefeux120691c2021-05-22 10:03:374use std::marker::PhantomData;
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:175
6struct Wrapper2<'a, T, const C: usize> {
7 x: &'a T,
8}
9
10impl<'a, const C: usize> Wrapper2<'a, i8, C> {
11 fn method(&self) {}
12}
13
14impl<'a, const C: usize> Wrapper2<'a, i16, C> {
15 fn method(&self) {}
16}
17
18impl<'a, const C: usize> Wrapper2<'a, i32, C> {
19 fn method(&self) {}
20}
21struct Wrapper<T>(T);
22
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1723impl Wrapper<i8> {
24 fn method(&self) {}
25}
26
27impl Wrapper<i16> {
28 fn method(&self) {}
29}
30
31impl Wrapper<i32> {
32 fn method(&self) {}
33}
34
35impl Wrapper<i64> {
36 fn method(&self) {}
37}
38
39impl Wrapper<u8> {
40 fn method(&self) {}
41}
42
43impl Wrapper<u16> {
44 fn method(&self) {}
45}
46
47struct Point<T> {
48 x: T,
49 y: T,
50}
51
52impl Point<f64> {
53 fn distance(&self) -> f64 {
54 self.x.hypot(self.y)
55 }
56}
57
58struct Other;
59
60impl Other {
61 fn other(&self) {}
62}
63
Artur Sinilac39826e2022-07-18 23:25:1464struct Struct<T> {
65 _phatom: PhantomData<T>,
Aliénore Bouttefeux120691c2021-05-22 10:03:3766}
67
68impl<T> Default for Struct<T> {
69 fn default() -> Self {
Artur Sinilac39826e2022-07-18 23:25:1470 Self { _phatom: PhantomData }
Aliénore Bouttefeux120691c2021-05-22 10:03:3771 }
72}
73
74impl<T: Clone + Copy + PartialEq + Eq + PartialOrd + Ord> Struct<T> {
75 fn method(&self) {}
76}
77
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1778fn main() {
Artur Sinilac39826e2022-07-18 23:25:1479 let point_f64 = Point { x: 1_f64, y: 1_f64 };
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1780 let d = point_f64.distance();
Artur Sinilac39826e2022-07-18 23:25:1481 let point_i32 = Point { x: 1_i32, y: 1_i32 };
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1782 let d = point_i32.distance();
83 //~^ ERROR no method named `distance` found for struct `Point<i32>
84 let d = point_i32.other();
Aliénore Bouttefeux6efa14b2021-05-21 12:01:3885 //~^ ERROR no method named `other` found for struct `Point
Michael Goulet0fabceb2023-04-26 21:48:1786 let v = vec![1, 2, 3];
87 v.iter().map(Box::new(|x| x * x) as Box<dyn Fn(&i32) -> i32>).extend(std::iter::once(100));
Aliénore Bouttefeux6efa14b2021-05-21 12:01:3888 //~^ ERROR no method named `extend` found for struct `Map
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1789 let wrapper = Wrapper(true);
90 wrapper.method();
91 //~^ ERROR no method named `method` found for struct `Wrapper<bool>
92 wrapper.other();
Aliénore Bouttefeux6efa14b2021-05-21 12:01:3893 //~^ ERROR no method named `other` found for struct `Wrapper
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1794 let boolean = true;
Artur Sinilac39826e2022-07-18 23:25:1495 let wrapper = Wrapper2::<'_, _, 3> { x: &boolean };
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1796 wrapper.method();
Artur Sinilac39826e2022-07-18 23:25:1497 //~^ ERROR no method named `method` found for struct `Wrapper2<'_, bool, 3>
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:1798 wrapper.other();
Aliénore Bouttefeux6efa14b2021-05-21 12:01:3899 //~^ ERROR no method named `other` found for struct `Wrapper2
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:17100 let a = vec![1, 2, 3];
101 a.not_found();
Aliénore Bouttefeux6efa14b2021-05-21 12:01:38102 //~^ ERROR no method named `not_found` found for struct `Vec
Aliénore Bouttefeux120691c2021-05-22 10:03:37103 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
Aliénore Bouttefeuxc64a2ed2021-04-15 14:58:17106}