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