File: associated-types-eq-hr.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (121 lines) | stat: -rw-r--r-- 2,261 bytes parent folder | download | duplicates (16)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Check testing of equality constraints in a higher-ranked context.

pub trait TheTrait<T> {
    type A;

    fn get(&self, t: T) -> Self::A;
}

struct IntStruct {
    x: isize,
}

impl<'a> TheTrait<&'a isize> for IntStruct {
    type A = &'a isize;

    fn get(&self, t: &'a isize) -> &'a isize {
        t
    }
}

struct UintStruct {
    x: isize,
}

impl<'a> TheTrait<&'a isize> for UintStruct {
    type A = &'a usize;

    fn get(&self, t: &'a isize) -> &'a usize {
        panic!()
    }
}

struct Tuple {}

impl<'a> TheTrait<(&'a isize, &'a isize)> for Tuple {
    type A = &'a isize;

    fn get(&self, t: (&'a isize, &'a isize)) -> &'a isize {
        t.0
    }
}

fn foo<T>()
where
    T: for<'x> TheTrait<&'x isize, A = &'x isize>,
{
    // ok for IntStruct, but not UintStruct
}

fn bar<T>()
where
    T: for<'x> TheTrait<&'x isize, A = &'x usize>,
{
    // ok for UintStruct, but not IntStruct
}

fn tuple_one<T>()
where
    T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'x isize>,
{
    // not ok for tuple, two lifetimes and we pick first
}

fn tuple_two<T>()
where
    T: for<'x, 'y> TheTrait<(&'x isize, &'y isize), A = &'y isize>,
{
    // not ok for tuple, two lifetimes and we pick second
}

fn tuple_three<T>()
where
    T: for<'x> TheTrait<(&'x isize, &'x isize), A = &'x isize>,
{
    // ok for tuple
}

fn tuple_four<T>()
where
    T: for<'x, 'y> TheTrait<(&'x isize, &'y isize)>,
{
    // not ok for tuple, two lifetimes, and lifetime matching is invariant
}

pub fn call_foo() {
    foo::<IntStruct>();
    foo::<UintStruct>(); //~ ERROR type mismatch
}

pub fn call_bar() {
    bar::<IntStruct>(); //~ ERROR type mismatch
    bar::<UintStruct>();
}

pub fn call_tuple_one() {
    tuple_one::<Tuple>();
    //~^ ERROR not general enough
    //~| ERROR not general enough
    //~| ERROR not general enough
    //~| ERROR not general enough
}

pub fn call_tuple_two() {
    tuple_two::<Tuple>();
    //~^ ERROR not general enough
    //~| ERROR not general enough
    //~| ERROR mismatched types
    //~| ERROR mismatched types
}

pub fn call_tuple_three() {
    tuple_three::<Tuple>();
}

pub fn call_tuple_four() {
    tuple_four::<Tuple>();
    //~^ ERROR not general enough
    //~| ERROR not general enough
}

fn main() {}