1
- //! Determining which types for which we can emit `#[derive(PartialEq)]`.
1
+ //! Determining which types for which we cannot emit `#[derive(PartialEq,
2
+ //! PartialOrd)]`.
2
3
3
4
use super :: { ConstrainResult , MonotoneFramework , generate_dependencies} ;
4
5
use ir:: comp:: CompKind ;
@@ -13,31 +14,39 @@ use ir::ty::TypeKind;
13
14
use std:: collections:: HashMap ;
14
15
use std:: collections:: HashSet ;
15
16
16
- /// An analysis that finds for each IR item whether partialeq or partialord cannot be derived.
17
+ /// An analysis that finds for each IR item whether `PartialEq`/`PartialOrd`
18
+ /// cannot be derived.
17
19
///
18
- /// We use the monotone constraint function `cannot_derive_partialeq_or_partialord`, defined as
19
- /// follows:
20
+ /// We use the monotone constraint function
21
+ /// `cannot_derive_partialeq_or_partialord`, defined as follows:
20
22
///
21
23
/// * If T is Opaque and layout of the type is known, get this layout as opaque
22
24
/// type and check whether it can be derived using trivial checks.
23
- /// * If T is Array type, partialeq or partialord cannot be derived if the length of
24
- /// the array is larger than the limit or the type of data the array contains cannot derive
25
- /// partialeq or partialord.
25
+ ///
26
+ /// * If T is Array type, `PartialEq` or partialord cannot be derived if the
27
+ /// length of the array is larger than the limit or the type of data the array
28
+ /// contains cannot derive `PartialEq`/`PartialOrd`.
29
+ ///
26
30
/// * If T is a type alias, a templated alias or an indirection to another type,
27
- /// partialeq or partialord cannot be derived if the type T refers to cannot be derived partialeq or partialord.
28
- /// * If T is a compound type, partialeq or partialord cannot be derived if any of its base member
29
- /// or field cannot be derived partialeq or partialord.
30
- /// * If T is a pointer, T cannot be derived partialeq or partialord if T is a function pointer
31
- /// and the function signature cannot be derived partialeq or partialord.
31
+ /// `PartialEq`/`PartialOrd` cannot be derived if the type T refers to cannot be
32
+ /// derived `PartialEq`/`PartialOrd`.
33
+ ///
34
+ /// * If T is a compound type, `PartialEq`/`PartialOrd` cannot be derived if any
35
+ /// of its base member or field cannot be derived `PartialEq`/`PartialOrd`.
36
+ ///
37
+ /// * If T is a pointer, T cannot be derived `PartialEq`/`PartialOrd` if T is a
38
+ /// function pointer and the function signature cannot be derived
39
+ /// `PartialEq`/`PartialOrd`.
40
+ ///
32
41
/// * If T is an instantiation of an abstract template definition, T cannot be
33
- /// derived partialeq or partialord if any of the template arguments or template definition
34
- /// cannot derive partialeq or partialord .
42
+ /// derived `PartialEq`/`PartialOrd` if any of the template arguments or
43
+ /// template definition cannot derive `PartialEq`/`PartialOrd` .
35
44
#[ derive( Debug , Clone ) ]
36
45
pub struct CannotDerivePartialEqOrPartialOrd < ' ctx > {
37
46
ctx : & ' ctx BindgenContext ,
38
47
39
48
// The incremental result of this analysis's computation. Everything in this
40
- // set cannot derive partialeq or partialord .
49
+ // set cannot derive `PartialEq`/`PartialOrd` .
41
50
cannot_derive_partialeq_or_partialord : HashSet < ItemId > ,
42
51
43
52
// Dependencies saying that if a key ItemId has been inserted into the
@@ -46,15 +55,15 @@ pub struct CannotDerivePartialEqOrPartialOrd<'ctx> {
46
55
//
47
56
// This is a subset of the natural IR graph with reversed edges, where we
48
57
// only include the edges from the IR graph that can affect whether a type
49
- // can derive partialeq or partialord .
58
+ // can derive `PartialEq`/`PartialOrd` .
50
59
dependencies : HashMap < ItemId , Vec < ItemId > > ,
51
60
}
52
61
53
62
impl < ' ctx > CannotDerivePartialEqOrPartialOrd < ' ctx > {
54
63
fn consider_edge ( kind : EdgeKind ) -> bool {
55
64
match kind {
56
65
// These are the only edges that can affect whether a type can derive
57
- // partialeq or partialord .
66
+ // `PartialEq`/`PartialOrd` .
58
67
EdgeKind :: BaseMember |
59
68
EdgeKind :: Field |
60
69
EdgeKind :: TypeReference |
@@ -115,7 +124,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
115
124
trace ! ( "constrain: {:?}" , id) ;
116
125
117
126
if self . cannot_derive_partialeq_or_partialord . contains ( & id) {
118
- trace ! ( " already know it cannot derive PartialEq or PartialOrd" ) ;
127
+ trace ! ( " already know it cannot derive ` PartialEq`/` PartialOrd` " ) ;
119
128
return ConstrainResult :: Same ;
120
129
}
121
130
@@ -140,10 +149,10 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
140
149
return if layout_can_derive &&
141
150
!( ty. is_union ( ) &&
142
151
self . ctx . options ( ) . rust_features ( ) . untagged_union ( ) ) {
143
- trace ! ( " we can trivially derive PartialEq or PartialOrd for the layout" ) ;
152
+ trace ! ( " we can trivially derive ` PartialEq`/` PartialOrd` for the layout" ) ;
144
153
ConstrainResult :: Same
145
154
} else {
146
- trace ! ( " we cannot derive PartialEq or PartialOrd for the layout" ) ;
155
+ trace ! ( " we cannot derive ` PartialEq`/` PartialOrd` for the layout" ) ;
147
156
self . insert ( id)
148
157
} ;
149
158
}
@@ -176,24 +185,24 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
176
185
TypeKind :: ObjCInterface ( ..) |
177
186
TypeKind :: ObjCId |
178
187
TypeKind :: ObjCSel => {
179
- trace ! ( " simple type that can always derive PartialEq or PartialOrd" ) ;
188
+ trace ! ( " simple type that can always derive ` PartialEq`/` PartialOrd` " ) ;
180
189
ConstrainResult :: Same
181
190
}
182
191
183
192
TypeKind :: Array ( t, len) => {
184
193
if self . cannot_derive_partialeq_or_partialord . contains ( & t) {
185
194
trace ! (
186
- " arrays of T for which we cannot derive PartialEq or PartialOrd \
187
- also cannot derive PartialEq or PartialOrd"
195
+ " arrays of T for which we cannot derive ` PartialEq`/` PartialOrd` \
196
+ also cannot derive ` PartialEq`/` PartialOrd` "
188
197
) ;
189
198
return self . insert ( id) ;
190
199
}
191
200
192
201
if len <= RUST_DERIVE_IN_ARRAY_LIMIT {
193
- trace ! ( " array is small enough to derive PartialEq or PartialOrd" ) ;
202
+ trace ! ( " array is small enough to derive ` PartialEq`/` PartialOrd` " ) ;
194
203
ConstrainResult :: Same
195
204
} else {
196
- trace ! ( " array is too large to derive PartialEq or PartialOrd" ) ;
205
+ trace ! ( " array is too large to derive ` PartialEq`/` PartialOrd` " ) ;
197
206
self . insert ( id)
198
207
}
199
208
}
@@ -204,7 +213,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
204
213
if let TypeKind :: Function ( ref sig) = * inner_type. kind ( ) {
205
214
if !sig. can_trivially_derive_partialeq_or_partialord ( ) {
206
215
trace ! (
207
- " function pointer that can't trivially derive PartialEq or PartialOrd"
216
+ " function pointer that can't trivially derive ` PartialEq`/` PartialOrd` "
208
217
) ;
209
218
return self . insert ( id) ;
210
219
}
@@ -216,11 +225,11 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
216
225
TypeKind :: Function ( ref sig) => {
217
226
if !sig. can_trivially_derive_partialeq_or_partialord ( ) {
218
227
trace ! (
219
- " function that can't trivially derive PartialEq or PartialOrd"
228
+ " function that can't trivially derive ` PartialEq`/` PartialOrd` "
220
229
) ;
221
230
return self . insert ( id) ;
222
231
}
223
- trace ! ( " function can derive PartialEq or PartialOrd" ) ;
232
+ trace ! ( " function can derive ` PartialEq`/` PartialOrd` " ) ;
224
233
ConstrainResult :: Same
225
234
}
226
235
@@ -230,13 +239,13 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
230
239
if self . cannot_derive_partialeq_or_partialord . contains ( & t) {
231
240
trace ! (
232
241
" aliases and type refs to T which cannot derive \
233
- PartialEq or PartialOrd also cannot derive PartialEq or PartialOrd"
242
+ ` PartialEq`/` PartialOrd` also cannot derive ` PartialEq`/` PartialOrd` "
234
243
) ;
235
244
self . insert ( id)
236
245
} else {
237
246
trace ! (
238
247
" aliases and type refs to T which can derive \
239
- PartialEq or PartialOrd can also derive PartialEq or PartialOrd"
248
+ ` PartialEq`/` PartialOrd` can also derive ` PartialEq`/` PartialOrd` "
240
249
) ;
241
250
ConstrainResult :: Same
242
251
}
@@ -250,7 +259,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
250
259
251
260
if info. kind ( ) == CompKind :: Union {
252
261
if self . ctx . options ( ) . rust_features ( ) . untagged_union ( ) {
253
- trace ! ( " cannot derive PartialEq or PartialOrd for Rust unions" ) ;
262
+ trace ! ( " cannot derive ` PartialEq`/` PartialOrd` for Rust unions" ) ;
254
263
return self . insert ( id) ;
255
264
}
256
265
@@ -259,11 +268,11 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
259
268
} )
260
269
{
261
270
trace ! (
262
- " union layout can trivially derive PartialEq or PartialOrd"
271
+ " union layout can trivially derive ` PartialEq`/` PartialOrd` "
263
272
) ;
264
273
return ConstrainResult :: Same ;
265
274
} else {
266
- trace ! ( " union layout cannot derive PartialEq or PartialOrd" ) ;
275
+ trace ! ( " union layout cannot derive ` PartialEq`/` PartialOrd` " ) ;
267
276
return self . insert ( id) ;
268
277
}
269
278
}
@@ -275,7 +284,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
275
284
} ) ;
276
285
if bases_cannot_derive {
277
286
trace ! (
278
- " base members cannot derive PartialEq or PartialOrd, so we can't \
287
+ " base members cannot derive ` PartialEq`/` PartialOrd` , so we can't \
279
288
either"
280
289
) ;
281
290
return self . insert ( id) ;
@@ -312,7 +321,7 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
312
321
} ) ;
313
322
if fields_cannot_derive {
314
323
trace ! (
315
- " fields cannot derive PartialEq or PartialOrd, so we can't either"
324
+ " fields cannot derive ` PartialEq`/` PartialOrd` , so we can't either"
316
325
) ;
317
326
return self . insert ( id) ;
318
327
}
@@ -328,8 +337,8 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
328
337
} ) ;
329
338
if args_cannot_derive {
330
339
trace ! (
331
- " template args cannot derive PartialEq or PartialOrd, so \
332
- insantiation can't either"
340
+ " template args cannot derive ` PartialEq`/` PartialOrd` , so \
341
+ insantiation can't either"
333
342
) ;
334
343
return self . insert ( id) ;
335
344
}
@@ -343,13 +352,13 @@ impl<'ctx> MonotoneFramework for CannotDerivePartialEqOrPartialOrd<'ctx> {
343
352
) ;
344
353
if def_cannot_derive {
345
354
trace ! (
346
- " template definition cannot derive PartialEq or PartialOrd, so \
347
- insantiation can't either"
355
+ " template definition cannot derive ` PartialEq`/` PartialOrd` , so \
356
+ insantiation can't either"
348
357
) ;
349
358
return self . insert ( id) ;
350
359
}
351
360
352
- trace ! ( " template instantiation can derive PartialEq or PartialOrd" ) ;
361
+ trace ! ( " template instantiation can derive ` PartialEq`/` PartialOrd` " ) ;
353
362
ConstrainResult :: Same
354
363
}
355
364
0 commit comments