11#![ deny( warnings) ]
22
33use {
4- anyhow:: { anyhow , bail , ensure , Context , Error , Result } ,
4+ anyhow:: { Context , Error , Result , anyhow , bail , ensure } ,
55 async_trait:: async_trait,
66 bytes:: Bytes ,
77 component_init_transform:: Invoker ,
@@ -18,12 +18,12 @@ use {
1818 } ,
1919 summary:: { Escape , Locations , Summary } ,
2020 wasmtime:: {
21- component:: { Component , Instance , Linker , ResourceTable , ResourceType } ,
2221 Config , Engine , Store ,
22+ component:: { Component , Instance , Linker , ResourceTable , ResourceType } ,
2323 } ,
2424 wasmtime_wasi:: {
25- p2:: pipe:: { MemoryInputPipe , MemoryOutputPipe } ,
2625 DirPerms , FilePerms , WasiCtx , WasiCtxBuilder , WasiCtxView , WasiView ,
26+ p2:: pipe:: { MemoryInputPipe , MemoryOutputPipe } ,
2727 } ,
2828 wit_parser:: { Resolve , TypeDefKind , UnresolvedPackageGroup , WorldId , WorldItem , WorldKey } ,
2929} ;
@@ -661,29 +661,27 @@ fn add_wasi_and_stubs(
661661 // Note that we do _not_ stub interfaces which appear to be part of WASIp2 since those should be
662662 // provided by the `wasmtime_wasi::add_to_linker_async` call above, and adding stubs to those same
663663 // interfaces would just cause trouble.
664- if !is_wasip2_cli ( & interface_name) {
665- if let Ok ( mut instance) = linker. instance ( & interface_name) {
666- for stub in stubs {
667- let interface_name = interface_name. clone ( ) ;
668- match stub {
669- Stub :: Function ( name) => instance. func_new ( name, {
664+ if !is_wasip2_cli ( & interface_name)
665+ && let Ok ( mut instance) = linker. instance ( & interface_name)
666+ {
667+ for stub in stubs {
668+ let interface_name = interface_name. clone ( ) ;
669+ match stub {
670+ Stub :: Function ( name) => instance. func_new ( name, {
671+ let name = name. clone ( ) ;
672+ move |_, _, _| {
673+ Err ( anyhow ! ( "called trapping stub: {interface_name}#{name}" ) )
674+ }
675+ } ) ,
676+ Stub :: Resource ( name) => instance
677+ . resource ( name, ResourceType :: host :: < ( ) > ( ) , {
670678 let name = name. clone ( ) ;
671- move |_, _, _ | {
679+ move |_, _| {
672680 Err ( anyhow ! ( "called trapping stub: {interface_name}#{name}" ) )
673681 }
674- } ) ,
675- Stub :: Resource ( name) => instance
676- . resource ( name, ResourceType :: host :: < ( ) > ( ) , {
677- let name = name. clone ( ) ;
678- move |_, _| {
679- Err ( anyhow ! (
680- "called trapping stub: {interface_name}#{name}"
681- ) )
682- }
683- } )
684- . map ( drop) ,
685- } ?;
686- }
682+ } )
683+ . map ( drop) ,
684+ } ?;
687685 }
688686 }
689687 } else {
0 commit comments