summaryrefslogtreecommitdiffstats
path: root/tests/ui/stability-attribute/generics-default-stability.rs
blob: 300cc34d63df205e8a0c056dc90ddfbc03a9200e (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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// aux-build:unstable_generic_param.rs
#![feature(unstable_default6)]

extern crate unstable_generic_param;

use unstable_generic_param::*;

struct R;

impl Trait1 for S {
    fn foo() -> () { () } // ok
}

struct S;

impl Trait3<usize> for S {
    fn foo() -> usize { 0 } // ok
}

fn main() {
    let _ = S;

    let _: Struct1<isize> = Struct1 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default'

    let _ = STRUCT1; // ok
    let _: Struct1 = STRUCT1; // ok
    let _: Struct1<usize> = STRUCT1; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Struct1<isize> = Struct1 { field: 0 }; //~ ERROR use of unstable library feature 'unstable_default'

    // Instability is not enforced for generic type parameters used in public fields.
    // Note how the unstable type default `usize` leaks,
    // and can be used without the 'unstable_default' feature.
    let _ = STRUCT1.field;
    let _ = Struct1 { field: 1 };
    let _ = Struct1 { field: () };
    let _ = Struct1 { field: 1isize };
    let _: Struct1 = Struct1 { field: 1 };
    let _: usize = STRUCT1.field;
    let _ = STRUCT1.field + 1;
    let _ = STRUCT1.field + 1usize;

    let _ = Struct2 { field: 1 }; // ok
    let _: Struct2 = Struct2 { field: 1 }; // ok
    let _: Struct2<usize> = Struct2 { field: 1 }; // ok

    let _ = STRUCT2;
    let _: Struct2 = STRUCT2; // ok
    let _: Struct2<usize> = STRUCT2; // ok
    let _: Struct2<isize> = Struct2 { field: 0 }; // ok
    let _ = STRUCT2.field; // ok
    let _: usize = STRUCT2.field; // ok
    let _ = STRUCT2.field + 1; // ok
    let _ = STRUCT2.field + 1usize; // ok

    let _ = STRUCT3;
    let _: Struct3 = STRUCT3; // ok
    let _: Struct3<isize, usize> = STRUCT3; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Struct3<isize> = STRUCT3; // ok
    let _: Struct3<isize, isize> = Struct3 { field1: 0, field2: 0 }; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Struct3<usize, usize> = Struct3 { field1: 0, field2: 0 }; //~ ERROR use of unstable library feature 'unstable_default'
    let _ = STRUCT3.field1; // ok
    let _: isize = STRUCT3.field1; // ok
    let _ = STRUCT3.field1 + 1; // ok
    // Note the aforementioned leak.
    let _: usize = STRUCT3.field2; // ok
    let _: Struct3<usize> = Struct3 { field1: 0, field2: 0 }; // ok
    let _ = STRUCT3.field2 + 1; // ok
    let _ = STRUCT3.field2 + 1usize; // ok

    let _ = STRUCT4;
    let _: Struct4<isize> = Struct4 { field: 1 };
    //~^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated]
    //~^^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated]
    //~^^^ use of deprecated field `unstable_generic_param::Struct4::field`: test [deprecated]
    let _ = STRUCT4;
    let _: Struct4 = STRUCT4; //~ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated]
    let _: Struct4<usize> = STRUCT4; //~ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated]
    let _: Struct4<isize> = Struct4 { field: 0 };
    //~^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated]
    //~^^ use of deprecated struct `unstable_generic_param::Struct4`: test [deprecated]
    //~^^^ use of deprecated field `unstable_generic_param::Struct4::field`: test [deprecated]

    let _ = STRUCT5;
    let _: Struct5<isize> = Struct5 { field: 1 }; //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated]
    //~^^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated]
    //~^^^ use of deprecated field `unstable_generic_param::Struct5::field`: test [deprecated]
    let _ = STRUCT5;
    let _: Struct5 = STRUCT5; //~ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated]
    let _: Struct5<usize> = STRUCT5; //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated]
    let _: Struct5<isize> = Struct5 { field: 0 }; //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated]
    //~^^ use of deprecated struct `unstable_generic_param::Struct5`: test [deprecated]
    //~^^^ use of deprecated field `unstable_generic_param::Struct5::field`: test [deprecated]

    let _: Struct6<isize> = Struct6 { field: 1 }; // ok
    let _: Struct6<isize> = Struct6 { field: 0 }; // ok

    let _: Alias1<isize> = Alias1::Some(1); //~ ERROR use of unstable library feature 'unstable_default'

    let _ = ALIAS1; // ok
    let _: Alias1 = ALIAS1; // ok
    let _: Alias1<usize> = ALIAS1; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Alias1<isize> = Alias1::Some(0); //~ ERROR use of unstable library feature 'unstable_default'

    // Instability is not enforced for generic type parameters used in public fields.
    // Note how the unstable type default `usize` leaks,
    // and can be used without the 'unstable_default' feature.
    let _ = Alias1::Some(1);
    let _ = Alias1::Some(());
    let _ = Alias1::Some(1isize);
    let _: Alias1 = Alias1::Some(1);
    let _: usize = ALIAS1.unwrap();
    let _ = ALIAS1.unwrap() + 1;
    let _ = ALIAS1.unwrap() + 1usize;

    let _ = Alias2::Some(1); // ok
    let _: Alias2 = Alias2::Some(1); // ok
    let _: Alias2<usize> = Alias2::Some(1); // ok

    let _ = ALIAS2;
    let _: Alias2 = ALIAS2; // ok
    let _: Alias2<usize> = ALIAS2; // ok
    let _: Alias2<isize> = Alias2::Some(0); // ok
    let _ = ALIAS2.unwrap(); // ok
    let _: usize = ALIAS2.unwrap(); // ok
    let _ = ALIAS2.unwrap() + 1; // ok
    let _ = ALIAS2.unwrap() + 1usize; // ok

    let _ = ALIAS3;
    let _: Alias3 = ALIAS3; // ok
    let _: Alias3<isize, usize> = ALIAS3; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Alias3<isize> = ALIAS3; // ok
    let _: Alias3<isize, isize> = Alias3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default'
    let _: Alias3<usize, usize> = Alias3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default'
    let _ = ALIAS3.unwrap(); // ok
    let _: isize = ALIAS3.unwrap(); // ok
    let _ = ALIAS3.unwrap() + 1; // ok
    // Note the aforementioned leak.
    let _: usize = ALIAS3B.unwrap_err(); // ok
    let _: Alias3<usize> = Alias3::Err(0); // ok
    let _ = ALIAS3B.unwrap_err() + 1; // ok
    let _ = ALIAS3B.unwrap_err() + 1usize; // ok

    let _ = ALIAS4;
    let _: Alias4<isize> = Alias4::Some(1);
    //~^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated]
    //~^^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated]
    let _ = ALIAS4;
    let _: Alias4 = ALIAS4; //~ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated]
    let _: Alias4<usize> = ALIAS4; //~ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated]
    let _: Alias4<isize> = Alias4::Some(0);
    //~^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated]
    //~^^ use of deprecated type alias `unstable_generic_param::Alias4`: test [deprecated]

    let _ = ALIAS5;
    let _: Alias5<isize> = Alias5::Some(1); //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated]
    //~^^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated]
    let _ = ALIAS5;
    let _: Alias5 = ALIAS5; //~ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated]
    let _: Alias5<usize> = ALIAS5; //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated]
    let _: Alias5<isize> = Alias5::Some(0); //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated]
    //~^^ use of deprecated type alias `unstable_generic_param::Alias5`: test [deprecated]

    let _: Alias6<isize> = Alias6::Some(1); // ok
    let _: Alias6<isize> = Alias6::Some(0); // ok

    let _: Enum1<isize> = Enum1::Some(1); //~ ERROR use of unstable library feature 'unstable_default'

    let _ = ENUM1; // ok
    let _: Enum1 = ENUM1; // ok
    let _: Enum1<usize> = ENUM1; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Enum1<isize> = Enum1::Some(0); //~ ERROR use of unstable library feature 'unstable_default'

    // Instability is not enforced for generic type parameters used in public fields.
    // Note how the unstable type default `usize` leaks,
    // and can be used without the 'unstable_default' feature.
    let _ = Enum1::Some(1);
    let _ = Enum1::Some(());
    let _ = Enum1::Some(1isize);
    let _: Enum1 = Enum1::Some(1);
    if let Enum1::Some(x) = ENUM1 {let _: usize = x;}
    if let Enum1::Some(x) = ENUM1 {let _ = x + 1;}
    if let Enum1::Some(x) = ENUM1 {let _ = x + 1usize;}

    let _ = Enum2::Some(1); // ok
    let _: Enum2 = Enum2::Some(1); // ok
    let _: Enum2<usize> = Enum2::Some(1); // ok

    let _ = ENUM2;
    let _: Enum2 = ENUM2; // ok
    let _: Enum2<usize> = ENUM2; // ok
    let _: Enum2<isize> = Enum2::Some(0); // ok
    if let Enum2::Some(x) = ENUM2 {let _ = x;} // ok
    if let Enum2::Some(x) = ENUM2 {let _: usize = x;} // ok
    if let Enum2::Some(x) = ENUM2 {let _ = x + 1;} // ok
    if let Enum2::Some(x) = ENUM2 {let _ = x + 1usize;} // ok

    let _ = ENUM3;
    let _: Enum3 = ENUM3; // ok
    let _: Enum3<isize, usize> = ENUM3; //~ ERROR use of unstable library feature 'unstable_default'
    let _: Enum3<isize> = ENUM3; // ok
    let _: Enum3<isize, isize> = Enum3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default'
    let _: Enum3<usize, usize> = Enum3::Ok(0); //~ ERROR use of unstable library feature 'unstable_default'
    if let Enum3::Ok(x) = ENUM3 {let _ = x;} // ok
    if let Enum3::Ok(x) = ENUM3 {let _: isize = x;} // ok
    if let Enum3::Ok(x) = ENUM3 {let _ = x + 1;} // ok
    // Note the aforementioned leak.
    if let Enum3::Err(x) = ENUM3B {let _: usize = x;} // ok
    let _: Enum3<usize> = Enum3::Err(0); // ok
    if let Enum3::Err(x) = ENUM3B {let _ = x + 1;} // ok
    if let Enum3::Err(x) = ENUM3B {let _ = x + 1usize;} // ok

    let _ = ENUM4;
    let _: Enum4<isize> = Enum4::Some(1);
    //~^ use of deprecated tuple variant `unstable_generic_param::Enum4::Some`: test [deprecated]
    //~^^ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated]
    let _ = ENUM4;
    let _: Enum4 = ENUM4; //~ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated]
    let _: Enum4<usize> = ENUM4; //~ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated]
    let _: Enum4<isize> = Enum4::Some(0);
    //~^ use of deprecated tuple variant `unstable_generic_param::Enum4::Some`: test [deprecated]
    //~^^ use of deprecated enum `unstable_generic_param::Enum4`: test [deprecated]

    let _ = ENUM5;
    let _: Enum5<isize> = Enum5::Some(1); //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated tuple variant `unstable_generic_param::Enum5::Some`: test [deprecated]
    //~^^ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated]
    let _ = ENUM5;
    let _: Enum5 = ENUM5; //~ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated]
    let _: Enum5<usize> = ENUM5; //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated]
    let _: Enum5<isize> = Enum5::Some(0); //~ ERROR use of unstable library feature 'unstable_default'
    //~^ use of deprecated tuple variant `unstable_generic_param::Enum5::Some`: test [deprecated]
    //~^^ use of deprecated enum `unstable_generic_param::Enum5`: test [deprecated]

    let _: Enum6<isize> = Enum6::Some(1); // ok
    let _: Enum6<isize> = Enum6::Some(0); // ok

    let _: Box1<isize, System> = Box1::new(1); //~ ERROR use of unstable library feature 'box_alloc_param'
    let _: Box1<isize> = Box1::new(1); // ok

    let _: Box2<isize, System> = Box2::new(1); // ok
    let _: Box2<isize> = Box2::new(1); // ok

    let _: Box3<isize> = Box3::new(1); // ok
}