From dea13b4bc7fc51caeb950a531b9652599dba2a2e Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 3 Aug 2018 15:37:15 -0600 Subject: [PATCH] Move path2cstr to rustc_fs_util --- src/librustc/util/common.rs | 15 --------------- src/librustc_codegen_llvm/back/write.rs | 3 +-- src/librustc_codegen_llvm/debuginfo/metadata.rs | 2 +- src/librustc_codegen_llvm/metadata.rs | 4 ++-- src/librustc_fs_util/lib.rs | 13 +++++++++++++ 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index 990fbc4bc91..1ec025f78c9 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -14,12 +14,10 @@ use rustc_data_structures::sync::Lock; use std::cell::{RefCell, Cell}; use std::collections::HashMap; -use std::ffi::CString; use std::fmt::Debug; use std::hash::{Hash, BuildHasher}; use std::panic; use std::env; -use std::path::Path; use std::time::{Duration, Instant}; use std::sync::mpsc::{Sender}; @@ -376,19 +374,6 @@ impl MemoizationMap for RefCell> } } -#[cfg(unix)] -pub fn path2cstr(p: &Path) -> CString { - use std::os::unix::prelude::*; - use std::ffi::OsStr; - let p: &OsStr = p.as_ref(); - CString::new(p.as_bytes()).unwrap() -} -#[cfg(windows)] -pub fn path2cstr(p: &Path) -> CString { - CString::new(p.to_str().unwrap()).unwrap() -} - - #[test] fn test_to_readable_str() { assert_eq!("0", to_readable_str(0)); diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs index 7630849d675..cdfa874b177 100644 --- a/src/librustc_codegen_llvm/back/write.rs +++ b/src/librustc_codegen_llvm/back/write.rs @@ -30,8 +30,7 @@ use CrateInfo; use rustc::hir::def_id::{CrateNum, LOCAL_CRATE}; use rustc::ty::TyCtxt; use rustc::util::common::{time_ext, time_depth, set_time_depth, print_time_passes_entry}; -use rustc::util::common::path2cstr; -use rustc_fs_util::link_or_copy; +use rustc_fs_util::{path2cstr, link_or_copy}; use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId}; use errors::emitter::{Emitter}; use syntax::attr; diff --git a/src/librustc_codegen_llvm/debuginfo/metadata.rs b/src/librustc_codegen_llvm/debuginfo/metadata.rs index 69ef92ed98e..3ae30e85796 100644 --- a/src/librustc_codegen_llvm/debuginfo/metadata.rs +++ b/src/librustc_codegen_llvm/debuginfo/metadata.rs @@ -35,7 +35,7 @@ use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; use rustc::ty::layout::{self, Align, LayoutOf, PrimitiveExt, Size, TyLayout}; use rustc::session::config; use rustc::util::nodemap::FxHashMap; -use rustc::util::common::path2cstr; +use rustc_fs_util::path2cstr; use libc::{c_uint, c_longlong}; use std::ffi::CString; diff --git a/src/librustc_codegen_llvm/metadata.rs b/src/librustc_codegen_llvm/metadata.rs index fcb704413ef..a4526a53769 100644 --- a/src/librustc_codegen_llvm/metadata.rs +++ b/src/librustc_codegen_llvm/metadata.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustc::util::common; use rustc::middle::cstore::MetadataLoader; use rustc_target::spec::Target; use llvm; @@ -19,6 +18,7 @@ use rustc_data_structures::owning_ref::OwningRef; use std::path::Path; use std::ptr; use std::slice; +use rustc_fs_util::path2cstr; pub use rustc_data_structures::sync::MetadataRef; @@ -57,7 +57,7 @@ impl MetadataLoader for LlvmMetadataLoader { filename: &Path) -> Result { unsafe { - let buf = common::path2cstr(filename); + let buf = path2cstr(filename); let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr()) .ok_or_else(|| format!("error reading library: '{}'", filename.display()))?; let of = ObjectFile::new(mb) diff --git a/src/librustc_fs_util/lib.rs b/src/librustc_fs_util/lib.rs index d25e187186e..ffe420b109d 100644 --- a/src/librustc_fs_util/lib.rs +++ b/src/librustc_fs_util/lib.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::path::{Path, PathBuf}; +use std::ffi::CString; use std::fs; use std::io; @@ -113,3 +114,15 @@ pub fn rename_or_copy_remove, Q: AsRef>(p: P, } } } + +#[cfg(unix)] +pub fn path2cstr(p: &Path) -> CString { + use std::os::unix::prelude::*; + use std::ffi::OsStr; + let p: &OsStr = p.as_ref(); + CString::new(p.as_bytes()).unwrap() +} +#[cfg(windows)] +pub fn path2cstr(p: &Path) -> CString { + CString::new(p.to_str().unwrap()).unwrap() +}