about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-04-01 08:24:46 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2018-04-10 14:40:25 +0200
commit7d33d1a84eadec1f1e54bf5e39575103c04b03bd (patch)
tree8cd1cf93018d1792e85e3f55038185035b2e6725
parent73b26f7f51d15c6cb6b4495f4ff9a405610037f8 (diff)
downloadrust-7d33d1a84eadec1f1e54bf5e39575103c04b03bd.tar.gz
rust-7d33d1a84eadec1f1e54bf5e39575103c04b03bd.zip
Make Session.has_global_allocator thread-safe
-rw-r--r--src/librustc/session/mod.rs4
-rw-r--r--src/librustc_metadata/creader.rs4
-rw-r--r--src/librustc_metadata/encoder.rs2
3 files changed, 4 insertions, 6 deletions
diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs
index 731e4feefa0..1c11c52357d 100644
--- a/src/librustc/session/mod.rs
+++ b/src/librustc/session/mod.rs
@@ -161,7 +161,7 @@ pub struct Session {
     pub jobserver_from_env: Option<Client>,
 
     /// Metadata about the allocators for the current crate being compiled
-    pub has_global_allocator: Cell<bool>,
+    pub has_global_allocator: Once<bool>,
 }
 
 pub struct PerfStats {
@@ -1142,7 +1142,7 @@ pub fn build_session_(
             });
             (*GLOBAL_JOBSERVER).clone()
         },
-        has_global_allocator: Cell::new(false),
+        has_global_allocator: Once::new(),
     };
 
     sess
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index 86f495c5fac..5b54994b9ce 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -812,9 +812,7 @@ impl<'a> CrateLoader<'a> {
 
     fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
         let has_global_allocator = has_global_allocator(krate);
-        if has_global_allocator {
-            self.sess.has_global_allocator.set(true);
-        }
+        self.sess.has_global_allocator.set(has_global_allocator);
 
         // Check to see if we actually need an allocator. This desire comes
         // about through the `#![needs_allocator]` attribute and is typically
diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs
index 1b208a512e2..66071f242fb 100644
--- a/src/librustc_metadata/encoder.rs
+++ b/src/librustc_metadata/encoder.rs
@@ -459,7 +459,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
         let is_proc_macro = tcx.sess.crate_types.borrow().contains(&CrateTypeProcMacro);
         let has_default_lib_allocator =
             attr::contains_name(tcx.hir.krate_attrs(), "default_lib_allocator");
-        let has_global_allocator = tcx.sess.has_global_allocator.get();
+        let has_global_allocator = *tcx.sess.has_global_allocator.get();
         let root = self.lazy(&CrateRoot {
             name: tcx.crate_name(LOCAL_CRATE),
             extra_filename: tcx.sess.opts.cg.extra_filename.clone(),