File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -517,6 +517,8 @@ struct Annotations {
517
517
opaque : bool ,
518
518
hide : bool ,
519
519
use_as : Option < String > ,
520
+ /// Disable deriving copy/clone on this struct.
521
+ no_copy : bool ,
520
522
}
521
523
522
524
impl Annotations {
@@ -525,6 +527,7 @@ impl Annotations {
525
527
opaque : false ,
526
528
hide : false ,
527
529
use_as : None ,
530
+ no_copy : false ,
528
531
} ;
529
532
530
533
anno. parse ( & cursor. comment ( ) ) ;
@@ -542,6 +545,7 @@ impl Annotations {
542
545
"opaque" => self . opaque = true ,
543
546
"hide" => self . hide = true ,
544
547
"replaces" => self . use_as = Some ( comment. get_tag_attr_value ( i) ) ,
548
+ "nocopy" => self . no_copy = true ,
545
549
_ => ( ) ,
546
550
}
547
551
}
@@ -1089,6 +1093,10 @@ fn visit_top(cursor: &Cursor,
1089
1093
ci. borrow_mut ( ) . hide = true ;
1090
1094
}
1091
1095
1096
+ if anno. no_copy {
1097
+ ci. borrow_mut ( ) . no_copy = true ;
1098
+ }
1099
+
1092
1100
// If we find a previous translation, we take it now and carry
1093
1101
// on.
1094
1102
//
Original file line number Diff line number Diff line change @@ -429,6 +429,8 @@ pub struct CompInfo {
429
429
pub opaque : bool ,
430
430
pub base_members : usize ,
431
431
pub layout : Layout ,
432
+ /// If this struct is explicitely marked as non-copiable.
433
+ pub no_copy : bool ,
432
434
/// Typedef'd types names, that we'll resolve early to avoid name conflicts
433
435
pub typedefs : Vec < String > ,
434
436
/// If this type has a template parameter which is not a type (e.g.: a size_t)
@@ -479,6 +481,7 @@ impl CompInfo {
479
481
hide : false ,
480
482
parser_cursor : None ,
481
483
opaque : false ,
484
+ no_copy : false ,
482
485
base_members : 0 ,
483
486
layout : layout,
484
487
typedefs : vec ! [ ] ,
@@ -570,6 +573,9 @@ impl CompInfo {
570
573
}
571
574
572
575
pub fn can_derive_copy ( & self ) -> bool {
576
+ if self . no_copy {
577
+ return false ;
578
+ }
573
579
match self . kind {
574
580
CompKind :: Union => true ,
575
581
CompKind :: Struct => {
Original file line number Diff line number Diff line change
1
+ /* automatically generated by rust-bindgen */
2
+
3
+
4
+ #![ feature( const_fn) ]
5
+ #![ allow( non_snake_case) ]
6
+
7
+
8
+ /** <div rustbindgen nocopy></div> */
9
+ #[ repr( C ) ]
10
+ #[ derive( Debug ) ]
11
+ pub struct Struct_CopiableButWait < T > {
12
+ pub whatever : :: std:: os:: raw:: c_int ,
13
+ pub _phantom0 : :: std:: marker:: PhantomData < T > ,
14
+ }
Original file line number Diff line number Diff line change
1
+
2
+ /* * <div rustbindgen nocopy></div> */
3
+ template <typename T>
4
+ class CopiableButWait {
5
+ int whatever;
6
+ };
You can’t perform that action at this time.
0 commit comments