Skip to content

Commit 92af0db

Browse files
committed
auto merge of #8518 : catamorphism/rust/issue-8498-workaround, r=brson
r? @brson
2 parents 253337d + 5be4408 commit 92af0db

File tree

4 files changed

+61
-15
lines changed

4 files changed

+61
-15
lines changed

src/compiletest/procsrv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn run(lib_path: &str,
4949

5050
let env = env + target_env(lib_path, prog);
5151
let mut proc = run::Process::new(prog, args, run::ProcessOptions {
52-
env: Some(env.slice(0, env.len())),
52+
env: Some(env),
5353
dir: None,
5454
in_fd: None,
5555
out_fd: None,

src/librustpkg/tests.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn mk_temp_workspace(short_name: &Path, version: &Version) -> Path {
114114
fn run_git(args: &[~str], env: Option<~[(~str, ~str)]>, cwd: &Path, err_msg: &str) {
115115
let cwd = (*cwd).clone();
116116
let mut prog = run::Process::new("git", args, run::ProcessOptions {
117-
env: env.map(|v| v.slice(0, v.len())),
117+
env: env,
118118
dir: Some(&cwd),
119119
in_fd: None,
120120
out_fd: None,
@@ -222,7 +222,7 @@ fn command_line_test_with_env(args: &[~str], cwd: &Path, env: Option<~[(~str, ~s
222222
assert!(os::path_is_dir(&*cwd));
223223
let cwd = (*cwd).clone();
224224
let mut prog = run::Process::new(cmd, args, run::ProcessOptions {
225-
env: env.map(|v| v.slice(0, v.len())),
225+
env: env,
226226
dir: Some(&cwd),
227227
in_fd: None,
228228
out_fd: None,
@@ -757,7 +757,9 @@ fn rust_path_test() {
757757
// use command_line_test_with_env
758758
let mut prog = run::Process::new("rustpkg",
759759
[~"install", ~"foo"],
760-
run::ProcessOptions { env: Some(&[(~"RUST_LOG",
760+
// This should actually extend the environment; then we can probably
761+
// un-ignore it
762+
run::ProcessOptions { env: Some(~[(~"RUST_LOG",
761763
~"rustpkg"),
762764
(~"RUST_PATH",
763765
dir_for_path.to_str())]),
@@ -1039,7 +1041,7 @@ fn test_extern_mod() {
10391041
~"--sysroot", test_sysroot().to_str(),
10401042
~"-o", exec_file.to_str()],
10411043
run::ProcessOptions {
1042-
env: env.map(|v| v.slice(0, v.len())),
1044+
env: env,
10431045
dir: Some(&dir),
10441046
in_fd: None,
10451047
out_fd: None,

src/libstd/run.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct ProcessOptions<'self> {
6868
* If this is Some(vec-of-names-and-values) then the new process will
6969
* have an environment containing the given named values only.
7070
*/
71-
env: Option<&'self [(~str, ~str)]>,
71+
env: Option<~[(~str, ~str)]>,
7272

7373
/**
7474
* If this is None then the new process will use the same initial working
@@ -171,7 +171,7 @@ impl Process {
171171
Some(fd) => (None, fd)
172172
};
173173

174-
let res = spawn_process_os(prog, args, options.env, options.dir,
174+
let res = spawn_process_os(prog, args, options.env.clone(), options.dir,
175175
in_fd, out_fd, err_fd);
176176

177177
unsafe {
@@ -444,7 +444,7 @@ struct SpawnProcessResult {
444444

445445
#[cfg(windows)]
446446
fn spawn_process_os(prog: &str, args: &[~str],
447-
env: Option<&[(~str, ~str)]>,
447+
env: Option<~[(~str, ~str)]>,
448448
dir: Option<&Path>,
449449
in_fd: c_int, out_fd: c_int, err_fd: c_int) -> SpawnProcessResult {
450450

@@ -627,7 +627,7 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str {
627627

628628
#[cfg(unix)]
629629
fn spawn_process_os(prog: &str, args: &[~str],
630-
env: Option<&[(~str, ~str)]>,
630+
env: Option<~[(~str, ~str)]>,
631631
dir: Option<&Path>,
632632
in_fd: c_int, out_fd: c_int, err_fd: c_int) -> SpawnProcessResult {
633633

@@ -717,7 +717,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T {
717717
}
718718

719719
#[cfg(unix)]
720-
fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
720+
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
721721
use vec;
722722

723723
// On posixy systems we can pass a char** for envp, which is a
@@ -749,7 +749,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T {
749749
}
750750

751751
#[cfg(windows)]
752-
fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
752+
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T {
753753
// On win32 we pass an "environment block" which is not a char**, but
754754
// rather a concatenation of null-terminated k=v\0 sequences, with a final
755755
// \0 to terminate.
@@ -1284,22 +1284,22 @@ mod tests {
12841284
}
12851285
12861286
#[cfg(unix,not(target_os="android"))]
1287-
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
1287+
fn run_env(env: Option<~[(~str, ~str)]>) -> run::Process {
12881288
run::Process::new("env", [], run::ProcessOptions {
12891289
env: env,
12901290
.. run::ProcessOptions::new()
12911291
})
12921292
}
12931293
#[cfg(unix,target_os="android")]
1294-
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
1294+
fn run_env(env: Option<~[(~str, ~str)]>) -> run::Process {
12951295
run::Process::new("/system/bin/sh", [~"-c",~"set"], run::ProcessOptions {
12961296
env: env,
12971297
.. run::ProcessOptions::new()
12981298
})
12991299
}
13001300
13011301
#[cfg(windows)]
1302-
fn run_env(env: Option<&[(~str, ~str)]>) -> run::Process {
1302+
fn run_env(env: Option<~[(~str, ~str)]>) -> run::Process {
13031303
run::Process::new("cmd", [~"/c", ~"set"], run::ProcessOptions {
13041304
env: env,
13051305
.. run::ProcessOptions::new()
@@ -1344,7 +1344,7 @@ mod tests {
13441344
let mut new_env = os::env();
13451345
new_env.push((~"RUN_TEST_NEW_ENV", ~"123"));
13461346
1347-
let mut prog = run_env(Some(new_env.slice(0, new_env.len())));
1347+
let mut prog = run_env(Some(new_env));
13481348
let output = str::from_bytes(prog.finish_with_output().output);
13491349
13501350
assert!(output.contains("RUN_TEST_NEW_ENV=123"));

src/test/run-pass/issue-8498.rs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
use std::io;
13+
14+
fn main() {
15+
// This is ok
16+
match &[(~5,~7)] {
17+
ps => {
18+
let (ref y, _) = ps[0];
19+
io::println(fmt!("1. y = %d", **y));
20+
assert!(**y == 5);
21+
}
22+
}
23+
24+
// This is not entirely ok
25+
match Some(&[(~5,)]) {
26+
Some(ps) => {
27+
let (ref y,) = ps[0];
28+
io::println(fmt!("2. y = %d", **y));
29+
if **y != 5 { io::println("sadness"); }
30+
}
31+
None => ()
32+
}
33+
34+
// This is not ok
35+
match Some(&[(~5,~7)]) {
36+
Some(ps) => {
37+
let (ref y, ref z) = ps[0];
38+
io::println(fmt!("3. y = %d z = %d", **y, **z));
39+
assert!(**y == 5);
40+
}
41+
None => ()
42+
}
43+
}
44+

0 commit comments

Comments
 (0)