@@ -1169,7 +1169,7 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
11691169
11701170 let resource_methods = funcs. remove ( & Some ( * id) ) . unwrap_or ( Vec :: new ( ) ) ;
11711171 let trait_name = format ! ( "{path}::Guest{camel}" ) ;
1172- self . generate_stub_impl ( & trait_name, "" , & resource_methods) ;
1172+ self . generate_stub_impl ( & trait_name, "" , & resource_methods, interface ) ;
11731173 }
11741174 format ! ( "{path}::Guest" )
11751175 }
@@ -1180,7 +1180,7 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
11801180 } ;
11811181
11821182 if !root_methods. is_empty ( ) || !extra_trait_items. is_empty ( ) {
1183- self . generate_stub_impl ( & guest_trait, & extra_trait_items, & root_methods) ;
1183+ self . generate_stub_impl ( & guest_trait, & extra_trait_items, & root_methods, interface ) ;
11841184 }
11851185 }
11861186
@@ -1189,6 +1189,7 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
11891189 trait_name : & str ,
11901190 extra_trait_items : & str ,
11911191 funcs : & [ & Function ] ,
1192+ interface : Option < ( InterfaceId , & WorldKey ) > ,
11921193 ) {
11931194 uwriteln ! ( self . src, "impl {trait_name} for Stub {{" ) ;
11941195 self . src . push_str ( extra_trait_items) ;
@@ -1197,7 +1198,19 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
11971198 if self . gen . skip . contains ( & func. name ) {
11981199 continue ;
11991200 }
1201+ let async_ = match & self . gen . opts . async_ {
1202+ AsyncConfig :: None => false ,
1203+ AsyncConfig :: All => true ,
1204+ AsyncConfig :: Some { exports, .. } => {
1205+ exports. contains ( & if let Some ( ( _, key) ) = interface {
1206+ format ! ( "{}#{}" , self . resolve. name_world_key( key) , func. name)
1207+ } else {
1208+ func. name . clone ( )
1209+ } )
1210+ }
1211+ } ;
12001212 let mut sig = FnSig {
1213+ async_,
12011214 use_item_name : true ,
12021215 private : true ,
12031216 ..Default :: default ( )
@@ -1206,8 +1219,14 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
12061219 sig. self_arg = Some ( "&self" . into ( ) ) ;
12071220 sig. self_is_first_param = true ;
12081221 }
1209- self . print_signature ( func, true , & sig, true ) ;
1210- self . src . push_str ( "{ unreachable!() }\n " ) ;
1222+ self . print_signature ( func, true , & sig, false ) ;
1223+ let call = if async_ {
1224+ let async_support = self . path_to_async_support ( ) ;
1225+ format ! ( "{{ #[allow(unreachable_code)]{async_support}::futures::future::ready(unreachable!()) }}\n " )
1226+ } else {
1227+ "{ unreachable!() }\n " . into ( )
1228+ } ;
1229+ self . src . push_str ( & call) ;
12111230 }
12121231
12131232 self . src . push_str ( "}\n " ) ;
@@ -1273,7 +1292,11 @@ impl {stream_and_future_support}::StreamPayload for {name} {{
12731292 ) -> Vec < String > {
12741293 let params = self . print_docs_and_params ( func, params_owned, sig, use_async_sugar) ;
12751294 if let FunctionKind :: Constructor ( _) = & func. kind {
1276- self . push_str ( " -> Self" )
1295+ self . push_str ( if sig. async_ && !use_async_sugar {
1296+ " -> impl ::core::future::Future<Output = Self>"
1297+ } else {
1298+ " -> Self"
1299+ } )
12771300 } else {
12781301 self . print_results ( & func. results , sig. async_ && !use_async_sugar) ;
12791302 }
0 commit comments