about summary refs log tree commit diff
path: root/src/librustc_codegen_utils
diff options
context:
space:
mode:
authorKonrad Borowski <konrad@borowski.pw>2018-12-23 16:47:11 +0100
committerGitHub <noreply@github.com>2018-12-23 16:47:11 +0100
commit8ac5380ea0204dbdcbc8108d259928b67d5f8ebb (patch)
tree174d912756fc2678af50d46ff457f7504750a975 /src/librustc_codegen_utils
parentb4a306c1e648c84f289c63e984941b7faad10af1 (diff)
parentddab10a692aab2e2984b5c826ed9d78a57e94851 (diff)
downloadrust-8ac5380ea0204dbdcbc8108d259928b67d5f8ebb.tar.gz
rust-8ac5380ea0204dbdcbc8108d259928b67d5f8ebb.zip
Merge branch 'master' into copied
Diffstat (limited to 'src/librustc_codegen_utils')
-rw-r--r--src/librustc_codegen_utils/codegen_backend.rs34
-rw-r--r--src/librustc_codegen_utils/lib.rs2
-rw-r--r--src/librustc_codegen_utils/symbol_names.rs8
-rw-r--r--src/librustc_codegen_utils/symbol_names_test.rs4
4 files changed, 20 insertions, 28 deletions
diff --git a/src/librustc_codegen_utils/codegen_backend.rs b/src/librustc_codegen_utils/codegen_backend.rs
index 046f0cccfee..74718460f56 100644
--- a/src/librustc_codegen_utils/codegen_backend.rs
+++ b/src/librustc_codegen_utils/codegen_backend.rs
@@ -22,8 +22,8 @@
 #![feature(box_syntax)]
 
 use std::any::Any;
-use std::io::{self, Write};
-use std::fs::File;
+use std::io::Write;
+use std::fs;
 use std::path::Path;
 use std::sync::{mpsc, Arc};
 
@@ -81,13 +81,9 @@ pub struct NoLlvmMetadataLoader;
 
 impl MetadataLoader for NoLlvmMetadataLoader {
     fn get_rlib_metadata(&self, _: &Target, filename: &Path) -> Result<MetadataRef, String> {
-        let mut file = File::open(filename)
-            .map_err(|e| format!("metadata file open err: {:?}", e))?;
-
-        let mut buf = Vec::new();
-        io::copy(&mut file, &mut buf).unwrap();
-        let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into();
-        return Ok(rustc_erase_owner!(buf.map_owner_box()));
+        let buf = fs::read(filename).map_err(|e| format!("metadata file open err: {:?}", e))?;
+        let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf);
+        Ok(rustc_erase_owner!(buf.map_owner_box()))
     }
 
     fn get_dylib_metadata(&self, target: &Target, filename: &Path) -> Result<MetadataRef, String> {
@@ -103,7 +99,7 @@ pub struct OngoingCodegen {
 }
 
 impl MetadataOnlyCodegenBackend {
-    pub fn new() -> Box<dyn CodegenBackend> {
+    pub fn boxed() -> Box<dyn CodegenBackend> {
         box MetadataOnlyCodegenBackend(())
     }
 }
@@ -165,15 +161,12 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
                 tcx,
                 collector::MonoItemCollectionMode::Eager
             ).0 {
-            match mono_item {
-                MonoItem::Fn(inst) => {
-                    let def_id = inst.def_id();
-                    if def_id.is_local()  {
-                        let _ = inst.def.is_inline(tcx);
-                        let _ = tcx.codegen_fn_attrs(def_id);
-                    }
+            if let MonoItem::Fn(inst) = mono_item {
+                let def_id = inst.def_id();
+                if def_id.is_local()  {
+                    let _ = inst.def.is_inline(tcx);
+                    let _ = tcx.codegen_fn_attrs(def_id);
                 }
-                _ => {}
             }
         }
         tcx.sess.abort_if_errors();
@@ -181,7 +174,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
         let metadata = tcx.encode_metadata();
 
         box OngoingCodegen {
-            metadata: metadata,
+            metadata,
             metadata_version: tcx.metadata_encoding_version().to_vec(),
             crate_name: tcx.crate_name(LOCAL_CRATE),
         }
@@ -212,8 +205,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend {
             } else {
                 &ongoing_codegen.metadata.raw_data
             };
-            let mut file = File::create(&output_name).unwrap();
-            file.write_all(metadata).unwrap();
+            fs::write(&output_name, metadata).unwrap();
         }
 
         sess.abort_if_errors();
diff --git a/src/librustc_codegen_utils/lib.rs b/src/librustc_codegen_utils/lib.rs
index ea8259d79a1..cbef3ff5b92 100644
--- a/src/librustc_codegen_utils/lib.rs
+++ b/src/librustc_codegen_utils/lib.rs
@@ -53,7 +53,7 @@ pub mod symbol_names_test;
 /// reporting an error.
 pub fn check_for_rustc_errors_attr(tcx: TyCtxt) {
     if let Some((id, span, _)) = *tcx.sess.entry_fn.borrow() {
-        let main_def_id = tcx.hir.local_def_id(id);
+        let main_def_id = tcx.hir().local_def_id(id);
 
         if tcx.has_attr(main_def_id, "rustc_error") {
             tcx.sess.span_fatal(span, "compilation successful");
diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs
index 344a2525784..d5b95e77b1a 100644
--- a/src/librustc_codegen_utils/symbol_names.rs
+++ b/src/librustc_codegen_utils/symbol_names.rs
@@ -71,7 +71,7 @@
 //! order to also avoid inter-crate conflicts two more measures are taken:
 //!
 //! - The name of the crate containing the symbol is prepended to the symbol
-//!   name, i.e. symbols are "crate qualified". For example, a function `foo` in
+//!   name, i.e., symbols are "crate qualified". For example, a function `foo` in
 //!   module `bar` in crate `baz` would get a symbol name like
 //!   `baz::bar::foo::{hash}` instead of just `bar::foo::{hash}`. This avoids
 //!   simple conflicts between functions from different crates.
@@ -250,7 +250,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
 
     debug!("symbol_name(def_id={:?}, substs={:?})", def_id, substs);
 
-    let node_id = tcx.hir.as_local_node_id(def_id);
+    let node_id = tcx.hir().as_local_node_id(def_id);
 
     if let Some(id) = node_id {
         if *tcx.sess.plugin_registrar_fn.get() == Some(id) {
@@ -265,7 +265,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
 
     // FIXME(eddyb) Precompute a custom symbol name based on attributes.
     let is_foreign = if let Some(id) = node_id {
-        match tcx.hir.get(id) {
+        match tcx.hir().get(id) {
             Node::ForeignItem(_) => true,
             _ => false,
         }
@@ -389,7 +389,7 @@ impl SymbolPathBuffer {
 
 impl ItemPathBuffer for SymbolPathBuffer {
     fn root_mode(&self) -> &RootMode {
-        const ABSOLUTE: &'static RootMode = &RootMode::Absolute;
+        const ABSOLUTE: &RootMode = &RootMode::Absolute;
         ABSOLUTE
     }
 
diff --git a/src/librustc_codegen_utils/symbol_names_test.rs b/src/librustc_codegen_utils/symbol_names_test.rs
index 6eaf0c1c08d..c4ad31ab021 100644
--- a/src/librustc_codegen_utils/symbol_names_test.rs
+++ b/src/librustc_codegen_utils/symbol_names_test.rs
@@ -33,7 +33,7 @@ pub fn report_symbol_names<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
 
     tcx.dep_graph.with_ignore(|| {
         let mut visitor = SymbolNamesTest { tcx };
-        tcx.hir.krate().visit_all_item_likes(&mut visitor);
+        tcx.hir().krate().visit_all_item_likes(&mut visitor);
     })
 }
 
@@ -45,7 +45,7 @@ impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> {
     fn process_attrs(&mut self,
                      node_id: ast::NodeId) {
         let tcx = self.tcx;
-        let def_id = tcx.hir.local_def_id(node_id);
+        let def_id = tcx.hir().local_def_id(node_id);
         for attr in tcx.get_attrs(def_id).iter() {
             if attr.check_name(SYMBOL_NAME) {
                 // for now, can only use on monomorphic names