File tree 4 files changed +31
-0
lines changed 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,10 @@ impl ParseCallbacks for MacroCallback {
126
126
vec ! [
127
127
"PartialEq" . into( ) ,
128
128
]
129
+ } else if name == "MyOrderedEnum" {
130
+ vec ! [
131
+ "PartialOrd" . into( ) ,
132
+ ]
129
133
} else {
130
134
vec ! [ ]
131
135
}
Original file line number Diff line number Diff line change @@ -234,3 +234,10 @@ typedef union {
234
234
} Coord;
235
235
236
236
Coord coord (double x, double y, double z, double t);
237
+
238
+ // Used to test custom derives on enum. See `test_custom_derive`.
239
+ enum MyOrderedEnum {
240
+ MICRON,
241
+ METER,
242
+ LIGHTYEAR,
243
+ };
Original file line number Diff line number Diff line change @@ -275,4 +275,14 @@ fn test_custom_derive() {
275
275
let test1 = unsafe { bindings:: Test :: new ( 5 ) } ;
276
276
let test2 = unsafe { bindings:: Test :: new ( 6 ) } ;
277
277
assert_ne ! ( test1, test2) ;
278
+
279
+ // The `add_derives` callback should have added `#[derive(PartialOrd)]`
280
+ // to the `my_rustified_enum` enum. If it didn't, this will fail to compile.
281
+
282
+ let micron = unsafe { bindings:: MyOrderedEnum :: MICRON } ;
283
+ let meter = unsafe { bindings:: MyOrderedEnum :: METER } ;
284
+ let lightyear = unsafe { bindings:: MyOrderedEnum :: LIGHTYEAR } ;
285
+
286
+ assert ! ( meter < lightyear) ;
287
+ assert ! ( meter > micron) ;
278
288
}
Original file line number Diff line number Diff line change @@ -3014,6 +3014,16 @@ impl CodeGenerator for Enum {
3014
3014
derives. push ( derive) ;
3015
3015
}
3016
3016
}
3017
+
3018
+ // The custom derives callback may return a list of derive attributes;
3019
+ // add them to the end of the list.
3020
+ let custom_derives;
3021
+ if let Some ( cb) = & ctx. options ( ) . parse_callbacks {
3022
+ custom_derives = cb. add_derives ( & name) ;
3023
+ // In most cases this will be a no-op, since custom_derives will be empty.
3024
+ derives. extend ( custom_derives. iter ( ) . map ( |s| s. as_str ( ) ) ) ;
3025
+ } ;
3026
+
3017
3027
attrs. push ( attributes:: derives ( & derives) ) ;
3018
3028
}
3019
3029
You can’t perform that action at this time.
0 commit comments