@@ -61,6 +61,17 @@ pub trait ItemCanonicalPath {
61
61
fn canonical_path ( & self , ctx : & BindgenContext ) -> Vec < String > ;
62
62
}
63
63
64
+ /// A trait for determining if some IR thing is opaque or not.
65
+ pub trait IsOpaque {
66
+ /// Extra context the IR thing needs to determine if it is opaque or not.
67
+ type Extra ;
68
+
69
+ /// Returns `true` if the thing is opaque, and `false` otherwise.
70
+ ///
71
+ /// May only be called when `ctx` is in the codegen phase.
72
+ fn is_opaque ( & self , ctx : & BindgenContext , extra : & Self :: Extra ) -> bool ;
73
+ }
74
+
64
75
/// A trait for iterating over an item and its parents and up its ancestor chain
65
76
/// up to (but not including) the implicit root module.
66
77
pub trait ItemAncestors {
@@ -231,7 +242,7 @@ impl Trace for Item {
231
242
// don't want to stop collecting types even though they may be
232
243
// opaque.
233
244
if ty. should_be_traced_unconditionally ( ) ||
234
- !self . is_opaque ( ctx) {
245
+ !self . is_opaque ( ctx, & ( ) ) {
235
246
ty. trace ( ctx, tracer, self ) ;
236
247
}
237
248
}
@@ -269,7 +280,7 @@ impl CanDeriveDebug for Item {
269
280
let result = ctx. options ( ) . derive_debug &&
270
281
match self . kind {
271
282
ItemKind :: Type ( ref ty) => {
272
- if self . is_opaque ( ctx) {
283
+ if self . is_opaque ( ctx, & ( ) ) {
273
284
ty. layout ( ctx)
274
285
. map_or ( true , |l| l. opaque ( ) . can_derive_debug ( ctx, ( ) ) )
275
286
} else {
@@ -292,7 +303,7 @@ impl CanDeriveDefault for Item {
292
303
ctx. options ( ) . derive_default &&
293
304
match self . kind {
294
305
ItemKind :: Type ( ref ty) => {
295
- if self . is_opaque ( ctx) {
306
+ if self . is_opaque ( ctx, & ( ) ) {
296
307
ty. layout ( ctx)
297
308
. map_or ( false ,
298
309
|l| l. opaque ( ) . can_derive_default ( ctx, ( ) ) )
@@ -317,7 +328,7 @@ impl<'a> CanDeriveCopy<'a> for Item {
317
328
318
329
let result = match self . kind {
319
330
ItemKind :: Type ( ref ty) => {
320
- if self . is_opaque ( ctx) {
331
+ if self . is_opaque ( ctx, & ( ) ) {
321
332
ty. layout ( ctx)
322
333
. map_or ( true , |l| l. opaque ( ) . can_derive_copy ( ctx, ( ) ) )
323
334
} else {
@@ -335,7 +346,7 @@ impl<'a> CanDeriveCopy<'a> for Item {
335
346
fn can_derive_copy_in_array ( & self , ctx : & BindgenContext , _: ( ) ) -> bool {
336
347
match self . kind {
337
348
ItemKind :: Type ( ref ty) => {
338
- if self . is_opaque ( ctx) {
349
+ if self . is_opaque ( ctx, & ( ) ) {
339
350
ty. layout ( ctx)
340
351
. map_or ( true , |l| {
341
352
l. opaque ( ) . can_derive_copy_in_array ( ctx, ( ) )
@@ -593,15 +604,6 @@ impl Item {
593
604
ctx. hidden_by_name ( & self . canonical_path ( ctx) , self . id )
594
605
}
595
606
596
- /// Is this item opaque?
597
- pub fn is_opaque ( & self , ctx : & BindgenContext ) -> bool {
598
- debug_assert ! ( ctx. in_codegen_phase( ) ,
599
- "You're not supposed to call this yet" ) ;
600
- self . annotations . opaque ( ) ||
601
- self . as_type ( ) . map_or ( false , |ty| ty. is_opaque ( ) ) ||
602
- ctx. opaque_by_name ( & self . canonical_path ( ctx) )
603
- }
604
-
605
607
/// Is this a reference to another type?
606
608
pub fn is_type_ref ( & self ) -> bool {
607
609
self . as_type ( ) . map_or ( false , |ty| ty. is_type_ref ( ) )
@@ -858,6 +860,28 @@ impl Item {
858
860
}
859
861
}
860
862
863
+ impl IsOpaque for ItemId {
864
+ type Extra = ( ) ;
865
+
866
+ fn is_opaque ( & self , ctx : & BindgenContext , _: & ( ) ) -> bool {
867
+ debug_assert ! ( ctx. in_codegen_phase( ) ,
868
+ "You're not supposed to call this yet" ) ;
869
+ ctx. resolve_item ( * self ) . is_opaque ( ctx, & ( ) )
870
+ }
871
+ }
872
+
873
+ impl IsOpaque for Item {
874
+ type Extra = ( ) ;
875
+
876
+ fn is_opaque ( & self , ctx : & BindgenContext , _: & ( ) ) -> bool {
877
+ debug_assert ! ( ctx. in_codegen_phase( ) ,
878
+ "You're not supposed to call this yet" ) ;
879
+ self . annotations . opaque ( ) ||
880
+ self . as_type ( ) . map_or ( false , |ty| ty. is_opaque ( ctx, self ) ) ||
881
+ ctx. opaque_by_name ( & self . canonical_path ( ctx) )
882
+ }
883
+ }
884
+
861
885
/// A set of items.
862
886
pub type ItemSet = BTreeSet < ItemId > ;
863
887
@@ -874,7 +898,7 @@ impl DotAttributes for Item {
874
898
self . id,
875
899
self . name( ctx) . get( ) ) ) ;
876
900
877
- if self . is_opaque ( ctx) {
901
+ if self . is_opaque ( ctx, & ( ) ) {
878
902
writeln ! ( out, "<tr><td>opaque</td><td>true</td></tr>" ) ?;
879
903
}
880
904
0 commit comments