@@ -178,6 +178,17 @@ pub struct AssemblerCommand {
178178 cmd : Command ,
179179}
180180
181+ // HACK(eddyb) work around `#[derive]` producing wrong bounds for `Clone`.
182+ pub struct TargetMachineFactory < B : WriteBackendMethods > (
183+ pub Arc < dyn Fn ( ) -> Result < B :: TargetMachine , String > + Send + Sync > ,
184+ ) ;
185+
186+ impl < B : WriteBackendMethods > Clone for TargetMachineFactory < B > {
187+ fn clone ( & self ) -> Self {
188+ TargetMachineFactory ( self . 0 . clone ( ) )
189+ }
190+ }
191+
181192/// Additional resources used by optimize_and_codegen (not module specific)
182193#[ derive( Clone ) ]
183194pub struct CodegenContext < B : WriteBackendMethods > {
@@ -196,8 +207,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
196207 pub regular_module_config : Arc < ModuleConfig > ,
197208 pub metadata_module_config : Arc < ModuleConfig > ,
198209 pub allocator_module_config : Arc < ModuleConfig > ,
199- pub tm_factory : Arc < dyn Fn ( )
200- -> Result < B :: TargetMachine , String > + Send + Sync > ,
210+ pub tm_factory : TargetMachineFactory < B > ,
201211 pub msvc_imps_needed : bool ,
202212 pub target_pointer_width : String ,
203213 pub debuginfo : config:: DebugInfo ,
@@ -962,7 +972,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
962972 regular_module_config : modules_config,
963973 metadata_module_config : metadata_config,
964974 allocator_module_config : allocator_config,
965- tm_factory : backend. target_machine_factory ( tcx. sess , false ) ,
975+ tm_factory : TargetMachineFactory ( backend. target_machine_factory ( tcx. sess , false ) ) ,
966976 total_cgus,
967977 msvc_imps_needed : msvc_imps_needed ( tcx) ,
968978 target_pointer_width : tcx. sess . target . target . target_pointer_width . clone ( ) ,
0 commit comments