about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 13:39:56 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 15:08:18 +0200
commitd1410ada92bfc80f4e7020336e182670084acd0e (patch)
tree415da9e0a10162e91a854e00b50621ea8bedda30 /src/librustc_codegen_ssa
parent47c84c4234a6e3ee24888bd94daeec13df7dd20d (diff)
downloadrust-d1410ada92bfc80f4e7020336e182670084acd0e.tar.gz
rust-d1410ada92bfc80f4e7020336e182670084acd0e.zip
[eddyb] rustc_codegen_ssa: avoid a `Clone` bound on `TargetMachine`.
Diffstat (limited to 'src/librustc_codegen_ssa')
-rw-r--r--src/librustc_codegen_ssa/back/write.rs16
-rw-r--r--src/librustc_codegen_ssa/interfaces/write.rs2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs
index e958b5441f2..e8cf9e7f40a 100644
--- a/src/librustc_codegen_ssa/back/write.rs
+++ b/src/librustc_codegen_ssa/back/write.rs
@@ -178,6 +178,17 @@ pub struct AssemblerCommand {
     cmd: Command,
 }
 
+// HACK(eddyb) work around `#[derive]` producing wrong bounds for `Clone`.
+pub struct TargetMachineFactory<B: WriteBackendMethods>(
+    pub Arc<dyn Fn() -> Result<B::TargetMachine, String> + Send + Sync>,
+);
+
+impl<B: WriteBackendMethods> Clone for TargetMachineFactory<B> {
+    fn clone(&self) -> Self {
+        TargetMachineFactory(self.0.clone())
+    }
+}
+
 /// Additional resources used by optimize_and_codegen (not module specific)
 #[derive(Clone)]
 pub struct CodegenContext<B: WriteBackendMethods> {
@@ -196,8 +207,7 @@ pub struct CodegenContext<B: WriteBackendMethods> {
     pub regular_module_config: Arc<ModuleConfig>,
     pub metadata_module_config: Arc<ModuleConfig>,
     pub allocator_module_config: Arc<ModuleConfig>,
-    pub tm_factory: Arc<dyn Fn()
-        -> Result<B::TargetMachine, String> + Send + Sync>,
+    pub tm_factory: TargetMachineFactory<B>,
     pub msvc_imps_needed: bool,
     pub target_pointer_width: String,
     pub debuginfo: config::DebugInfo,
@@ -962,7 +972,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
         regular_module_config: modules_config,
         metadata_module_config: metadata_config,
         allocator_module_config: allocator_config,
-        tm_factory: backend.target_machine_factory(tcx.sess, false),
+        tm_factory: TargetMachineFactory(backend.target_machine_factory(tcx.sess, false)),
         total_cgus,
         msvc_imps_needed: msvc_imps_needed(tcx),
         target_pointer_width: tcx.sess.target.target.target_pointer_width.clone(),
diff --git a/src/librustc_codegen_ssa/interfaces/write.rs b/src/librustc_codegen_ssa/interfaces/write.rs
index 3419e1c59ed..72522e19af2 100644
--- a/src/librustc_codegen_ssa/interfaces/write.rs
+++ b/src/librustc_codegen_ssa/interfaces/write.rs
@@ -18,7 +18,7 @@ use rustc_errors::{FatalError, Handler};
 
 pub trait WriteBackendMethods: 'static + Sized + Clone {
     type Module: Send + Sync;
-    type TargetMachine: Clone;
+    type TargetMachine;
     type ModuleBuffer: ModuleBufferMethods;
     type Context: ?Sized;
     type ThinData: Send + Sync;