]> git.lizzy.rs Git - rust.git/blob - tests/ui/structs/structure-constructor-type-mismatch.rs
internally change regions to be covariant
[rust.git] / tests / ui / structs / structure-constructor-type-mismatch.rs
1 struct Point<T> {
2     x: T,
3     y: T,
4 }
5
6 type PointF = Point<f32>;
7
8 struct Pair<T,U> {
9     x: T,
10     y: U,
11 }
12
13 type PairF<U> = Pair<f32,U>;
14
15 fn main() {
16     let pt = PointF {
17         x: 1,
18         //~^ ERROR mismatched types
19         //~| expected `f32`, found integer
20         y: 2,
21         //~^ ERROR mismatched types
22         //~| expected `f32`, found integer
23     };
24
25     let pt2 = Point::<f32> {
26         x: 3,
27         //~^ ERROR mismatched types
28         //~| expected `f32`, found integer
29         y: 4,
30         //~^ ERROR mismatched types
31         //~| expected `f32`, found integer
32     };
33
34     let pair = PairF {
35         x: 5,
36         //~^ ERROR mismatched types
37         //~| expected `f32`, found integer
38         y: 6,
39     };
40
41     let pair2 = PairF::<i32> {
42         x: 7,
43         //~^ ERROR mismatched types
44         //~| expected `f32`, found integer
45         y: 8,
46     };
47
48     let pt3 = PointF::<i32> { //~ ERROR this type alias takes 0 generic arguments but 1 generic argument
49         x: 9,  //~ ERROR mismatched types
50         y: 10, //~ ERROR mismatched types
51     };
52
53     match (Point { x: 1, y: 2 }) {
54         PointF::<u32> { .. } => {} //~ ERROR this type alias takes 0 generic arguments but 1 generic argument
55         //~^ ERROR mismatched types
56     }
57
58     match (Point { x: 1, y: 2 }) {
59         PointF { .. } => {} //~ ERROR mismatched types
60     }
61
62     match (Point { x: 1.0, y: 2.0 }) {
63         PointF { .. } => {} // ok
64     }
65
66     match (Pair { x: 1, y: 2 }) {
67         PairF::<u32> { .. } => {} //~ ERROR mismatched types
68     }
69
70     match (Pair { x: 1.0, y: 2 }) {
71         PairF::<u32> { .. } => {} // ok
72     }
73 }