@@ -180,7 +180,7 @@ impl InterfaceGenerator<'_> {
180
180
f = func. name. to_snake_case( ) ,
181
181
p = name. to_snake_case( ) ,
182
182
) ) ;
183
- self . print_ty ( ty, false ) ;
183
+ self . print_ty ( ty) ;
184
184
self . push_str ( "\n " ) ;
185
185
}
186
186
}
@@ -194,7 +194,7 @@ impl InterfaceGenerator<'_> {
194
194
f = func. name. to_snake_case( ) ,
195
195
p = "result" ,
196
196
) ) ;
197
- self . print_ty ( ty, false ) ;
197
+ self . print_ty ( ty) ;
198
198
self . push_str ( "\n " ) ;
199
199
}
200
200
}
@@ -206,7 +206,7 @@ impl InterfaceGenerator<'_> {
206
206
self . gen . src . push_str ( s) ;
207
207
}
208
208
209
- fn print_ty ( & mut self , ty : & Type , skip_name : bool ) {
209
+ fn print_ty ( & mut self , ty : & Type ) {
210
210
match ty {
211
211
Type :: Bool => self . push_str ( "`bool`" ) ,
212
212
Type :: U8 => self . push_str ( "`u8`" ) ,
@@ -223,25 +223,23 @@ impl InterfaceGenerator<'_> {
223
223
Type :: String => self . push_str ( "`string`" ) ,
224
224
Type :: Id ( id) => {
225
225
let ty = & self . resolve . types [ * id] ;
226
- if !skip_name {
227
- if let Some ( name) = & ty. name {
228
- self . push_str ( "[`" ) ;
229
- self . push_str ( name) ;
230
- self . push_str ( "`](#" ) ;
231
- self . push_str ( & name. to_snake_case ( ) ) ;
232
- self . push_str ( ")" ) ;
233
- return ;
234
- }
226
+ if let Some ( name) = & ty. name {
227
+ self . push_str ( "[`" ) ;
228
+ self . push_str ( name) ;
229
+ self . push_str ( "`](#" ) ;
230
+ self . push_str ( & name. to_snake_case ( ) ) ;
231
+ self . push_str ( ")" ) ;
232
+ return ;
235
233
}
236
234
match & ty. kind {
237
- TypeDefKind :: Type ( t) => self . print_ty ( t, false ) ,
235
+ TypeDefKind :: Type ( t) => self . print_ty ( t) ,
238
236
TypeDefKind :: Tuple ( t) => {
239
237
self . push_str ( "(" ) ;
240
238
for ( i, t) in t. types . iter ( ) . enumerate ( ) {
241
239
if i > 0 {
242
240
self . push_str ( ", " ) ;
243
241
}
244
- self . print_ty ( t, false ) ;
242
+ self . print_ty ( t) ;
245
243
}
246
244
self . push_str ( ")" ) ;
247
245
}
@@ -250,29 +248,32 @@ impl InterfaceGenerator<'_> {
250
248
| TypeDefKind :: Enum ( _)
251
249
| TypeDefKind :: Variant ( _)
252
250
| TypeDefKind :: Union ( _) => {
253
- unreachable ! ( )
251
+ // These types are always named, so we will have
252
+ // printed the name above, so we don't need to print
253
+ // the contents.
254
+ assert ! ( ty. name. is_some( ) ) ;
254
255
}
255
256
TypeDefKind :: Option ( t) => {
256
257
self . push_str ( "option<" ) ;
257
- self . print_ty ( t, false ) ;
258
+ self . print_ty ( t) ;
258
259
self . push_str ( ">" ) ;
259
260
}
260
261
TypeDefKind :: Result ( r) => match ( r. ok , r. err ) {
261
262
( Some ( ok) , Some ( err) ) => {
262
263
self . push_str ( "result<" ) ;
263
- self . print_ty ( & ok, false ) ;
264
+ self . print_ty ( & ok) ;
264
265
self . push_str ( ", " ) ;
265
- self . print_ty ( & err, false ) ;
266
+ self . print_ty ( & err) ;
266
267
self . push_str ( ">" ) ;
267
268
}
268
269
( None , Some ( err) ) => {
269
270
self . push_str ( "result<_, " ) ;
270
- self . print_ty ( & err, false ) ;
271
+ self . print_ty ( & err) ;
271
272
self . push_str ( ">" ) ;
272
273
}
273
274
( Some ( ok) , None ) => {
274
275
self . push_str ( "result<" ) ;
275
- self . print_ty ( & ok, false ) ;
276
+ self . print_ty ( & ok) ;
276
277
self . push_str ( ">" ) ;
277
278
}
278
279
( None , None ) => {
@@ -281,13 +282,13 @@ impl InterfaceGenerator<'_> {
281
282
} ,
282
283
TypeDefKind :: List ( t) => {
283
284
self . push_str ( "list<" ) ;
284
- self . print_ty ( t, false ) ;
285
+ self . print_ty ( t) ;
285
286
self . push_str ( ">" ) ;
286
287
}
287
288
TypeDefKind :: Future ( t) => match t {
288
289
Some ( t) => {
289
290
self . push_str ( "future<" ) ;
290
- self . print_ty ( t, false ) ;
291
+ self . print_ty ( t) ;
291
292
self . push_str ( ">" ) ;
292
293
}
293
294
None => {
@@ -297,19 +298,19 @@ impl InterfaceGenerator<'_> {
297
298
TypeDefKind :: Stream ( s) => match ( s. element , s. end ) {
298
299
( Some ( element) , Some ( end) ) => {
299
300
self . push_str ( "stream<" ) ;
300
- self . print_ty ( & element, false ) ;
301
+ self . print_ty ( & element) ;
301
302
self . push_str ( ", " ) ;
302
- self . print_ty ( & end, false ) ;
303
+ self . print_ty ( & end) ;
303
304
self . push_str ( ">" ) ;
304
305
}
305
306
( None , Some ( end) ) => {
306
307
self . push_str ( "stream<_, " ) ;
307
- self . print_ty ( & end, false ) ;
308
+ self . print_ty ( & end) ;
308
309
self . push_str ( ">" ) ;
309
310
}
310
311
( Some ( element) , None ) => {
311
312
self . push_str ( "stream<" ) ;
312
- self . print_ty ( & element, false ) ;
313
+ self . print_ty ( & element) ;
313
314
self . push_str ( ">" ) ;
314
315
}
315
316
( None , None ) => {
@@ -380,7 +381,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
380
381
format ! ( "{}::{}" , name, field. name) ,
381
382
format ! ( "#{}.{}" , name. to_snake_case( ) , field. name. to_snake_case( ) ) ,
382
383
) ;
383
- self . print_ty ( & field. ty , false ) ;
384
+ self . print_ty ( & field. ty ) ;
384
385
self . gen . src . indent ( 1 ) ;
385
386
self . push_str ( "\n \n " ) ;
386
387
self . docs ( & field. docs ) ;
@@ -405,7 +406,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
405
406
format ! ( "{}::{}" , name, i) ,
406
407
format ! ( "#{}.{}" , name. to_snake_case( ) , i) ,
407
408
) ;
408
- self . print_ty ( ty, false ) ;
409
+ self . print_ty ( ty) ;
409
410
self . push_str ( "\n " ) ;
410
411
}
411
412
}
@@ -453,7 +454,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
453
454
) ;
454
455
if let Some ( ty) = & case. ty {
455
456
self . push_str ( ": " ) ;
456
- self . print_ty ( ty, false ) ;
457
+ self . print_ty ( ty) ;
457
458
}
458
459
self . gen . src . indent ( 1 ) ;
459
460
self . push_str ( "\n \n " ) ;
@@ -477,7 +478,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
477
478
. hrefs
478
479
. insert ( format ! ( "{name}::{i}" ) , format ! ( "#{snake}.{i}" ) ) ;
479
480
self . push_str ( ": " ) ;
480
- self . print_ty ( & case. ty , false ) ;
481
+ self . print_ty ( & case. ty ) ;
481
482
self . gen . src . indent ( 1 ) ;
482
483
self . push_str ( "\n \n " ) ;
483
484
self . docs ( & case. docs ) ;
@@ -513,7 +514,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
513
514
fn type_option ( & mut self , id : TypeId , name : & str , payload : & Type , docs : & Docs ) {
514
515
self . print_type_header ( name) ;
515
516
self . push_str ( "option<" ) ;
516
- self . print_ty ( payload, false ) ;
517
+ self . print_ty ( payload) ;
517
518
self . push_str ( ">" ) ;
518
519
self . print_type_info ( id, docs) ;
519
520
}
@@ -523,19 +524,19 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
523
524
match ( result. ok , result. err ) {
524
525
( Some ( ok) , Some ( err) ) => {
525
526
self . push_str ( "result<" ) ;
526
- self . print_ty ( & ok, false ) ;
527
+ self . print_ty ( & ok) ;
527
528
self . push_str ( ", " ) ;
528
- self . print_ty ( & err, false ) ;
529
+ self . print_ty ( & err) ;
529
530
self . push_str ( ">" ) ;
530
531
}
531
532
( None , Some ( err) ) => {
532
533
self . push_str ( "result<_, " ) ;
533
- self . print_ty ( & err, false ) ;
534
+ self . print_ty ( & err) ;
534
535
self . push_str ( ">" ) ;
535
536
}
536
537
( Some ( ok) , None ) => {
537
538
self . push_str ( "result<" ) ;
538
- self . print_ty ( & ok, false ) ;
539
+ self . print_ty ( & ok) ;
539
540
self . push_str ( ">" ) ;
540
541
}
541
542
( None , None ) => {
@@ -547,7 +548,7 @@ impl<'a> wit_bindgen_core::InterfaceGenerator<'a> for InterfaceGenerator<'a> {
547
548
548
549
fn type_alias ( & mut self , id : TypeId , name : & str , ty : & Type , docs : & Docs ) {
549
550
self . print_type_header ( name) ;
550
- self . print_ty ( ty, true ) ;
551
+ self . print_ty ( ty) ;
551
552
self . push_str ( "\n \n " ) ;
552
553
self . print_type_info ( id, docs) ;
553
554
self . push_str ( "\n " ) ;
0 commit comments