Skip to content

Commit dea13b4

Browse files
Move path2cstr to rustc_fs_util
1 parent e3177c6 commit dea13b4

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

src/librustc/util/common.rs

-15
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ use rustc_data_structures::sync::Lock;
1414

1515
use std::cell::{RefCell, Cell};
1616
use std::collections::HashMap;
17-
use std::ffi::CString;
1817
use std::fmt::Debug;
1918
use std::hash::{Hash, BuildHasher};
2019
use std::panic;
2120
use std::env;
22-
use std::path::Path;
2321
use std::time::{Duration, Instant};
2422

2523
use std::sync::mpsc::{Sender};
@@ -376,19 +374,6 @@ impl<K, V, S> MemoizationMap for RefCell<HashMap<K,V,S>>
376374
}
377375
}
378376

379-
#[cfg(unix)]
380-
pub fn path2cstr(p: &Path) -> CString {
381-
use std::os::unix::prelude::*;
382-
use std::ffi::OsStr;
383-
let p: &OsStr = p.as_ref();
384-
CString::new(p.as_bytes()).unwrap()
385-
}
386-
#[cfg(windows)]
387-
pub fn path2cstr(p: &Path) -> CString {
388-
CString::new(p.to_str().unwrap()).unwrap()
389-
}
390-
391-
392377
#[test]
393378
fn test_to_readable_str() {
394379
assert_eq!("0", to_readable_str(0));

src/librustc_codegen_llvm/back/write.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use CrateInfo;
3030
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
3131
use rustc::ty::TyCtxt;
3232
use rustc::util::common::{time_ext, time_depth, set_time_depth, print_time_passes_entry};
33-
use rustc::util::common::path2cstr;
34-
use rustc_fs_util::link_or_copy;
33+
use rustc_fs_util::{path2cstr, link_or_copy};
3534
use errors::{self, Handler, Level, DiagnosticBuilder, FatalError, DiagnosticId};
3635
use errors::emitter::{Emitter};
3736
use syntax::attr;

src/librustc_codegen_llvm/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt};
3535
use rustc::ty::layout::{self, Align, LayoutOf, PrimitiveExt, Size, TyLayout};
3636
use rustc::session::config;
3737
use rustc::util::nodemap::FxHashMap;
38-
use rustc::util::common::path2cstr;
38+
use rustc_fs_util::path2cstr;
3939

4040
use libc::{c_uint, c_longlong};
4141
use std::ffi::CString;

src/librustc_codegen_llvm/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc::util::common;
1211
use rustc::middle::cstore::MetadataLoader;
1312
use rustc_target::spec::Target;
1413
use llvm;
@@ -19,6 +18,7 @@ use rustc_data_structures::owning_ref::OwningRef;
1918
use std::path::Path;
2019
use std::ptr;
2120
use std::slice;
21+
use rustc_fs_util::path2cstr;
2222

2323
pub use rustc_data_structures::sync::MetadataRef;
2424

@@ -57,7 +57,7 @@ impl MetadataLoader for LlvmMetadataLoader {
5757
filename: &Path)
5858
-> Result<MetadataRef, String> {
5959
unsafe {
60-
let buf = common::path2cstr(filename);
60+
let buf = path2cstr(filename);
6161
let mb = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf.as_ptr())
6262
.ok_or_else(|| format!("error reading library: '{}'", filename.display()))?;
6363
let of = ObjectFile::new(mb)

src/librustc_fs_util/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use std::path::{Path, PathBuf};
12+
use std::ffi::CString;
1213
use std::fs;
1314
use std::io;
1415

@@ -113,3 +114,15 @@ pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
113114
}
114115
}
115116
}
117+
118+
#[cfg(unix)]
119+
pub fn path2cstr(p: &Path) -> CString {
120+
use std::os::unix::prelude::*;
121+
use std::ffi::OsStr;
122+
let p: &OsStr = p.as_ref();
123+
CString::new(p.as_bytes()).unwrap()
124+
}
125+
#[cfg(windows)]
126+
pub fn path2cstr(p: &Path) -> CString {
127+
CString::new(p.to_str().unwrap()).unwrap()
128+
}

0 commit comments

Comments
 (0)