@@ -17,7 +17,10 @@ use self::struct_layout::StructLayoutTracker;
17
17
18
18
use super :: BindgenOptions ;
19
19
20
- use crate :: codegen:: helpers:: { CppSemanticAttributeAdder , CppSemanticAttributeCreator , CppSemanticAttributeSingle } ;
20
+ use crate :: codegen:: helpers:: {
21
+ CppSemanticAttributeAdder , CppSemanticAttributeCreator ,
22
+ CppSemanticAttributeSingle ,
23
+ } ;
21
24
use crate :: ir:: analysis:: { HasVtable , Sizedness } ;
22
25
use crate :: ir:: annotations:: FieldAccessorKind ;
23
26
use crate :: ir:: comment;
@@ -898,7 +901,8 @@ impl CodeGenerator for Type {
898
901
} else {
899
902
quote ! { }
900
903
} ;
901
- let mut semantic_annotations = CppSemanticAttributeSingle :: new ( ctx. options ( ) ) ;
904
+ let mut semantic_annotations =
905
+ CppSemanticAttributeSingle :: new ( ctx. options ( ) ) ;
902
906
// We are handling (essentially) type X = Y;
903
907
// We want to denote only if X has unused template params, e.g.
904
908
// type X<A> = Y;
@@ -944,7 +948,11 @@ impl CodeGenerator for Type {
944
948
let mut attributes = Vec :: new ( ) ;
945
949
if let Some ( original_name) = item. original_name ( ctx) {
946
950
if name != original_name {
947
- let mut semantic_annotations = CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attributes) ;
951
+ let mut semantic_annotations =
952
+ CppSemanticAttributeAdder :: new (
953
+ ctx. options ( ) ,
954
+ & mut attributes,
955
+ ) ;
948
956
semantic_annotations. original_name ( & original_name) ;
949
957
}
950
958
}
@@ -1112,8 +1120,8 @@ impl<'a> CodeGenerator for Vtable<'a> {
1112
1120
1113
1121
// FIXME: Need to account for overloading with times_seen (separately from regular function path).
1114
1122
let function_name = ctx. rust_ident ( function_name) ;
1115
- let mut args = utils:: fnsig_arguments ( ctx, signature) ;
1116
- let ret = utils:: fnsig_return_ty ( ctx, signature) ;
1123
+ let ( mut args, _ ) = utils:: fnsig_arguments ( ctx, signature) ;
1124
+ let ( ret, _ ) = utils:: fnsig_return_ty ( ctx, signature) ;
1117
1125
1118
1126
args[ 0 ] = if m. is_const ( ) {
1119
1127
quote ! { this: * const #class_ident }
@@ -1338,9 +1346,7 @@ impl<'a> FieldCodegen<'a> for FieldData {
1338
1346
let field_item =
1339
1347
self . ty ( ) . into_resolver ( ) . through_type_refs ( ) . resolve ( ctx) ;
1340
1348
let field_ty = field_item. expect_type ( ) ;
1341
- let ty = self
1342
- . ty ( )
1343
- . to_rust_ty_or_opaque ( ctx, & ( ) ) ;
1349
+ let ty = self . ty ( ) . to_rust_ty_or_opaque ( ctx, & ( ) ) ;
1344
1350
let ( mut ty, ty_annotations) = ty. to_outer_type ( ) ;
1345
1351
ty. append_implicit_template_params ( ctx, field_item) ;
1346
1352
@@ -1406,10 +1412,13 @@ impl<'a> FieldCodegen<'a> for FieldData {
1406
1412
self . annotations ( ) . accessor_kind ( ) . unwrap_or ( accessor_kind) ;
1407
1413
1408
1414
let mut attributes = Vec :: new ( ) ;
1409
- let mut csaa = CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attributes) ;
1415
+ let mut csaa =
1416
+ CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attributes) ;
1410
1417
match ty_annotations {
1411
1418
RustTyAnnotation :: Reference => csaa. field_type_reference ( ) ,
1412
- RustTyAnnotation :: RValueReference => csaa. field_type_rvalue_reference ( ) ,
1419
+ RustTyAnnotation :: RValueReference => {
1420
+ csaa. field_type_rvalue_reference ( )
1421
+ }
1413
1422
_ => { }
1414
1423
} ;
1415
1424
@@ -2076,7 +2085,8 @@ impl CodeGenerator for CompInfo {
2076
2085
} else {
2077
2086
attributes. push ( attributes:: repr ( "C" ) ) ;
2078
2087
}
2079
- let mut semantic_annotations = CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attributes) ;
2088
+ let mut semantic_annotations =
2089
+ CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attributes) ;
2080
2090
if unused_template_params {
2081
2091
semantic_annotations. discards_template_param ( ) ;
2082
2092
}
@@ -2144,7 +2154,10 @@ impl CodeGenerator for CompInfo {
2144
2154
2145
2155
if let Some ( original_name) = item. original_name ( ctx) {
2146
2156
if canonical_name != original_name {
2147
- let mut semantic_annotations = CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attributes) ;
2157
+ let mut semantic_annotations = CppSemanticAttributeAdder :: new (
2158
+ ctx. options ( ) ,
2159
+ & mut attributes,
2160
+ ) ;
2148
2161
semantic_annotations. original_name ( & original_name) ;
2149
2162
}
2150
2163
}
@@ -3100,7 +3113,8 @@ impl CodeGenerator for Enum {
3100
3113
3101
3114
let mut attrs = vec ! [ ] ;
3102
3115
3103
- let mut semantic_annotations = CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attrs) ;
3116
+ let mut semantic_annotations =
3117
+ CppSemanticAttributeAdder :: new ( ctx. options ( ) , & mut attrs) ;
3104
3118
if let Some ( original_name) = item. original_name ( ctx) {
3105
3119
if name != original_name {
3106
3120
semantic_annotations. original_name ( & original_name) ;
@@ -3698,7 +3712,8 @@ impl RustTy {
3698
3712
inner : RustTyAnnotation ,
3699
3713
) -> Self {
3700
3714
let annotation = match inner {
3701
- RustTyAnnotation :: HasUnusedTemplateArgs | RustTyAnnotation :: Opaque => inner,
3715
+ RustTyAnnotation :: HasUnusedTemplateArgs |
3716
+ RustTyAnnotation :: Opaque => inner,
3702
3717
_ => RustTyAnnotation :: Reference ,
3703
3718
} ;
3704
3719
Self { ts, annotation }
@@ -3709,7 +3724,8 @@ impl RustTy {
3709
3724
inner : RustTyAnnotation ,
3710
3725
) -> Self {
3711
3726
let annotation = match inner {
3712
- RustTyAnnotation :: HasUnusedTemplateArgs | RustTyAnnotation :: Opaque => inner,
3727
+ RustTyAnnotation :: HasUnusedTemplateArgs |
3728
+ RustTyAnnotation :: Opaque => inner,
3713
3729
_ => RustTyAnnotation :: RValueReference ,
3714
3730
} ;
3715
3731
Self { ts, annotation }
@@ -3806,7 +3822,9 @@ impl TryToRustTy for Type {
3806
3822
IntKind :: I8 => Ok ( quote ! { i8 } . into ( ) ) ,
3807
3823
IntKind :: U8 => Ok ( quote ! { u8 } . into ( ) ) ,
3808
3824
IntKind :: I16 => Ok ( quote ! { i16 } . into ( ) ) ,
3809
- IntKind :: U16 if ctx. options ( ) . use_distinct_char16_t => Ok ( quote ! { c_char16_t } . into ( ) ) ,
3825
+ IntKind :: U16 if ctx. options ( ) . use_distinct_char16_t => {
3826
+ Ok ( quote ! { c_char16_t } . into ( ) )
3827
+ }
3810
3828
IntKind :: U16 => Ok ( quote ! { u16 } . into ( ) ) ,
3811
3829
IntKind :: I32 => Ok ( quote ! { i32 } . into ( ) ) ,
3812
3830
IntKind :: U32 => Ok ( quote ! { u32 } . into ( ) ) ,
@@ -4103,7 +4121,7 @@ impl TryToRustTy for FunctionSig {
4103
4121
if !ctx. options ( ) . rust_features ( ) . vectorcall_abi =>
4104
4122
{
4105
4123
warn ! ( "Skipping function with vectorcall ABI that isn't supported by the configured Rust target" ) ;
4106
- Ok ( proc_macro2:: TokenStream :: new ( ) )
4124
+ Ok ( proc_macro2:: TokenStream :: new ( ) . into ( ) )
4107
4125
}
4108
4126
_ => Ok ( quote ! {
4109
4127
unsafe extern #abi fn ( #( #arguments ) , * ) #ret
@@ -4136,22 +4154,25 @@ impl CodeGenerator for Function {
4136
4154
Linkage :: External => { }
4137
4155
}
4138
4156
4139
- // Pure virtual methods have no actual symbol, so we can't generate
4140
- // something meaningful for them.
4141
- let is_dynamic_function = match self . kind ( ) {
4142
- FunctionKind :: Method ( ref method_kind)
4143
- if method_kind. is_pure_virtual ( ) =>
4144
- {
4145
- true
4157
+ let is_pure_virtual = match self . kind ( ) {
4158
+ FunctionKind :: Method ( ref method_kind) => {
4159
+ method_kind. is_pure_virtual ( )
4146
4160
}
4161
+ _ => false ,
4162
+ } ;
4163
+
4164
+ let is_virtual = matches ! (
4165
+ self . kind( ) ,
4166
+ FunctionKind :: Method ( MethodKind :: Virtual { .. } )
4167
+ ) ;
4168
+
4169
+ let is_dynamic_function = match self . kind ( ) {
4147
4170
FunctionKind :: Function => {
4148
4171
ctx. options ( ) . dynamic_library_name . is_some ( )
4149
4172
}
4150
4173
_ => false ,
4151
4174
} ;
4152
4175
4153
- let is_virtual = matches ! ( self . kind( ) , FunctionKind :: Method ( MethodKind :: Virtual { .. } ) ) ;
4154
-
4155
4176
// Similar to static member variables in a class template, we can't
4156
4177
// generate bindings to template functions, because the set of
4157
4178
// instantiations is open ended and we have no way of knowing which
@@ -4207,7 +4228,8 @@ impl CodeGenerator for Function {
4207
4228
attributes. push ( attributes:: doc ( comment) ) ;
4208
4229
}
4209
4230
4210
- let mut semantic_annotations = CppSemanticAttributeAdder :: new ( & ctx. options ( ) , & mut attributes) ;
4231
+ let mut semantic_annotations =
4232
+ CppSemanticAttributeAdder :: new ( & ctx. options ( ) , & mut attributes) ;
4211
4233
4212
4234
if is_pure_virtual {
4213
4235
semantic_annotations. is_pure_virtual ( ) ;
@@ -4625,10 +4647,10 @@ pub(crate) fn codegen(
4625
4647
}
4626
4648
4627
4649
pub mod utils {
4628
- use super :: {
4629
- error, RustTy , RustTyAnnotation , ToRustTyOrOpaque ,
4650
+ use super :: { error, RustTy , RustTyAnnotation , ToRustTyOrOpaque } ;
4651
+ use crate :: codegen:: helpers:: {
4652
+ CppSemanticAttributeCreator , CppSemanticAttributeSingle ,
4630
4653
} ;
4631
- use crate :: codegen:: helpers:: { CppSemanticAttributeSingle , CppSemanticAttributeCreator } ;
4632
4654
use crate :: ir:: context:: BindgenContext ;
4633
4655
use crate :: ir:: function:: { Abi , FunctionSig } ;
4634
4656
use crate :: ir:: item:: { Item , ItemCanonicalPath } ;
@@ -4958,23 +4980,21 @@ pub mod utils {
4958
4980
let ts = quote ! {
4959
4981
-> #ret_ty
4960
4982
} ;
4961
- let mut semantic_annotation = CppSemanticAttributeSingle :: new ( ctx. options ( ) ) ;
4983
+ let mut semantic_annotation =
4984
+ CppSemanticAttributeSingle :: new ( ctx. options ( ) ) ;
4962
4985
match annotations {
4963
- super :: RustTyAnnotation :: None => { } ,
4986
+ super :: RustTyAnnotation :: None => { }
4964
4987
super :: RustTyAnnotation :: Reference => {
4965
4988
semantic_annotation. ret_type_reference ( )
4966
4989
}
4967
4990
super :: RustTyAnnotation :: RValueReference => {
4968
4991
semantic_annotation. ret_type_rvalue_reference ( )
4969
4992
}
4970
- super :: RustTyAnnotation :: HasUnusedTemplateArgs | super :: RustTyAnnotation :: Opaque => {
4971
- semantic_annotation. incomprehensible_param_in_arg_or_return ( )
4972
- }
4993
+ super :: RustTyAnnotation :: HasUnusedTemplateArgs |
4994
+ super :: RustTyAnnotation :: Opaque => semantic_annotation
4995
+ . incomprehensible_param_in_arg_or_return ( ) ,
4973
4996
} ;
4974
- (
4975
- ts,
4976
- semantic_annotation. result ( )
4977
- )
4997
+ ( ts, semantic_annotation. result ( ) )
4978
4998
}
4979
4999
}
4980
5000
@@ -5042,25 +5062,26 @@ pub mod utils {
5042
5062
5043
5063
assert ! ( !arg_name. is_empty( ) ) ;
5044
5064
let arg_name = ctx. rust_ident ( arg_name) ;
5045
- let mut semantic_annotation = CppSemanticAttributeSingle :: new ( ctx. options ( ) ) ;
5065
+ let mut semantic_annotation =
5066
+ CppSemanticAttributeSingle :: new ( ctx. options ( ) ) ;
5046
5067
match arg_details. annotation {
5047
- RustTyAnnotation :: None => { } ,
5068
+ RustTyAnnotation :: None => { }
5048
5069
RustTyAnnotation :: Reference => {
5049
5070
semantic_annotation. arg_type_reference ( & arg_name)
5050
5071
}
5051
5072
RustTyAnnotation :: RValueReference => {
5052
5073
semantic_annotation. arg_type_rvalue_reference ( & arg_name)
5053
5074
}
5054
- RustTyAnnotation :: HasUnusedTemplateArgs | RustTyAnnotation :: Opaque => {
5055
- semantic_annotation. incomprehensible_param_in_arg_or_return ( )
5056
- }
5075
+ RustTyAnnotation :: HasUnusedTemplateArgs |
5076
+ RustTyAnnotation :: Opaque => semantic_annotation
5077
+ . incomprehensible_param_in_arg_or_return ( ) ,
5057
5078
} ;
5058
5079
5059
5080
(
5060
5081
quote ! {
5061
5082
#arg_name : #arg_ty
5062
5083
} ,
5063
- semantic_annotation. result ( )
5084
+ semantic_annotation. result ( ) ,
5064
5085
)
5065
5086
} )
5066
5087
. unzip ( ) ;
0 commit comments