@@ -300,20 +300,20 @@ impl AppendImplicitTemplateParams for quote::Tokens {
300
300
_ => { } ,
301
301
}
302
302
303
- if let Some ( params) = item. used_template_params ( ctx) {
304
- if params. is_empty ( ) {
305
- return ;
306
- }
303
+ let params = item. used_template_params ( ctx) ;
307
304
308
- let params = params. into_iter ( ) . map ( |p| {
309
- p. try_to_rust_ty ( ctx, & ( ) )
310
- . expect ( "template params cannot fail to be a rust type" )
311
- } ) ;
312
-
313
- self . append_all ( quote ! {
314
- < #( #params ) , * >
315
- } ) ;
305
+ if params. is_empty ( ) {
306
+ return ;
316
307
}
308
+
309
+ let params = params. into_iter ( ) . map ( |p| {
310
+ p. try_to_rust_ty ( ctx, & ( ) )
311
+ . expect ( "template params cannot fail to be a rust type" )
312
+ } ) ;
313
+
314
+ self . append_all ( quote ! {
315
+ < #( #params ) , * >
316
+ } ) ;
317
317
}
318
318
}
319
319
@@ -481,10 +481,8 @@ impl CodeGenerator for Var {
481
481
// number of actual variables for a single declaration are open ended
482
482
// and we don't know what instantiations do or don't exist.
483
483
let type_params = item. all_template_params ( ctx) ;
484
- if let Some ( params) = type_params {
485
- if !params. is_empty ( ) {
486
- return ;
487
- }
484
+ if !type_params. is_empty ( ) {
485
+ return ;
488
486
}
489
487
490
488
let ty = self . ty ( ) . to_rust_ty_or_opaque ( ctx, & ( ) ) ;
@@ -637,12 +635,8 @@ impl CodeGenerator for Type {
637
635
return ;
638
636
}
639
637
640
- let mut outer_params = item. used_template_params ( ctx)
641
- . and_then ( |ps| if ps. is_empty ( ) {
642
- None
643
- } else {
644
- Some ( ps)
645
- } ) ;
638
+ let used_params = item. used_template_params ( ctx) ;
639
+ let mut outer_params = if used_params. is_empty ( ) { None } else { Some ( used_params) } ;
646
640
647
641
let inner_rust_type = if item. is_opaque ( ctx, & ( ) ) {
648
642
outer_params = None ;
@@ -1598,21 +1592,20 @@ impl CodeGenerator for CompInfo {
1598
1592
1599
1593
let mut generic_param_names = vec ! [ ] ;
1600
1594
1601
- if let Some ( ref params) = used_template_params {
1602
- for ( idx, ty) in params. iter ( ) . enumerate ( ) {
1603
- let param = ctx. resolve_type ( * ty) ;
1604
- let name = param. name ( ) . unwrap ( ) ;
1605
- let ident = ctx. rust_ident ( name) ;
1606
- generic_param_names. push ( ident. clone ( ) ) ;
1607
1595
1608
- let prefix = ctx. trait_prefix ( ) ;
1609
- let field_name = ctx. rust_ident ( format ! ( "_phantom_{}" , idx) ) ;
1610
- fields. push ( quote ! {
1611
- pub #field_name : :: #prefix:: marker:: PhantomData <
1612
- :: #prefix:: cell:: UnsafeCell <#ident>
1613
- > ,
1614
- } ) ;
1615
- }
1596
+ for ( idx, ty) in used_template_params. iter ( ) . enumerate ( ) {
1597
+ let param = ctx. resolve_type ( * ty) ;
1598
+ let name = param. name ( ) . unwrap ( ) ;
1599
+ let ident = ctx. rust_ident ( name) ;
1600
+ generic_param_names. push ( ident. clone ( ) ) ;
1601
+
1602
+ let prefix = ctx. trait_prefix ( ) ;
1603
+ let field_name = ctx. rust_ident ( format ! ( "_phantom_{}" , idx) ) ;
1604
+ fields. push ( quote ! {
1605
+ pub #field_name : :: #prefix:: marker:: PhantomData <
1606
+ :: #prefix:: cell:: UnsafeCell <#ident>
1607
+ > ,
1608
+ } ) ;
1616
1609
}
1617
1610
1618
1611
let generics = if !generic_param_names. is_empty ( ) {
@@ -1657,7 +1650,7 @@ impl CodeGenerator for CompInfo {
1657
1650
derives. push ( "Copy" ) ;
1658
1651
1659
1652
if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ( ) ||
1660
- used_template_params. is_some ( )
1653
+ ! used_template_params. is_empty ( )
1661
1654
{
1662
1655
// FIXME: This requires extra logic if you have a big array in a
1663
1656
// templated struct. The reason for this is that the magic:
@@ -1739,7 +1732,7 @@ impl CodeGenerator for CompInfo {
1739
1732
) ;
1740
1733
}
1741
1734
1742
- if used_template_params. is_none ( ) {
1735
+ if used_template_params. is_empty ( ) {
1743
1736
if !is_opaque {
1744
1737
for var in self . inner_vars ( ) {
1745
1738
ctx. resolve_item ( * var) . codegen ( ctx, result, & ( ) ) ;
@@ -2951,7 +2944,6 @@ impl TryToRustTy for Type {
2951
2944
TypeKind :: TemplateAlias ( ..) |
2952
2945
TypeKind :: Alias ( ..) => {
2953
2946
let template_params = item. used_template_params ( ctx)
2954
- . unwrap_or ( vec ! [ ] )
2955
2947
. into_iter ( )
2956
2948
. filter ( |param| param. is_template_param ( ctx, & ( ) ) )
2957
2949
. collect :: < Vec < _ > > ( ) ;
@@ -2972,7 +2964,7 @@ impl TryToRustTy for Type {
2972
2964
TypeKind :: Comp ( ref info) => {
2973
2965
let template_params = item. used_template_params ( ctx) ;
2974
2966
if info. has_non_type_template_params ( ) ||
2975
- ( item. is_opaque ( ctx, & ( ) ) && template_params. is_some ( ) )
2967
+ ( item. is_opaque ( ctx, & ( ) ) && ! template_params. is_empty ( ) )
2976
2968
{
2977
2969
return self . try_to_opaque ( ctx, item) ;
2978
2970
}
@@ -3066,18 +3058,16 @@ impl TryToRustTy for TemplateInstantiation {
3066
3058
let def_path = def. namespace_aware_canonical_path ( ctx) ;
3067
3059
ty. append_separated ( def_path. into_iter ( ) . map ( |p| ctx. rust_ident ( p) ) , proc_macro2:: Term :: intern ( "::" ) ) ;
3068
3060
3069
- let def_params = match def. self_template_params ( ctx) {
3070
- Some ( params) => params,
3071
- None => {
3072
- // This can happen if we generated an opaque type for a partial
3073
- // template specialization, and we've hit an instantiation of
3074
- // that partial specialization.
3075
- extra_assert ! (
3076
- def. is_opaque( ctx, & ( ) )
3077
- ) ;
3078
- return Err ( error:: Error :: InstantiationOfOpaqueType ) ;
3079
- }
3080
- } ;
3061
+ let def_params = def. self_template_params ( ctx) ;
3062
+ if def_params. is_empty ( ) {
3063
+ // This can happen if we generated an opaque type for a partial
3064
+ // template specialization, and we've hit an instantiation of
3065
+ // that partial specialization.
3066
+ extra_assert ! (
3067
+ def. is_opaque( ctx, & ( ) )
3068
+ ) ;
3069
+ return Err ( error:: Error :: InstantiationOfOpaqueType ) ;
3070
+ }
3081
3071
3082
3072
// TODO: If the definition type is a template class/struct
3083
3073
// definition's member template definition, it could rely on
@@ -3171,10 +3161,8 @@ impl CodeGenerator for Function {
3171
3161
// instantiations is open ended and we have no way of knowing which
3172
3162
// monomorphizations actually exist.
3173
3163
let type_params = item. all_template_params ( ctx) ;
3174
- if let Some ( params) = type_params {
3175
- if !params. is_empty ( ) {
3176
- return ;
3177
- }
3164
+ if !type_params. is_empty ( ) {
3165
+ return ;
3178
3166
}
3179
3167
3180
3168
let name = self . name ( ) ;
0 commit comments