@@ -27,82 +27,90 @@ pub trait ParseCallbacks: fmt::Debug {
27
27
}
28
28
29
29
/// This function will be run on every macro that is identified.
30
- fn will_parse_macro ( & self , _name : & str ) -> MacroParsingBehavior {
30
+ #[ allow( unused_variables) ]
31
+ fn will_parse_macro ( & self , name : & str ) -> MacroParsingBehavior {
31
32
MacroParsingBehavior :: Default
32
33
}
33
34
34
35
/// This function will run for every extern variable and function. The returned value determines
35
36
/// the name visible in the bindings.
37
+ #[ allow( unused_variables) ]
36
38
fn generated_name_override (
37
39
& self ,
38
- _item_info : ItemInfo < ' _ > ,
40
+ item_info : ItemInfo < ' _ > ,
39
41
) -> Option < String > {
40
42
None
41
43
}
42
44
43
45
/// This function will run for every extern variable and function. The returned value determines
44
46
/// the link name in the bindings.
47
+ #[ allow( unused_variables) ]
45
48
fn generated_link_name_override (
46
49
& self ,
47
- _item_info : ItemInfo < ' _ > ,
50
+ item_info : ItemInfo < ' _ > ,
48
51
) -> Option < String > {
49
52
None
50
53
}
51
54
52
55
/// The integer kind an integer macro should have, given a name and the
53
56
/// value of that macro, or `None` if you want the default to be chosen.
54
- fn int_macro ( & self , _name : & str , _value : i64 ) -> Option < IntKind > {
57
+ #[ allow( unused_variables) ]
58
+ fn int_macro ( & self , name : & str , value : i128 ) -> Option < IntKind > {
55
59
None
56
60
}
57
61
58
62
/// This will be run on every string macro. The callback cannot influence the further
59
63
/// treatment of the macro, but may use the value to generate additional code or configuration.
60
- fn str_macro ( & self , _name : & str , _value : & [ u8 ] ) { }
64
+ #[ allow( unused_variables) ]
65
+ fn str_macro ( & self , name : & str , value : & [ u8 ] ) { }
61
66
62
67
/// This will be run on every function-like macro. The callback cannot
63
68
/// influence the further treatment of the macro, but may use the value to
64
69
/// generate additional code or configuration.
65
- ///
66
- /// The first parameter represents the name and argument list (including the
67
- /// parentheses) of the function-like macro. The second parameter represents
68
- /// the expansion of the macro as a sequence of tokens.
69
- fn func_macro ( & self , _name : & str , _value : & [ & [ u8 ] ] ) { }
70
+ #[ allow( unused_variables) ]
71
+ fn fn_macro ( & self , info : & FnMacroInfo < ' _ > ) { }
70
72
71
73
/// This function should return whether, given an enum variant
72
74
/// name, and value, this enum variant will forcibly be a constant.
75
+ #[ allow( unused_variables) ]
73
76
fn enum_variant_behavior (
74
77
& self ,
75
- _enum_name : Option < & str > ,
76
- _original_variant_name : & str ,
77
- _variant_value : EnumVariantValue ,
78
+ enum_name : Option < & str > ,
79
+ original_variant_name : & str ,
80
+ variant_value : EnumVariantValue ,
78
81
) -> Option < EnumVariantCustomBehavior > {
79
82
None
80
83
}
81
84
82
85
/// Allows to rename an enum variant, replacing `_original_variant_name`.
86
+ #[ allow( unused_variables) ]
83
87
fn enum_variant_name (
84
88
& self ,
85
- _enum_name : Option < & str > ,
86
- _original_variant_name : & str ,
87
- _variant_value : EnumVariantValue ,
89
+ enum_name : Option < & str > ,
90
+ original_variant_name : & str ,
91
+ variant_value : EnumVariantValue ,
88
92
) -> Option < String > {
89
93
None
90
94
}
91
95
92
96
/// Allows to rename an item, replacing `_original_item_name`.
93
- fn item_name ( & self , _original_item_name : & str ) -> Option < String > {
97
+ #[ allow( unused_variables) ]
98
+ fn item_name ( & self , original_item_name : & str ) -> Option < String > {
94
99
None
95
100
}
96
101
97
102
/// This will be called on every header filename passed to (`Builder::header`)[`crate::Builder::header`].
98
- fn header_file ( & self , _filename : & str ) { }
103
+ #[ allow( unused_variables) ]
104
+ fn header_file ( & self , filename : & str ) { }
99
105
100
106
/// This will be called on every file inclusion, with the full path of the included file.
101
- fn include_file ( & self , _filename : & str ) { }
107
+ #[ allow( unused_variables) ]
108
+ fn include_file ( & self , filename : & str ) { }
102
109
103
110
/// This will be called every time `bindgen` reads an environment variable whether it has any
104
111
/// content or not.
105
- fn read_env_var ( & self , _key : & str ) { }
112
+ #[ allow( unused_variables) ]
113
+ fn read_env_var ( & self , key : & str ) { }
106
114
107
115
/// This will be called to determine whether a particular blocklisted type
108
116
/// implements a trait or not. This will be used to implement traits on
@@ -113,10 +121,11 @@ pub trait ParseCallbacks: fmt::Debug {
113
121
/// * `Some(ImplementsTrait::Manually)`: any type including `_name` can't
114
122
/// derive `_derive_trait` but can implemented it manually
115
123
/// * `Some(ImplementsTrait::No)`: `_name` doesn't implement `_derive_trait`
124
+ #[ allow( unused_variables) ]
116
125
fn blocklisted_type_implements_trait (
117
126
& self ,
118
- _name : & str ,
119
- _derive_trait : DeriveTrait ,
127
+ name : & str ,
128
+ derive_trait : DeriveTrait ,
120
129
) -> Option < ImplementsTrait > {
121
130
None
122
131
}
@@ -125,22 +134,25 @@ pub trait ParseCallbacks: fmt::Debug {
125
134
///
126
135
/// If no additional attributes are wanted, this function should return an
127
136
/// empty `Vec`.
128
- fn add_derives ( & self , _info : & DeriveInfo < ' _ > ) -> Vec < String > {
137
+ #[ allow( unused_variables) ]
138
+ fn add_derives ( & self , info : & DeriveInfo < ' _ > ) -> Vec < String > {
129
139
vec ! [ ]
130
140
}
131
141
132
142
/// Process a source code comment.
133
- fn process_comment ( & self , _comment : & str ) -> Option < String > {
143
+ #[ allow( unused_variables) ]
144
+ fn process_comment ( & self , comment : & str ) -> Option < String > {
134
145
None
135
146
}
136
147
137
148
/// Potentially override the visibility of a composite type field.
138
149
///
139
150
/// Caution: This allows overriding standard C++ visibility inferred by
140
151
/// `respect_cxx_access_specs`.
152
+ #[ allow( unused_variables) ]
141
153
fn field_visibility (
142
154
& self ,
143
- _info : FieldInfo < ' _ > ,
155
+ info : FieldInfo < ' _ > ,
144
156
) -> Option < crate :: FieldVisibilityKind > {
145
157
None
146
158
}
@@ -151,7 +163,8 @@ pub trait ParseCallbacks: fmt::Debug {
151
163
///
152
164
/// The returned string is new function name.
153
165
#[ cfg( feature = "experimental" ) ]
154
- fn wrap_as_variadic_fn ( & self , _name : & str ) -> Option < String > {
166
+ #[ allow( unused_variables) ]
167
+ fn wrap_as_variadic_fn ( & self , name : & str ) -> Option < String > {
155
168
None
156
169
}
157
170
}
@@ -206,3 +219,27 @@ pub struct FieldInfo<'a> {
206
219
/// The name of the field.
207
220
pub field_name : & ' a str ,
208
221
}
222
+
223
+ /// A struct providing information about the function-like macro being passed to [`ParseCallbacks::fn_macro`].
224
+ pub struct FnMacroInfo < ' m > {
225
+ pub ( crate ) name : & ' m str ,
226
+ pub ( crate ) args : & ' m [ & ' m str ] ,
227
+ pub ( crate ) body : & ' m [ & ' m str ] ,
228
+ }
229
+
230
+ impl FnMacroInfo < ' _ > {
231
+ /// The macro name.
232
+ pub fn name ( & self ) -> & str {
233
+ self . name
234
+ }
235
+
236
+ /// The macro argument names.
237
+ pub fn args ( & self ) -> & [ & str ] {
238
+ self . args
239
+ }
240
+
241
+ /// The macro body as delimited `clang` tokens.
242
+ pub fn body ( & self ) -> & [ & str ] {
243
+ self . body
244
+ }
245
+ }
0 commit comments