@@ -523,22 +523,40 @@ impl CodeGenerator for Type {
523
523
typedef = typedef. attr ( ) . doc ( comment) ;
524
524
}
525
525
526
- let mut generics = typedef. type_ ( rust_name) . generics ( ) ;
527
- for template_arg in applicable_template_args. iter ( ) {
528
- let template_arg = ctx. resolve_type ( * template_arg) ;
529
- if template_arg. is_named ( ) {
530
- let name = template_arg. name ( ) . unwrap ( ) ;
531
- if name. contains ( "typename " ) {
532
- warn ! ( "Item contained `typename`'d template \
533
- parameter: {:?}", item) ;
534
- return ;
526
+ // We prefer using `pub use` over `pub type` because of:
527
+ // https://github.com/rust-lang/rust/issues/26264
528
+ let simple_enum_path = match inner_rust_type. node {
529
+ ast:: TyKind :: Path ( None , ref p) => {
530
+ if applicable_template_args. is_empty ( ) &&
531
+ !inner_item. expect_type ( ) . canonical_type ( ctx) . is_builtin_or_named ( ) &&
532
+ p. segments . iter ( ) . all ( |p| p. parameters . is_none ( ) ) {
533
+ Some ( p. clone ( ) )
534
+ } else {
535
+ None
535
536
}
536
- generics =
537
- generics. ty_param_id ( template_arg. name ( ) . unwrap ( ) ) ;
538
- }
539
- }
537
+ } ,
538
+ _ => None ,
539
+ } ;
540
540
541
- let typedef = generics. build ( ) . build_ty ( inner_rust_type) ;
541
+ let typedef = if let Some ( p) = simple_enum_path {
542
+ typedef. use_ ( ) . build ( p) . as_ ( rust_name)
543
+ } else {
544
+ let mut generics = typedef. type_ ( rust_name) . generics ( ) ;
545
+ for template_arg in applicable_template_args. iter ( ) {
546
+ let template_arg = ctx. resolve_type ( * template_arg) ;
547
+ if template_arg. is_named ( ) {
548
+ let name = template_arg. name ( ) . unwrap ( ) ;
549
+ if name. contains ( "typename " ) {
550
+ warn ! ( "Item contained `typename`'d template \
551
+ parameter: {:?}", item) ;
552
+ return ;
553
+ }
554
+ generics =
555
+ generics. ty_param_id ( template_arg. name ( ) . unwrap ( ) ) ;
556
+ }
557
+ }
558
+ generics. build ( ) . build_ty ( inner_rust_type)
559
+ } ;
542
560
result. push ( typedef)
543
561
}
544
562
TypeKind :: Enum ( ref ei) => {
0 commit comments