@@ -830,19 +830,19 @@ impl CodeGenerator for Type {
830
830
let mut outer_params = item. used_template_params ( ctx) ;
831
831
832
832
let is_opaque = item. is_opaque ( ctx, & ( ) ) ;
833
- let inner_rust_type = if is_opaque {
833
+ let ( inner_rust_type, inner_annotations ) = if is_opaque {
834
834
outer_params = vec ! [ ] ;
835
- self . to_opaque ( ctx, item)
835
+ ( self . to_opaque ( ctx, item) , RustTyAnnotation :: None )
836
836
} else {
837
837
// Its possible that we have better layout information than
838
838
// the inner type does, so fall back to an opaque blob based
839
839
// on our layout if converting the inner item fails.
840
- let mut inner_ty = inner_item
840
+ let ( mut inner_ty, inner_annotations ) = inner_item
841
841
. try_to_rust_ty_or_opaque ( ctx, & ( ) )
842
- . map ( |ty| ty. ignore_annotations ( ) )
843
- . unwrap_or_else ( |_| self . to_opaque ( ctx, item) ) ;
842
+ . map ( |ty| ty. to_outer_type ( ) )
843
+ . unwrap_or_else ( |_| ( self . to_opaque ( ctx, item) , RustTyAnnotation :: None ) ) ;
844
844
inner_ty. append_implicit_template_params ( ctx, inner_item) ;
845
- inner_ty
845
+ ( inner_ty, inner_annotations )
846
846
} ;
847
847
848
848
{
@@ -875,6 +875,10 @@ impl CodeGenerator for Type {
875
875
} else {
876
876
quote ! { }
877
877
} ;
878
+ tokens. append_all ( match inner_annotations {
879
+ RustTyAnnotation :: None | RustTyAnnotation :: Reference => quote ! { } ,
880
+ RustTyAnnotation :: HasUnusedTemplateArgs => attributes:: alias_discards_template_params ( ) ,
881
+ } ) ;
878
882
879
883
let alias_style = if ctx. options ( ) . type_alias . matches ( & name) {
880
884
AliasVariation :: TypeAlias
@@ -3489,10 +3493,27 @@ impl RustTy {
3489
3493
}
3490
3494
}
3491
3495
3492
- fn new_reference ( ts : proc_macro2:: TokenStream ) -> Self {
3496
+ fn new_reference ( ts : proc_macro2:: TokenStream , inner : RustTyAnnotation ) -> Self {
3497
+ let annotation = match inner {
3498
+ RustTyAnnotation :: HasUnusedTemplateArgs => RustTyAnnotation :: HasUnusedTemplateArgs ,
3499
+ _ => RustTyAnnotation :: Reference
3500
+ } ;
3493
3501
Self {
3494
3502
ts,
3495
- annotation : RustTyAnnotation :: Reference ,
3503
+ annotation,
3504
+ }
3505
+ }
3506
+
3507
+ // We're constructing some outer type composed of an inner type,
3508
+ // e.g. a reference to a T - the inner type is T
3509
+ fn wraps ( ts : proc_macro2:: TokenStream , inner : RustTyAnnotation ) -> Self {
3510
+ let annotation = match inner {
3511
+ RustTyAnnotation :: HasUnusedTemplateArgs => RustTyAnnotation :: HasUnusedTemplateArgs ,
3512
+ _ => RustTyAnnotation :: None
3513
+ } ;
3514
+ Self {
3515
+ ts,
3516
+ annotation,
3496
3517
}
3497
3518
}
3498
3519
@@ -3513,6 +3534,12 @@ impl RustTy {
3513
3534
self . ts
3514
3535
}
3515
3536
3537
+ // Use when this is an inner type and will become part of an outer type.
3538
+ // Pass the annotation into [wraps]
3539
+ fn to_outer_type ( self ) -> ( proc_macro2:: TokenStream , RustTyAnnotation ) {
3540
+ ( self . ts , self . annotation )
3541
+ }
3542
+
3516
3543
fn to_unannotated_ts ( self ) -> error:: Result < proc_macro2:: TokenStream > {
3517
3544
if matches ! ( self . annotation, RustTyAnnotation :: None ) {
3518
3545
Ok ( self . ts )
@@ -3687,20 +3714,20 @@ impl TryToRustTy for Type {
3687
3714
// Regardless if we can properly represent the inner type, we
3688
3715
// should always generate a proper pointer here, so use
3689
3716
// infallible conversion of the inner type.
3690
- let mut ty = inner. to_rust_ty_or_opaque ( ctx, & ( ) ) . ignore_annotations ( ) ;
3717
+ let ( mut ty, inner_annotations ) = inner. to_rust_ty_or_opaque ( ctx, & ( ) ) . to_outer_type ( ) ;
3691
3718
ty. append_implicit_template_params ( ctx, inner) ;
3692
3719
3693
3720
// Avoid the first function pointer level, since it's already
3694
3721
// represented in Rust.
3695
3722
if inner_ty. canonical_type ( ctx) . is_function ( ) || is_objc_pointer
3696
3723
{
3697
- Ok ( ty . into ( ) )
3724
+ Ok ( RustTy :: wraps ( ty , inner_annotations ) )
3698
3725
} else {
3699
3726
let ty_ptr = ty. to_ptr ( is_const) ;
3700
3727
Ok ( if is_reference {
3701
- RustTy :: new_reference ( ty_ptr)
3728
+ RustTy :: new_reference ( ty_ptr, inner_annotations )
3702
3729
} else {
3703
- ty_ptr . into ( )
3730
+ RustTy :: wraps ( ty_ptr , inner_annotations )
3704
3731
} )
3705
3732
}
3706
3733
}
@@ -4682,7 +4709,8 @@ pub mod utils {
4682
4709
} else {
4683
4710
t. to_rust_ty_or_opaque ( ctx, & ( ) )
4684
4711
} ;
4685
- RustTy :: new ( rust_ty. ignore_annotations ( ) . to_ptr ( ctx. resolve_type ( t) . is_const ( ) ) )
4712
+ let ( inner_ty, annotations) = rust_ty. to_outer_type ( ) ;
4713
+ RustTy :: wraps ( inner_ty. to_ptr ( ctx. resolve_type ( t) . is_const ( ) ) , annotations)
4686
4714
}
4687
4715
TypeKind :: Pointer ( inner) => {
4688
4716
let inner = ctx. resolve_item ( inner) ;
0 commit comments