@@ -177,7 +177,7 @@ impl<'a> GenericTypes<'a> {
177
177
if non_lifetimes_processed { return false ; }
178
178
non_lifetimes_processed = true ;
179
179
assert_simple_bound ( & trait_bound) ;
180
- * gen = ( "crate::" . to_string ( ) + & types. resolve_path ( & trait_bound. path ) ,
180
+ * gen = ( "crate::" . to_string ( ) + & types. resolve_path ( & trait_bound. path , None ) ,
181
181
Some ( & trait_bound. path ) ) ;
182
182
}
183
183
}
@@ -700,7 +700,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
700
700
} ,
701
701
"Option" => {
702
702
if let Some ( syn:: Type :: Path ( p) ) = single_contained {
703
- if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path ) ) {
703
+ if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , None ) ) {
704
704
if is_ref {
705
705
return Some ( ( "if " , vec ! [
706
706
( ".is_none() { std::ptr::null() } else { " . to_owned( ) , format!( "({}.as_ref().unwrap())" , var_access) )
@@ -746,7 +746,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
746
746
} ,
747
747
"Option" => {
748
748
if let Some ( syn:: Type :: Path ( p) ) = single_contained {
749
- if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path ) ) {
749
+ if self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , None ) ) {
750
750
if is_ref {
751
751
return Some ( ( "if " , vec ! [ ( ".inner.is_null() { None } else { Some((*" . to_string( ) , format!( "{}" , var_name) ) ] , ").clone()) }" ) )
752
752
} else {
@@ -903,8 +903,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
903
903
} else { None }
904
904
}
905
905
}
906
- pub fn resolve_path ( & self , p : & syn:: Path ) -> String {
907
- self . maybe_resolve_path ( p, None ) . unwrap ( )
906
+ pub fn resolve_path ( & self , p : & syn:: Path , generics : Option < & GenericTypes > ) -> String {
907
+ self . maybe_resolve_path ( p, generics ) . unwrap ( )
908
908
}
909
909
910
910
// ***********************************
@@ -1026,7 +1026,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1026
1026
pub fn write_empty_rust_val < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type ) {
1027
1027
match t {
1028
1028
syn:: Type :: Path ( p) => {
1029
- let resolved = self . resolve_path ( & p. path ) ;
1029
+ let resolved = self . resolve_path ( & p. path , None ) ;
1030
1030
if self . crate_types . opaques . get ( & resolved) . is_some ( ) {
1031
1031
write ! ( w, "crate::{} {{ inner: std::ptr::null_mut(), is_owned: true }}" , resolved) . unwrap ( ) ;
1032
1032
} else {
@@ -1059,7 +1059,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1059
1059
pub fn write_empty_rust_val_check_suffix < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type ) -> bool {
1060
1060
match t {
1061
1061
syn:: Type :: Path ( p) => {
1062
- let resolved = self . resolve_path ( & p. path ) ;
1062
+ let resolved = self . resolve_path ( & p. path , None ) ;
1063
1063
if self . crate_types . opaques . get ( & resolved) . is_some ( ) {
1064
1064
write ! ( w, ".inner.is_null()" ) . unwrap ( ) ;
1065
1065
false
@@ -1164,38 +1164,18 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1164
1164
unimplemented ! ( ) ;
1165
1165
}
1166
1166
1167
- if let Some ( gen_types) = generics {
1168
- if let Some ( ( _, synpath) ) = gen_types. maybe_resolve_path ( & p. path ) {
1169
- let genpath = self . resolve_path ( & synpath) ;
1170
- assert ! ( !self . is_known_container( & genpath, is_ref) && !self . is_transparent_container( & genpath, is_ref) ) ;
1171
- if let Some ( c_type) = path_lookup ( & genpath, is_ref, ptr_for_ref) {
1172
- write ! ( w, "{}" , c_type) . unwrap ( ) ;
1173
- return ;
1174
- } else {
1175
- let synident = single_ident_generic_path_to_ident ( synpath) . unwrap ( ) ;
1176
- if let Some ( t) = self . crate_types . traits . get ( & genpath) {
1177
- decl_lookup ( w, & DeclType :: Trait ( t) , & genpath, is_ref, is_mut) ;
1178
- return ;
1179
- } else if let Some ( _) = self . imports . get ( synident) {
1180
- // crate_types lookup has to have succeeded:
1181
- panic ! ( "Failed to print inline conversion for {}" , synident) ;
1182
- } else if let Some ( decl_type) = self . declared . get ( synident) {
1183
- decl_lookup ( w, decl_type, & self . maybe_resolve_path ( synpath, None ) . unwrap ( ) , is_ref, is_mut) ;
1184
- return ;
1185
- } else { unimplemented ! ( ) ; }
1186
- }
1187
- }
1188
- }
1189
-
1190
- let resolved_path = self . resolve_path ( & p. path ) ;
1167
+ let resolved_path = self . resolve_path ( & p. path , generics) ;
1191
1168
if let Some ( c_type) = path_lookup ( & resolved_path, is_ref, ptr_for_ref) {
1192
1169
write ! ( w, "{}" , c_type) . unwrap ( ) ;
1193
1170
} else if self . crate_types . opaques . get ( & resolved_path) . is_some ( ) {
1194
1171
decl_lookup ( w, & DeclType :: StructImported , & resolved_path, is_ref, is_mut) ;
1195
1172
} else if self . crate_types . mirrored_enums . get ( & resolved_path) . is_some ( ) {
1196
1173
decl_lookup ( w, & DeclType :: MirroredEnum , & resolved_path, is_ref, is_mut) ;
1197
1174
} else if let Some ( ident) = single_ident_generic_path_to_ident ( & p. path ) {
1198
- if let Some ( _) = self . imports . get ( ident) {
1175
+ if let Some ( t) = self . crate_types . traits . get ( & resolved_path) {
1176
+ decl_lookup ( w, & DeclType :: Trait ( t) , & resolved_path, is_ref, is_mut) ;
1177
+ return ;
1178
+ } else if let Some ( _) = self . imports . get ( ident) {
1199
1179
// crate_types lookup has to have succeeded:
1200
1180
panic ! ( "Failed to print inline conversion for {}" , ident) ;
1201
1181
} else if let Some ( decl_type) = self . declared . get ( ident) {
@@ -1216,12 +1196,12 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1216
1196
// We assume all slices contain only literals or references.
1217
1197
// This may result in some outputs not compiling.
1218
1198
if let syn:: Type :: Path ( p) = & * s. elem {
1219
- let resolved = self . resolve_path ( & p. path ) ;
1199
+ let resolved = self . resolve_path ( & p. path , generics ) ;
1220
1200
assert ! ( self . is_primitive( & resolved) ) ;
1221
1201
write ! ( w, "{}" , path_lookup( "[u8]" , is_ref, ptr_for_ref) . unwrap( ) ) . unwrap ( ) ;
1222
1202
} else if let syn:: Type :: Reference ( r) = & * s. elem {
1223
1203
if let syn:: Type :: Path ( p) = & * r. elem {
1224
- write ! ( w, "{}" , sliceconv( self . c_type_has_inner_from_path( & self . resolve_path( & p. path) ) ) ) . unwrap ( ) ;
1204
+ write ! ( w, "{}" , sliceconv( self . c_type_has_inner_from_path( & self . resolve_path( & p. path, generics ) ) ) ) . unwrap ( ) ;
1225
1205
} else { unimplemented ! ( ) ; }
1226
1206
} else { unimplemented ! ( ) ; }
1227
1207
} ,
@@ -1374,10 +1354,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1374
1354
}
1375
1355
if let syn:: Type :: Reference ( t) = ty {
1376
1356
if let syn:: Type :: Path ( p) = & * t. elem {
1377
- self . c_type_has_inner_from_path( & self . resolve_path( & p. path) )
1357
+ self . c_type_has_inner_from_path( & self . resolve_path( & p. path, generics ) )
1378
1358
} else { false }
1379
1359
} else if let syn:: Type :: Path ( p) = ty {
1380
- self . c_type_has_inner_from_path( & self . resolve_path( & p. path) )
1360
+ self . c_type_has_inner_from_path( & self . resolve_path( & p. path, generics ) )
1381
1361
} else { false }
1382
1362
} else { true } ;
1383
1363
@@ -1469,16 +1449,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1469
1449
if p. qself . is_some ( ) || p. path . leading_colon . is_some ( ) {
1470
1450
unimplemented ! ( ) ;
1471
1451
}
1472
- if let Some ( gen_types) = generics {
1473
- if let Some ( resolved) = gen_types. maybe_resolve_path ( & p. path ) {
1474
- assert ! ( !self . is_known_container( & resolved. 0 , is_ref) && !self . is_transparent_container( & resolved. 0 , is_ref) ) ;
1475
- if let Some ( ( prefix, suffix) ) = path_lookup ( & resolved. 0 , is_ref) {
1476
- write ! ( w, "let mut local_{} = {}{}{};" , ident, prefix, var, suffix) . unwrap ( ) ;
1477
- return true ;
1478
- } else { return false ; }
1479
- }
1480
- }
1481
- let resolved_path = self . resolve_path ( & p. path ) ;
1452
+ let resolved_path = self . resolve_path ( & p. path , generics) ;
1482
1453
if self . is_known_container ( & resolved_path, is_ref) || self . is_transparent_container ( & resolved_path, is_ref) {
1483
1454
if let syn:: PathArguments :: AngleBracketed ( args) = & p. path . segments . iter ( ) . next ( ) . unwrap ( ) . arguments {
1484
1455
convert_container ! ( resolved_path, args. args. len( ) , || args. args. iter( ) . map( |arg| {
@@ -1506,7 +1477,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1506
1477
} ,
1507
1478
syn:: Type :: Slice ( s) => {
1508
1479
if let syn:: Type :: Path ( p) = & * s. elem {
1509
- let resolved = self . resolve_path ( & p. path ) ;
1480
+ let resolved = self . resolve_path ( & p. path , generics ) ;
1510
1481
assert ! ( self . is_primitive( & resolved) ) ;
1511
1482
let slice_path = format ! ( "[{}]" , resolved) ;
1512
1483
if let Some ( ( prefix, suffix) ) = path_lookup ( & slice_path, true ) {
@@ -1543,7 +1514,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1543
1514
// Opaque types with inner pointers shouldn't ever create new stack
1544
1515
// variables, so we don't handle it and just assert that it doesn't
1545
1516
// here.
1546
- assert ! ( !self . c_type_has_inner_from_path( & self . resolve_path( & p. path) ) ) ;
1517
+ assert ! ( !self . c_type_has_inner_from_path( & self . resolve_path( & p. path, generics ) ) ) ;
1547
1518
}
1548
1519
}
1549
1520
}
@@ -1558,10 +1529,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1558
1529
}
1559
1530
if let syn:: Type :: Reference ( t) = elem {
1560
1531
if let syn:: Type :: Path ( p) = & * t. elem {
1561
- self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path ) )
1532
+ self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , generics ) )
1562
1533
} else { false }
1563
1534
} else if let syn:: Type :: Path ( p) = elem {
1564
- self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path ) )
1535
+ self . c_type_has_inner_from_path ( & self . resolve_path ( & p. path , generics ) )
1565
1536
} else { false }
1566
1537
} ;
1567
1538
if idx != 0 { write ! ( w, ", " ) . unwrap ( ) ; }
@@ -1624,7 +1595,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1624
1595
( $call: expr, $item: expr) => { {
1625
1596
write!( w, "#[no_mangle]\n pub static {}_{}: extern \" C\" fn (" , mangled_container, $call) . unwrap( ) ;
1626
1597
if let syn:: Type :: Path ( syn:: TypePath { path, .. } ) = $item {
1627
- let resolved = self . resolve_path( path) ;
1598
+ let resolved = self . resolve_path( path, generics ) ;
1628
1599
if self . is_known_container( & resolved, is_ref) || self . is_transparent_container( & resolved, is_ref) {
1629
1600
self . write_c_mangled_container_path_intern( generics, w, Self :: path_to_generic_args( path) ,
1630
1601
& format!( "{}" , single_ident_generic_path_to_ident( path) . unwrap( ) ) , is_ref, false , false , false ) ;
@@ -1679,7 +1650,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1679
1650
write ! ( w, ">" ) . unwrap ( ) ;
1680
1651
}
1681
1652
} else if let syn:: Type :: Path ( p_arg) = t {
1682
- let resolved_generic = self . resolve_path ( & p_arg. path ) ;
1653
+ let resolved_generic = self . resolve_path ( & p_arg. path , None ) ;
1683
1654
if self . is_primitive ( & resolved_generic) {
1684
1655
write ! ( w, "{}" , resolved_generic) . unwrap ( ) ;
1685
1656
} else if let Some ( c_type) = self . c_type_from_path ( & resolved_generic, is_ref, false ) {
@@ -1721,7 +1692,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1721
1692
}
1722
1693
} else if let syn:: Type :: Reference ( r_arg) = t {
1723
1694
if let syn:: Type :: Path ( p_arg) = & * r_arg. elem {
1724
- let resolved = self . resolve_path ( & p_arg. path ) ;
1695
+ let resolved = self . resolve_path ( & p_arg. path , None ) ;
1725
1696
if single_ident_generic_path_to_ident ( & p_arg. path ) . is_some ( ) {
1726
1697
if self . crate_types . opaques . get ( & resolved) . is_some ( ) {
1727
1698
write ! ( w, "crate::{}" , resolved) . unwrap ( ) ;
@@ -1730,7 +1701,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1730
1701
} else { unimplemented ! ( ) ; }
1731
1702
} else if let syn:: Type :: Array ( a_arg) = t {
1732
1703
if let syn:: Type :: Path ( p_arg) = & * a_arg. elem {
1733
- let resolved = self . resolve_path ( & p_arg. path ) ;
1704
+ let resolved = self . resolve_path ( & p_arg. path , None ) ;
1734
1705
assert ! ( self . is_primitive( & resolved) ) ;
1735
1706
if let syn:: Expr :: Lit ( syn:: ExprLit { lit : syn:: Lit :: Int ( len) , .. } ) = & a_arg. len {
1736
1707
write ! ( w, "{}" ,
@@ -1775,7 +1746,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1775
1746
for arg in args. iter ( ) {
1776
1747
macro_rules! write_path {
1777
1748
( $p_arg: expr, $extra_write: expr) => {
1778
- let subtype = self . resolve_path( & $p_arg. path) ;
1749
+ let subtype = self . resolve_path( & $p_arg. path, generics ) ;
1779
1750
if self . is_transparent_container( ident, is_ref) {
1780
1751
// We dont (yet) support primitives or containers inside transparent
1781
1752
// containers, so check for that first:
@@ -1855,7 +1826,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1855
1826
} else { return false ; }
1856
1827
} else if let syn:: Type :: Array ( a) = arg {
1857
1828
if let syn:: Type :: Path ( p_arg) = & * a. elem {
1858
- let resolved = self . resolve_path ( & p_arg. path ) ;
1829
+ let resolved = self . resolve_path ( & p_arg. path , generics ) ;
1859
1830
if !self . is_primitive ( & resolved) { return false ; }
1860
1831
if let syn:: Expr :: Lit ( syn:: ExprLit { lit : syn:: Lit :: Int ( len) , .. } ) = & a. len {
1861
1832
if self . c_type_from_path ( & format ! ( "[{}; {}]" , resolved, len. base10_digits( ) ) , is_ref, ptr_for_ref) . is_none ( ) { return false ; }
@@ -1966,15 +1937,15 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
1966
1937
syn:: Type :: Slice ( s) => {
1967
1938
if !is_ref || is_mut { return false ; }
1968
1939
if let syn:: Type :: Path ( p) = & * s. elem {
1969
- let resolved = self . resolve_path ( & p. path ) ;
1940
+ let resolved = self . resolve_path ( & p. path , generics ) ;
1970
1941
if self . is_primitive ( & resolved) {
1971
1942
write ! ( w, "{}::{}slice" , Self :: container_templ_path( ) , resolved) . unwrap ( ) ;
1972
1943
true
1973
1944
} else { false }
1974
1945
} else if let syn:: Type :: Reference ( r) = & * s. elem {
1975
1946
if let syn:: Type :: Path ( p) = & * r. elem {
1976
1947
// Slices with "real types" inside are mapped as the equivalent non-ref Vec
1977
- let resolved = self . resolve_path ( & p. path ) ;
1948
+ let resolved = self . resolve_path ( & p. path , generics ) ;
1978
1949
let mangled_container = if let Some ( ident) = self . crate_types . opaques . get ( & resolved) {
1979
1950
format ! ( "CVec_{}Z" , ident)
1980
1951
} else if let Some ( en) = self . crate_types . mirrored_enums . get ( & resolved) {
0 commit comments