@@ -2248,7 +2248,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2248
2248
}
2249
2249
2250
2250
fn write_conversion_inline_intern < W : std:: io:: Write ,
2251
- LP : Fn ( & str , bool , bool ) -> Option < String > , DL : Fn ( & mut W , & DeclType , & str , bool , bool ) , SC : Fn ( bool , Option < & str > ) -> String >
2251
+ LP : Fn ( & str , bool , bool ) -> Option < String > , DL : Fn ( & mut W , & DeclType , & str , bool , bool , bool ) , SC : Fn ( bool , Option < & str > ) -> String >
2252
2252
( & self , w : & mut W , t : & syn:: Type , generics : Option < & GenericTypes > , is_ref : bool , is_mut : bool , ptr_for_ref : bool ,
2253
2253
tupleconv : & str , prefix : bool , sliceconv : SC , path_lookup : LP , decl_lookup : DL ) {
2254
2254
match generics. resolve_type ( t) {
@@ -2271,14 +2271,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2271
2271
} else if let Some ( c_type) = path_lookup ( & resolved_path, is_ref, ptr_for_ref) {
2272
2272
write ! ( w, "{}" , c_type) . unwrap ( ) ;
2273
2273
} else if let Some ( ( _, generics) ) = self . crate_types . opaques . get ( & resolved_path) {
2274
- decl_lookup ( w, & DeclType :: StructImported { generics : & generics } , & resolved_path, is_ref, is_mut) ;
2274
+ decl_lookup ( w, & DeclType :: StructImported { generics : & generics } , & resolved_path, is_ref, is_mut, false ) ;
2275
2275
} else if self . crate_types . mirrored_enums . get ( & resolved_path) . is_some ( ) {
2276
- decl_lookup ( w, & DeclType :: MirroredEnum , & resolved_path, is_ref, is_mut) ;
2276
+ decl_lookup ( w, & DeclType :: MirroredEnum , & resolved_path, is_ref, is_mut, false ) ;
2277
2277
} else if let Some ( t) = self . crate_types . traits . get ( & resolved_path) {
2278
- decl_lookup ( w, & DeclType :: Trait ( t) , & resolved_path, is_ref, is_mut) ;
2278
+ decl_lookup ( w, & DeclType :: Trait ( t) , & resolved_path, is_ref, is_mut, false ) ;
2279
2279
} else if let Some ( ident) = single_ident_generic_path_to_ident ( & p. path ) {
2280
2280
if let Some ( decl_type) = self . types . maybe_resolve_declared ( ident) {
2281
- decl_lookup ( w, decl_type, & self . maybe_resolve_ident ( ident) . unwrap ( ) , is_ref, is_mut) ;
2281
+ decl_lookup ( w, decl_type, & self . maybe_resolve_ident ( ident) . unwrap ( ) , is_ref, is_mut, false ) ;
2282
2282
} else { unimplemented ! ( ) ; }
2283
2283
} else {
2284
2284
if let Some ( trait_impls) = self . crate_types . traits_impld . get ( & resolved_path) {
@@ -2287,7 +2287,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2287
2287
// in the whole crate, just treat it as a reference to whatever the
2288
2288
// implementor is.
2289
2289
let implementor = self . crate_types . opaques . get ( & trait_impls[ 0 ] ) . unwrap ( ) ;
2290
- decl_lookup ( w, & DeclType :: StructImported { generics : & implementor. 1 } , & trait_impls[ 0 ] , true , is_mut) ;
2290
+ decl_lookup ( w, & DeclType :: StructImported { generics : & implementor. 1 } , & trait_impls[ 0 ] , true , is_mut, true ) ;
2291
2291
return ;
2292
2292
}
2293
2293
}
@@ -2371,11 +2371,14 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2371
2371
fn write_to_c_conversion_inline_prefix_inner < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type , generics : Option < & GenericTypes > , is_ref : bool , ptr_for_ref : bool , from_ptr : bool ) {
2372
2372
self . write_conversion_inline_intern ( w, t, generics, is_ref, false , ptr_for_ref, "() /*" , true , |_, _| "local_" . to_owned ( ) ,
2373
2373
|a, b, c| self . to_c_conversion_inline_prefix_from_path ( a, b, c) ,
2374
- |w, decl_type, decl_path, is_ref, _is_mut| {
2374
+ |w, decl_type, decl_path, is_ref, _is_mut, is_trait_alias | {
2375
2375
match decl_type {
2376
2376
DeclType :: MirroredEnum if is_ref && ptr_for_ref => write ! ( w, "crate::{}::from_native(" , decl_path) . unwrap ( ) ,
2377
2377
DeclType :: MirroredEnum if is_ref => write ! ( w, "&crate::{}::from_native(" , decl_path) . unwrap ( ) ,
2378
2378
DeclType :: MirroredEnum => write ! ( w, "crate::{}::native_into(" , decl_path) . unwrap ( ) ,
2379
+ DeclType :: StructImported { ..} if is_trait_alias => {
2380
+ if is_ref { write ! ( w, "&" ) . unwrap ( ) ; }
2381
+ } ,
2379
2382
DeclType :: EnumIgnored { ..} |DeclType :: StructImported { ..} if is_ref && from_ptr => {
2380
2383
if !ptr_for_ref { write ! ( w, "&" ) . unwrap ( ) ; }
2381
2384
write ! ( w, "crate::{} {{ inner: unsafe {{ (" , decl_path) . unwrap ( )
@@ -2400,8 +2403,11 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2400
2403
fn write_to_c_conversion_inline_suffix_inner < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type , generics : Option < & GenericTypes > , is_ref : bool , ptr_for_ref : bool , from_ptr : bool ) {
2401
2404
self . write_conversion_inline_intern ( w, t, generics, is_ref, false , ptr_for_ref, "*/" , false , |_, _| ".into()" . to_owned ( ) ,
2402
2405
|a, b, c| self . to_c_conversion_inline_suffix_from_path ( a, b, c) ,
2403
- |w, decl_type, full_path, is_ref, _is_mut| match decl_type {
2406
+ |w, decl_type, full_path, is_ref, _is_mut, is_trait_alias | match decl_type {
2404
2407
DeclType :: MirroredEnum => write ! ( w, ")" ) . unwrap ( ) ,
2408
+ DeclType :: StructImported { ..} if is_trait_alias => {
2409
+ write ! ( w, ".as_ref_to()" ) . unwrap ( ) ;
2410
+ } ,
2405
2411
DeclType :: EnumIgnored { generics } |DeclType :: StructImported { generics } if is_ref => {
2406
2412
write ! ( w, " as *const {}<" , full_path) . unwrap ( ) ;
2407
2413
for param in generics. params . iter ( ) {
@@ -2438,7 +2444,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2438
2444
fn write_from_c_conversion_prefix_inner < W : std:: io:: Write > ( & self , w : & mut W , t : & syn:: Type , generics : Option < & GenericTypes > , is_ref : bool , _ptr_for_ref : bool ) {
2439
2445
self . write_conversion_inline_intern ( w, t, generics, is_ref, false , false , "() /*" , true , |_, _| "&local_" . to_owned ( ) ,
2440
2446
|a, b, _c| self . from_c_conversion_prefix_from_path ( a, b) ,
2441
- |w, decl_type, _full_path, is_ref, _is_mut| match decl_type {
2447
+ |w, decl_type, _full_path, is_ref, _is_mut, _is_trait_alias | match decl_type {
2442
2448
DeclType :: StructImported { ..} if is_ref => write ! ( w, "" ) . unwrap ( ) ,
2443
2449
DeclType :: StructImported { ..} if !is_ref => write ! ( w, "*unsafe {{ Box::from_raw(" ) . unwrap ( ) ,
2444
2450
DeclType :: MirroredEnum if is_ref => write ! ( w, "&" ) . unwrap ( ) ,
@@ -2459,7 +2465,8 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2459
2465
( true , Some ( _) ) => unreachable ! ( ) ,
2460
2466
} ,
2461
2467
|a, b, _c| self . from_c_conversion_suffix_from_path ( a, b) ,
2462
- |w, decl_type, _full_path, is_ref, is_mut| match decl_type {
2468
+ |w, decl_type, _full_path, is_ref, is_mut, is_trait_alias| match decl_type {
2469
+ DeclType :: StructImported { ..} if is_trait_alias => write ! ( w, ".as_ref_to()" ) . unwrap ( ) ,
2463
2470
DeclType :: StructImported { ..} if is_ref && ptr_for_ref => write ! ( w, "XXX unimplemented" ) . unwrap ( ) ,
2464
2471
DeclType :: StructImported { ..} if is_mut && is_ref => write ! ( w, ".get_native_mut_ref()" ) . unwrap ( ) ,
2465
2472
DeclType :: StructImported { ..} if is_ref => write ! ( w, ".get_native_ref()" ) . unwrap ( ) ,
@@ -2482,7 +2489,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2482
2489
Some ( format ! ( "&{}" , conv) )
2483
2490
} else { None }
2484
2491
} ,
2485
- |w, decl_type, _full_path, is_ref, _is_mut| match decl_type {
2492
+ |w, decl_type, _full_path, is_ref, _is_mut, _is_trait_alias | match decl_type {
2486
2493
DeclType :: StructImported { ..} if !is_ref => write ! ( w, "" ) . unwrap ( ) ,
2487
2494
_ => unimplemented ! ( ) ,
2488
2495
} ) ;
@@ -2496,7 +2503,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
2496
2503
( true , Some ( _) ) => unreachable ! ( ) ,
2497
2504
} ,
2498
2505
|a, b, _c| self . from_c_conversion_suffix_from_path ( a, b) ,
2499
- |w, decl_type, _full_path, is_ref, _is_mut| match decl_type {
2506
+ |w, decl_type, _full_path, is_ref, _is_mut, _is_trait_alias | match decl_type {
2500
2507
DeclType :: StructImported { ..} if !is_ref => write ! ( w, ".get_native_ref()" ) . unwrap ( ) ,
2501
2508
_ => unimplemented ! ( ) ,
2502
2509
} ) ;
0 commit comments