@@ -148,6 +148,9 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
148
148
}
149
149
writeln_docs ( w, & t. attrs , "" ) ;
150
150
151
+ let mut gen_types = GenericTypes :: new ( ) ;
152
+ assert ! ( gen_types. learn_generics( & t. generics, types) ) ;
153
+
151
154
writeln ! ( w, "#[repr(C)]\n pub struct {} {{" , trait_name) . unwrap ( ) ;
152
155
writeln ! ( w, "\t pub this_arg: *mut c_void," ) . unwrap ( ) ;
153
156
let associated_types = learn_associated_types ( t) ;
@@ -158,15 +161,17 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
158
161
match export_status ( & m. attrs ) {
159
162
ExportStatus :: NoExport => {
160
163
// NoExport in this context means we'll hit an unimplemented!() at runtime,
161
- // so add a comment noting that this needs to change in the output.
162
- writeln ! ( w, "\t //XXX: Need to export {}" , m. sig. ident) . unwrap ( ) ;
163
- continue ;
164
+ // so bail out.
165
+ unimplemented ! ( ) ;
164
166
} ,
165
167
ExportStatus :: Export => { } ,
166
168
ExportStatus :: TestOnly => continue ,
167
169
}
168
170
if m. default . is_some ( ) { unimplemented ! ( ) ; }
169
171
172
+ gen_types. push_ctx ( ) ;
173
+ assert ! ( gen_types. learn_generics( & m. sig. generics, types) ) ;
174
+
170
175
writeln_docs ( w, & m. attrs , "\t " ) ;
171
176
172
177
if let syn:: ReturnType :: Type ( _, rtype) = & m. sig . output {
@@ -183,7 +188,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
183
188
// called when the trait method is called which allows updating on the fly.
184
189
write ! ( w, "\t pub {}: " , m. sig. ident) . unwrap ( ) ;
185
190
generated_fields. push ( format ! ( "{}" , m. sig. ident) ) ;
186
- types. write_c_type ( w, & * r. elem , None , false ) ;
191
+ types. write_c_type ( w, & * r. elem , Some ( & gen_types ) , false ) ;
187
192
writeln ! ( w, "," ) . unwrap ( ) ;
188
193
writeln ! ( w, "\t /// Fill in the {} field as a reference to it will be given to Rust after this returns" , m. sig. ident) . unwrap ( ) ;
189
194
writeln ! ( w, "\t /// Note that this takes a pointer to this object, not the this_ptr like other methods do" ) . unwrap ( ) ;
@@ -195,6 +200,7 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
195
200
// which does not compile since Thing is not defined before it is used.
196
201
writeln ! ( extra_headers, "struct LDK{};" , trait_name) . unwrap ( ) ;
197
202
writeln ! ( extra_headers, "typedef struct LDK{} LDK{};" , trait_name, trait_name) . unwrap ( ) ;
203
+ gen_types. pop_ctx ( ) ;
198
204
continue ;
199
205
}
200
206
// Sadly, this currently doesn't do what we want, but it should be easy to get
@@ -204,8 +210,10 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
204
210
205
211
write ! ( w, "\t pub {}: extern \" C\" fn (" , m. sig. ident) . unwrap ( ) ;
206
212
generated_fields. push ( format ! ( "{}" , m. sig. ident) ) ;
207
- write_method_params ( w, & m. sig , & associated_types, "c_void" , types, None , true , false ) ;
213
+ write_method_params ( w, & m. sig , & associated_types, "c_void" , types, Some ( & gen_types ) , true , false ) ;
208
214
writeln ! ( w, "," ) . unwrap ( ) ;
215
+
216
+ gen_types. pop_ctx ( ) ;
209
217
} ,
210
218
& syn:: TraitItem :: Type ( _) => { } ,
211
219
_ => unimplemented ! ( ) ,
@@ -284,8 +292,10 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
284
292
m. sig . abi . is_some ( ) || m. sig . variadic . is_some ( ) {
285
293
unimplemented ! ( ) ;
286
294
}
295
+ gen_types. push_ctx ( ) ;
296
+ assert ! ( gen_types. learn_generics( & m. sig. generics, types) ) ;
287
297
write ! ( w, "\t fn {}" , m. sig. ident) . unwrap ( ) ;
288
- types. write_rust_generic_param ( w, m. sig . generics . params . iter ( ) ) ;
298
+ types. write_rust_generic_param ( w, Some ( & gen_types ) , m. sig . generics . params . iter ( ) ) ;
289
299
write ! ( w, "(" ) . unwrap ( ) ;
290
300
for inp in m. sig . inputs . iter ( ) {
291
301
match inp {
@@ -309,27 +319,26 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
309
319
ident. mutability . is_some ( ) || ident. subpat . is_some ( ) {
310
320
unimplemented ! ( ) ;
311
321
}
312
- write ! ( w, ", {}{}: " , if types. skip_arg( & * arg. ty, None ) { "_" } else { "" } , ident. ident) . unwrap ( ) ;
322
+ write ! ( w, ", {}{}: " , if types. skip_arg( & * arg. ty, Some ( & gen_types ) ) { "_" } else { "" } , ident. ident) . unwrap ( ) ;
313
323
}
314
324
_ => unimplemented ! ( ) ,
315
325
}
316
- types. write_rust_type ( w, & * arg. ty ) ;
326
+ types. write_rust_type ( w, Some ( & gen_types ) , & * arg. ty ) ;
317
327
}
318
328
}
319
329
}
320
330
write ! ( w, ")" ) . unwrap ( ) ;
321
331
match & m. sig . output {
322
332
syn:: ReturnType :: Type ( _, rtype) => {
323
333
write ! ( w, " -> " ) . unwrap ( ) ;
324
- types. write_rust_type ( w, & * rtype)
334
+ types. write_rust_type ( w, Some ( & gen_types ) , & * rtype)
325
335
} ,
326
336
_ => { } ,
327
337
}
328
338
write ! ( w, " {{\n \t \t " ) . unwrap ( ) ;
329
339
match export_status ( & m. attrs ) {
330
340
ExportStatus :: NoExport => {
331
- writeln ! ( w, "unimplemented!();\n \t }}" ) . unwrap ( ) ;
332
- continue ;
341
+ unimplemented ! ( ) ;
333
342
} ,
334
343
_ => { } ,
335
344
}
@@ -339,25 +348,27 @@ fn writeln_trait<'a, 'b, W: std::io::Write>(w: &mut W, t: &'a syn::ItemTrait, ty
339
348
writeln ! ( w, "if let Some(f) = self.set_{} {{" , m. sig. ident) . unwrap ( ) ;
340
349
writeln ! ( w, "\t \t \t (f)(self);" ) . unwrap ( ) ;
341
350
write ! ( w, "\t \t }}\n \t \t " ) . unwrap ( ) ;
342
- types. write_from_c_conversion_to_ref_prefix ( w, & * r. elem , None ) ;
351
+ types. write_from_c_conversion_to_ref_prefix ( w, & * r. elem , Some ( & gen_types ) ) ;
343
352
write ! ( w, "self.{}" , m. sig. ident) . unwrap ( ) ;
344
- types. write_from_c_conversion_to_ref_suffix ( w, & * r. elem , None ) ;
353
+ types. write_from_c_conversion_to_ref_suffix ( w, & * r. elem , Some ( & gen_types ) ) ;
345
354
writeln ! ( w, "\n \t }}" ) . unwrap ( ) ;
355
+ gen_types. pop_ctx ( ) ;
346
356
continue ;
347
357
}
348
358
}
349
- write_method_var_decl_body ( w, & m. sig , "\t " , types, None , true ) ;
359
+ write_method_var_decl_body ( w, & m. sig , "\t " , types, Some ( & gen_types ) , true ) ;
350
360
write ! ( w, "(self.{})(" , m. sig. ident) . unwrap ( ) ;
351
- write_method_call_params ( w, & m. sig , & associated_types, "\t " , types, None , "" , true ) ;
361
+ write_method_call_params ( w, & m. sig , & associated_types, "\t " , types, Some ( & gen_types ) , "" , true ) ;
352
362
353
363
writeln ! ( w, "\n \t }}" ) . unwrap ( ) ;
364
+ gen_types. pop_ctx ( ) ;
354
365
} ,
355
366
& syn:: TraitItem :: Type ( ref t) => {
356
367
if t. default . is_some ( ) || t. generics . lt_token . is_some ( ) { unimplemented ! ( ) ; }
357
368
let mut bounds_iter = t. bounds . iter ( ) ;
358
369
match bounds_iter. next ( ) . unwrap ( ) {
359
370
syn:: TypeParamBound :: Trait ( tr) => {
360
- writeln ! ( w, "\t type {} = crate::{};" , t. ident, types. resolve_path( & tr. path, None ) ) . unwrap ( ) ;
371
+ writeln ! ( w, "\t type {} = crate::{};" , t. ident, types. resolve_path( & tr. path, Some ( & gen_types ) ) ) . unwrap ( ) ;
361
372
} ,
362
373
_ => unimplemented ! ( ) ,
363
374
}
0 commit comments