about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-11-23 23:46:32 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-11-28 20:59:56 +0300
commita9cef4945fb60c19b7434b7409f1e33dd6922cc8 (patch)
tree0626b55dd58137787adcdc0f5f11d4cb0379eea9 /src
parent765133ac2e3f74b89417782f71d1aa505579523b (diff)
downloadrust-a9cef4945fb60c19b7434b7409f1e33dd6922cc8.tar.gz
rust-a9cef4945fb60c19b7434b7409f1e33dd6922cc8.zip
rustc_metadata: Privatize all fields of `CrateRoot`
All of them are read-only
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/creader.rs67
-rw-r--r--src/librustc_metadata/locator.rs23
-rw-r--r--src/librustc_metadata/rmeta/decoder.rs48
-rw-r--r--src/librustc_metadata/rmeta/mod.rs24
4 files changed, 105 insertions, 57 deletions
diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs
index f160c45b315..ae309a2aa13 100644
--- a/src/librustc_metadata/creader.rs
+++ b/src/librustc_metadata/creader.rs
@@ -47,9 +47,9 @@ pub struct CrateLoader<'a> {
 fn dump_crates(cstore: &CStore) {
     info!("resolved crates:");
     cstore.iter_crate_data(|cnum, data| {
-        info!("  name: {}", data.root.name);
+        info!("  name: {}", data.root.name());
         info!("  cnum: {}", cnum);
-        info!("  hash: {}", data.root.hash);
+        info!("  hash: {}", data.root.hash());
         info!("  reqd: {:?}", data.dep_kind());
         let CrateSource { dylib, rlib, rmeta } = data.source();
         dylib.as_ref().map(|dl| info!("  dylib: {}", dl.0.display()));
@@ -101,10 +101,10 @@ impl<'a> CrateLoader<'a> {
                       -> Option<CrateNum> {
         let mut ret = None;
         self.cstore.iter_crate_data(|cnum, data| {
-            if data.root.name != name { return }
+            if data.root.name() != name { return }
 
             match hash {
-                Some(hash) if *hash == data.root.hash => { ret = Some(cnum); return }
+                Some(hash) if *hash == data.root.hash() => { ret = Some(cnum); return }
                 Some(..) => return,
                 None => {}
             }
@@ -152,26 +152,26 @@ impl<'a> CrateLoader<'a> {
                                   span: Span,
                                   root: &CrateRoot<'_>) {
         // Check for (potential) conflicts with the local crate
-        if self.local_crate_name == root.name &&
-           self.sess.local_crate_disambiguator() == root.disambiguator {
+        if self.local_crate_name == root.name() &&
+           self.sess.local_crate_disambiguator() == root.disambiguator() {
             span_fatal!(self.sess, span, E0519,
                         "the current crate is indistinguishable from one of its \
                          dependencies: it has the same crate-name `{}` and was \
                          compiled with the same `-C metadata` arguments. This \
                          will result in symbol conflicts between the two.",
-                        root.name)
+                        root.name())
         }
 
         // Check for conflicts with any crate loaded so far
         self.cstore.iter_crate_data(|_, other| {
-            if other.root.name == root.name && // same crate-name
-               other.root.disambiguator == root.disambiguator &&  // same crate-disambiguator
-               other.root.hash != root.hash { // but different SVH
+            if other.root.name() == root.name() && // same crate-name
+               other.root.disambiguator() == root.disambiguator() &&  // same crate-disambiguator
+               other.root.hash() != root.hash() { // but different SVH
                 span_fatal!(self.sess, span, E0523,
                         "found two different crates with name `{}` that are \
                          not distinguished by differing `-C metadata`. This \
                          will result in symbol conflicts between the two.",
-                        root.name)
+                        root.name())
             }
         });
     }
@@ -189,14 +189,14 @@ impl<'a> CrateLoader<'a> {
 
         let Library { source, metadata } = lib;
         let crate_root = metadata.get_root();
-        let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash);
+        let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash());
         self.verify_no_symbol_conflicts(span, &crate_root);
 
         let private_dep = self.sess.opts.externs.get(&name.as_str())
             .map(|e| e.is_private_dep)
             .unwrap_or(false);
 
-        info!("register crate `{}` (private_dep = {})", crate_root.name, private_dep);
+        info!("register crate `{}` (private_dep = {})", crate_root.name(), private_dep);
 
         // Claim this crate number and cache it
         let cnum = self.cstore.alloc_new_crate_num();
@@ -207,7 +207,7 @@ impl<'a> CrateLoader<'a> {
         let root = if let Some(root) = root {
             root
         } else {
-            crate_paths = CratePaths::new(crate_root.name, source.clone());
+            crate_paths = CratePaths::new(crate_root.name(), source.clone());
             &crate_paths
         };
 
@@ -221,7 +221,7 @@ impl<'a> CrateLoader<'a> {
                 None => (&source, &crate_root),
             };
             let dlsym_dylib = dlsym_source.dylib.as_ref().expect("no dylib for a proc-macro crate");
-            Some(self.dlsym_proc_macros(&dlsym_dylib.0, dlsym_root.disambiguator, span))
+            Some(self.dlsym_proc_macros(&dlsym_dylib.0, dlsym_root.disambiguator(), span))
         } else {
             None
         };
@@ -378,7 +378,7 @@ impl<'a> CrateLoader<'a> {
         if locator.triple == self.sess.opts.target_triple {
             let mut result = LoadResult::Loaded(library);
             self.cstore.iter_crate_data(|cnum, data| {
-                if data.root.name == root.name && root.hash == data.root.hash {
+                if data.root.name() == root.name() && root.hash() == data.root.hash() {
                     assert!(locator.hash.is_none());
                     info!("load success, going to previous cnum: {}", cnum);
                     result = LoadResult::Previous(cnum);
@@ -494,13 +494,12 @@ impl<'a> CrateLoader<'a> {
                                                           sym::needs_panic_runtime);
 
         self.cstore.iter_crate_data(|cnum, data| {
-            needs_panic_runtime = needs_panic_runtime ||
-                                  data.root.needs_panic_runtime;
-            if data.root.panic_runtime {
+            needs_panic_runtime = needs_panic_runtime || data.needs_panic_runtime();
+            if data.is_panic_runtime() {
                 // Inject a dependency from all #![needs_panic_runtime] to this
                 // #![panic_runtime] crate.
                 self.inject_dependency_if(cnum, "a panic runtime",
-                                          &|data| data.root.needs_panic_runtime);
+                                          &|data| data.needs_panic_runtime());
                 runtime_found = runtime_found || data.dep_kind() == DepKind::Explicit;
             }
         });
@@ -536,11 +535,11 @@ impl<'a> CrateLoader<'a> {
 
         // Sanity check the loaded crate to ensure it is indeed a panic runtime
         // and the panic strategy is indeed what we thought it was.
-        if !data.root.panic_runtime {
+        if !data.is_panic_runtime() {
             self.sess.err(&format!("the crate `{}` is not a panic runtime",
                                    name));
         }
-        if data.root.panic_strategy != desired_strategy {
+        if data.panic_strategy() != desired_strategy {
             self.sess.err(&format!("the crate `{}` does not have the panic \
                                     strategy `{}`",
                                    name, desired_strategy.desc()));
@@ -548,7 +547,7 @@ impl<'a> CrateLoader<'a> {
 
         self.cstore.injected_panic_runtime = Some(cnum);
         self.inject_dependency_if(cnum, "a panic runtime",
-                                  &|data| data.root.needs_panic_runtime);
+                                  &|data| data.needs_panic_runtime());
     }
 
     fn inject_sanitizer_runtime(&mut self) {
@@ -622,7 +621,7 @@ impl<'a> CrateLoader<'a> {
 
             let mut uses_std = false;
             self.cstore.iter_crate_data(|_, data| {
-                if data.root.name == sym::std {
+                if data.root.name() == sym::std {
                     uses_std = true;
                 }
             });
@@ -640,7 +639,7 @@ impl<'a> CrateLoader<'a> {
                 let data = self.cstore.get_crate_data(cnum);
 
                 // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
-                if !data.root.sanitizer_runtime {
+                if !data.is_sanitizer_runtime() {
                     self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
                                            name));
                 }
@@ -661,7 +660,7 @@ impl<'a> CrateLoader<'a> {
             let data = self.cstore.get_crate_data(cnum);
 
             // Sanity check the loaded crate to ensure it is indeed a profiler runtime
-            if !data.root.profiler_runtime {
+            if !data.is_profiler_runtime() {
                 self.sess.err(&format!("the crate `profiler_builtins` is not \
                                         a profiler runtime"));
             }
@@ -687,7 +686,7 @@ impl<'a> CrateLoader<'a> {
         let mut needs_allocator = attr::contains_name(&krate.attrs,
                                                       sym::needs_allocator);
         self.cstore.iter_crate_data(|_, data| {
-            needs_allocator = needs_allocator || data.root.needs_allocator;
+            needs_allocator = needs_allocator || data.needs_allocator();
         });
         if !needs_allocator {
             self.cstore.allocator_kind = None;
@@ -723,7 +722,7 @@ impl<'a> CrateLoader<'a> {
             None
         };
         self.cstore.iter_crate_data(|_, data| {
-            if !data.root.has_global_allocator {
+            if !data.has_global_allocator() {
                 return
             }
             match global_allocator {
@@ -732,14 +731,14 @@ impl<'a> CrateLoader<'a> {
                                             conflicts with this global \
                                             allocator in: {}",
                                            other_crate,
-                                           data.root.name));
+                                           data.root.name()));
                 }
                 Some(None) => {
                     self.sess.err(&format!("the `#[global_allocator]` in this \
                                             crate conflicts with global \
-                                            allocator in: {}", data.root.name));
+                                            allocator in: {}", data.root.name()));
                 }
-                None => global_allocator = Some(Some(data.root.name)),
+                None => global_allocator = Some(Some(data.root.name())),
             }
         });
         if global_allocator.is_some() {
@@ -753,7 +752,7 @@ impl<'a> CrateLoader<'a> {
         // attribute.
         let mut has_default = attr::contains_name(&krate.attrs, sym::default_lib_allocator);
         self.cstore.iter_crate_data(|_, data| {
-            if data.root.has_default_lib_allocator {
+            if data.has_default_lib_allocator() {
                 has_default = true;
             }
         });
@@ -787,9 +786,9 @@ impl<'a> CrateLoader<'a> {
                 self.sess.err(&format!("the crate `{}` cannot depend \
                                         on a crate that needs {}, but \
                                         it depends on `{}`",
-                                       self.cstore.get_crate_data(krate).root.name,
+                                       self.cstore.get_crate_data(krate).root.name(),
                                        what,
-                                       data.root.name));
+                                       data.root.name()));
             }
         }
 
diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs
index 64230fd9e60..a7a4a96bb52 100644
--- a/src/librustc_metadata/locator.rs
+++ b/src/librustc_metadata/locator.rs
@@ -597,7 +597,7 @@ impl<'a> CrateLocator<'a> {
                                                "multiple matching crates for `{}`",
                                                self.crate_name);
                 let candidates = libraries.iter().filter_map(|(_, lib)| {
-                    let crate_name = &lib.metadata.get_root().name.as_str();
+                    let crate_name = &lib.metadata.get_root().name().as_str();
                     match &(&lib.source.dylib, &lib.source.rlib) {
                         &(&Some((ref pd, _)), &Some((ref pr, _))) => {
                             Some(format!("\ncrate `{}`: {}\n{:>padding$}",
@@ -774,35 +774,36 @@ impl<'a> CrateLocator<'a> {
         }
 
         if self.exact_paths.is_empty() {
-            if self.crate_name != root.name {
+            if self.crate_name != root.name() {
                 info!("Rejecting via crate name");
                 return None;
             }
         }
 
-        if root.triple != self.triple {
+        if root.triple() != &self.triple {
             info!("Rejecting via crate triple: expected {} got {}",
                   self.triple,
-                  root.triple);
+                  root.triple());
             self.rejected_via_triple.push(CrateMismatch {
                 path: libpath.to_path_buf(),
-                got: root.triple.to_string(),
+                got: root.triple().to_string(),
             });
             return None;
         }
 
-        if let Some(myhash) = self.hash {
-            if *myhash != root.hash {
-                info!("Rejecting via hash: expected {} got {}", *myhash, root.hash);
+        let hash = root.hash();
+        if let Some(&expected_hash) = self.hash {
+            if hash != expected_hash {
+                info!("Rejecting via hash: expected {} got {}", expected_hash, hash);
                 self.rejected_via_hash.push(CrateMismatch {
                     path: libpath.to_path_buf(),
-                    got: myhash.to_string(),
+                    got: hash.to_string(),
                 });
                 return None;
             }
         }
 
-        Some(root.hash)
+        Some(hash)
     }
 
 
@@ -1021,7 +1022,7 @@ pub fn find_plugin_registrar(
 
     match library.source.dylib {
         Some(dylib) => {
-            Some((dylib.0, library.metadata.get_root().disambiguator))
+            Some((dylib.0, library.metadata.get_root().disambiguator()))
         }
         None => {
             span_err!(sess, span, E0457,
diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs
index 3004af39435..db476284779 100644
--- a/src/librustc_metadata/rmeta/decoder.rs
+++ b/src/librustc_metadata/rmeta/decoder.rs
@@ -558,6 +558,22 @@ impl CrateRoot<'_> {
         self.proc_macro_data.is_some()
     }
 
+    crate fn name(&self) -> Symbol {
+        self.name
+    }
+
+    crate fn disambiguator(&self) -> CrateDisambiguator {
+        self.disambiguator
+    }
+
+    crate fn hash(&self) -> Svh {
+        self.hash
+    }
+
+    crate fn triple(&self) -> &TargetTriple {
+        &self.triple
+    }
+
     crate fn decode_crate_deps(
         &self,
         metadata: &'a MetadataBlob,
@@ -1546,6 +1562,38 @@ impl<'a, 'tcx> CrateMetadata {
     crate fn update_dep_kind(&self, f: impl FnOnce(DepKind) -> DepKind) {
         self.dep_kind.with_lock(|dep_kind| *dep_kind = f(*dep_kind))
     }
+
+    crate fn panic_strategy(&self) -> PanicStrategy {
+        self.root.panic_strategy
+    }
+
+    crate fn needs_panic_runtime(&self) -> bool {
+        self.root.needs_panic_runtime
+    }
+
+    crate fn is_panic_runtime(&self) -> bool {
+        self.root.panic_runtime
+    }
+
+    crate fn is_sanitizer_runtime(&self) -> bool {
+        self.root.sanitizer_runtime
+    }
+
+    crate fn is_profiler_runtime(&self) -> bool {
+        self.root.profiler_runtime
+    }
+
+    crate fn needs_allocator(&self) -> bool {
+        self.root.needs_allocator
+    }
+
+    crate fn has_global_allocator(&self) -> bool {
+        self.root.has_global_allocator
+    }
+
+    crate fn has_default_lib_allocator(&self) -> bool {
+        self.root.has_default_lib_allocator
+    }
 }
 
 // Cannot be implemented on 'ProcMacro', as libproc_macro
diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs
index 1bca2836a3a..4ea562fced3 100644
--- a/src/librustc_metadata/rmeta/mod.rs
+++ b/src/librustc_metadata/rmeta/mod.rs
@@ -173,16 +173,16 @@ macro_rules! Lazy {
 
 #[derive(RustcEncodable, RustcDecodable)]
 crate struct CrateRoot<'tcx> {
-    pub name: Symbol,
-    pub triple: TargetTriple,
+    name: Symbol,
+    triple: TargetTriple,
     extra_filename: String,
-    pub hash: Svh,
-    pub disambiguator: CrateDisambiguator,
-    pub panic_strategy: PanicStrategy,
+    hash: Svh,
+    disambiguator: CrateDisambiguator,
+    panic_strategy: PanicStrategy,
     edition: Edition,
-    pub has_global_allocator: bool,
+    has_global_allocator: bool,
     has_panic_handler: bool,
-    pub has_default_lib_allocator: bool,
+    has_default_lib_allocator: bool,
     plugin_registrar_fn: Option<DefIndex>,
     proc_macro_decls_static: Option<DefIndex>,
     proc_macro_stability: Option<attr::Stability>,
@@ -207,12 +207,12 @@ crate struct CrateRoot<'tcx> {
     proc_macro_data: Option<Lazy<[DefIndex]>>,
 
     compiler_builtins: bool,
-    pub needs_allocator: bool,
-    pub needs_panic_runtime: bool,
+    needs_allocator: bool,
+    needs_panic_runtime: bool,
     no_builtins: bool,
-    pub panic_runtime: bool,
-    pub profiler_runtime: bool,
-    pub sanitizer_runtime: bool,
+    panic_runtime: bool,
+    profiler_runtime: bool,
+    sanitizer_runtime: bool,
     symbol_mangling_version: SymbolManglingVersion,
 }