Skip to content

Commit a828e79

Browse files
committed
std: Tweak the std::env OsString/String interface
This commit tweaks the interface of the `std::env` module to make it more ergonomic for common usage: * `env::var` was renamed to `env::var_os` * `env::var_string` was renamed to `env::var` * `env::args` was renamed to `env::args_os` * `env::args` was re-added as a panicking iterator over string values * `env::vars` was renamed to `env::vars_os` * `env::vars` was re-added as a panicking iterator over string values. This should make common usage (e.g. unicode values everywhere) more ergonomic as well as "the default". This is also a breaking change due to the differences of what's yielded from each of these functions, but migration should be fairly easy as the defaults operate over `String` which is a common type to use. [breaking-change]
1 parent 446bc89 commit a828e79

File tree

21 files changed

+162
-80
lines changed

21 files changed

+162
-80
lines changed

src/compiletest/compiletest.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(collections)]
1515
#![feature(int_uint)]
1616
#![feature(io)]
17-
#![feature(os)]
1817
#![feature(path)]
1918
#![feature(rustc_private)]
2019
#![feature(slicing_syntax, unboxed_closures)]
@@ -48,8 +47,7 @@ pub mod common;
4847
pub mod errors;
4948

5049
pub fn main() {
51-
let args = env::args().map(|s| s.into_string().unwrap()).collect();;
52-
let config = parse_config(args);
50+
let config = parse_config(env::args().collect());
5351

5452
if config.valgrind_path.is_none() && config.force_valgrind {
5553
panic!("Can't find Valgrind to run Valgrind tests");

src/compiletest/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn make_new_path(path: &str) -> String {
4040

4141
// Windows just uses PATH as the library search path, so we have to
4242
// maintain the current value while adding our own
43-
match env::var_string(lib_path_env_var()) {
43+
match env::var(lib_path_env_var()) {
4444
Ok(curr) => {
4545
format!("{}{}{}", path, path_div(), curr)
4646
}

src/liblog/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fn enabled(level: u32,
397397
/// This is not threadsafe at all, so initialization is performed through a
398398
/// `Once` primitive (and this function is called from that primitive).
399399
fn init() {
400-
let (mut directives, filter) = match env::var_string("RUST_LOG") {
400+
let (mut directives, filter) = match env::var("RUST_LOG") {
401401
Ok(spec) => directive::parse_logging_spec(&spec[]),
402402
Err(..) => (Vec::new(), None),
403403
};

src/librustc/metadata/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static PATH_ENTRY_SEPARATOR: &'static str = ":";
207207

208208
/// Returns RUST_PATH as a string, without default paths added
209209
pub fn get_rust_path() -> Option<String> {
210-
env::var_string("RUST_PATH").ok()
210+
env::var("RUST_PATH").ok()
211211
}
212212

213213
/// Returns the value of RUST_PATH, as a list

src/librustc/middle/infer/region_inference/graphviz.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ pub fn maybe_print_constraints_for<'a, 'tcx>(region_vars: &RegionVarBindings<'a,
6161
}
6262

6363
let requested_node : Option<ast::NodeId> =
64-
env::var_string("RUST_REGION_GRAPH_NODE").ok().and_then(|s| s.parse().ok());
64+
env::var("RUST_REGION_GRAPH_NODE").ok().and_then(|s| s.parse().ok());
6565

6666
if requested_node.is_some() && requested_node != Some(subject_node) {
6767
return;
6868
}
6969

70-
let requested_output = env::var_string("RUST_REGION_GRAPH").ok();
70+
let requested_output = env::var("RUST_REGION_GRAPH").ok();
7171
debug!("requested_output: {:?} requested_node: {:?}",
7272
requested_output, requested_node);
7373

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ pub fn get_unstable_features_setting() -> UnstableFeatures {
10521052
// subverting the unstable features lints
10531053
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
10541054
// The matching key to the above, only known by the build system
1055-
let bootstrap_provided_key = env::var_string("RUSTC_BOOTSTRAP_KEY").ok();
1055+
let bootstrap_provided_key = env::var("RUSTC_BOOTSTRAP_KEY").ok();
10561056
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
10571057
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
10581058
(true, _, _) => UnstableFeatures::Disallow,

src/librustc_back/target/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl Target {
384384
Path::new(target)
385385
};
386386

387-
let target_path = env::var("RUST_TARGET_PATH")
387+
let target_path = env::var_os("RUST_TARGET_PATH")
388388
.unwrap_or(OsString::from_str(""));
389389

390390
// FIXME 16351: add a sane default search path?

src/librustc_driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
464464
// compiler, not for the target.
465465
let mut _old_path = OsString::from_str("");
466466
if cfg!(windows) {
467-
_old_path = env::var("PATH").unwrap_or(_old_path);
467+
_old_path = env::var_os("PATH").unwrap_or(_old_path);
468468
let mut new_path = sess.host_filesearch(PathKind::All).get_dylib_search_paths();
469469
new_path.extend(env::split_paths(&_old_path));
470470
env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());
@@ -737,7 +737,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
737737
pub fn phase_6_link_output(sess: &Session,
738738
trans: &trans::CrateTranslation,
739739
outputs: &OutputFilenames) {
740-
let old_path = env::var("PATH").unwrap_or(OsString::from_str(""));
740+
let old_path = env::var_os("PATH").unwrap_or(OsString::from_str(""));
741741
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths();
742742
new_path.extend(env::split_paths(&old_path));
743743
env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap());

src/librustc_driver/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ pub fn monitor<F:FnOnce()+Send>(f: F) {
771771

772772
// FIXME: Hacks on hacks. If the env is trying to override the stack size
773773
// then *don't* set it explicitly.
774-
if env::var("RUST_MIN_STACK").is_none() {
774+
if env::var_os("RUST_MIN_STACK").is_none() {
775775
cfg = cfg.stack_size(STACK_SIZE);
776776
}
777777

@@ -835,8 +835,7 @@ pub fn diagnostics_registry() -> diagnostics::registry::Registry {
835835
}
836836

837837
pub fn main() {
838-
let args = env::args().map(|s| s.into_string().unwrap());
839-
let result = run(args.collect());
838+
let result = run(env::args().collect());
840839
std::env::set_exit_status(result as i32);
841840
}
842841

src/librustc_trans/save/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@ pub fn process_crate(sess: &Session,
15511551
info!("Dumping crate {}", cratename);
15521552

15531553
// find a path to dump our data to
1554-
let mut root_path = match env::var_string("DXR_RUST_TEMP_FOLDER") {
1554+
let mut root_path = match env::var("DXR_RUST_TEMP_FOLDER") {
15551555
Ok(val) => Path::new(val),
15561556
Err(..) => match odir {
15571557
Some(val) => val.join("dxr"),

src/librustdoc/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ struct Output {
122122
}
123123

124124
pub fn main() {
125-
static STACK_SIZE: uint = 32000000; // 32MB
125+
const STACK_SIZE: usize = 32000000; // 32MB
126126
let res = std::thread::Builder::new().stack_size(STACK_SIZE).scoped(move || {
127-
let s = env::args().map(|s| s.into_string().unwrap());
128-
main_args(&s.collect::<Vec<_>>())
127+
let s = env::args().collect::<Vec<_>>();
128+
main_args(&s)
129129
}).join();
130130
env::set_exit_status(res.ok().unwrap() as i32);
131131
}

src/libstd/dynamic_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl DynamicLibrary {
101101
/// Returns the current search path for dynamic libraries being used by this
102102
/// process
103103
pub fn search_path() -> Vec<Path> {
104-
match env::var(DynamicLibrary::envvar()) {
104+
match env::var_os(DynamicLibrary::envvar()) {
105105
Some(var) => env::split_paths(&var).collect(),
106106
None => Vec::new(),
107107
}

0 commit comments

Comments
 (0)