Skip to content

Commit 767e3ae

Browse files
committed
auto merge of #6434 : alexcrichton/rust/less-implicit-vecs, r=bstrie
This closes #5204 and #6421. This also removes the `vecs_implicitly_copyable` lint (although now reading #6421, this may not be desired?). If we want to leave it in, it at least removes it from the compiler.
2 parents 27c228f + ffcc680 commit 767e3ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+653
-681
lines changed

Diff for: src/compiletest/compiletest.rc

+38-27
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
#[crate_type = "bin"];
1212

13-
#[allow(vecs_implicitly_copyable)];
1413
#[allow(non_camel_case_types)];
15-
#[allow(deprecated_pattern)];
1614

1715
extern mod std(vers = "0.7-pre");
1816

@@ -43,8 +41,8 @@ pub mod errors;
4341
pub fn main() {
4442
let args = os::args();
4543
let config = parse_config(args);
46-
log_config(config);
47-
run_tests(config);
44+
log_config(&config);
45+
run_tests(&config);
4846
}
4947

5048
pub fn parse_config(args: ~[~str]) -> config {
@@ -89,30 +87,31 @@ pub fn parse_config(args: ~[~str]) -> config {
8987
run_ignored: getopts::opt_present(matches, ~"ignored"),
9088
filter:
9189
if vec::len(matches.free) > 0u {
92-
option::Some(matches.free[0])
90+
option::Some(copy matches.free[0])
9391
} else { option::None },
9492
logfile: getopts::opt_maybe_str(matches, ~"logfile").map(|s| Path(*s)),
9593
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
9694
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
9795
jit: getopts::opt_present(matches, ~"jit"),
9896
newrt: getopts::opt_present(matches, ~"newrt"),
99-
target: opt_str(getopts::opt_maybe_str(matches, ~"target")),
100-
adb_path: opt_str(getopts::opt_maybe_str(matches, ~"adb-path")),
101-
adb_test_dir: opt_str(getopts::opt_maybe_str(matches, ~"adb-test-dir")),
97+
target: opt_str2(getopts::opt_maybe_str(matches, ~"target")).to_str(),
98+
adb_path: opt_str2(getopts::opt_maybe_str(matches, ~"adb-path")).to_str(),
99+
adb_test_dir:
100+
opt_str2(getopts::opt_maybe_str(matches, ~"adb-test-dir")).to_str(),
102101
adb_device_status:
103-
if (opt_str(getopts::opt_maybe_str(matches, ~"target")) ==
102+
if (opt_str2(getopts::opt_maybe_str(matches, ~"target")) ==
104103
~"arm-linux-androideabi") {
105-
if (opt_str(getopts::opt_maybe_str(matches, ~"adb-test-dir")) !=
104+
if (opt_str2(getopts::opt_maybe_str(matches, ~"adb-test-dir")) !=
106105
~"(none)" &&
107-
opt_str(getopts::opt_maybe_str(matches, ~"adb-test-dir")) !=
106+
opt_str2(getopts::opt_maybe_str(matches, ~"adb-test-dir")) !=
108107
~"") { true }
109108
else { false }
110109
} else { false },
111110
verbose: getopts::opt_present(matches, ~"verbose")
112111
}
113112
}
114113

115-
pub fn log_config(config: config) {
114+
pub fn log_config(config: &config) {
116115
let c = config;
117116
logv(c, fmt!("configuration:"));
118117
logv(c, fmt!("compile_lib_path: %s", config.compile_lib_path));
@@ -123,9 +122,9 @@ pub fn log_config(config: config) {
123122
logv(c, fmt!("stage_id: %s", config.stage_id));
124123
logv(c, fmt!("mode: %s", mode_str(config.mode)));
125124
logv(c, fmt!("run_ignored: %b", config.run_ignored));
126-
logv(c, fmt!("filter: %s", opt_str(config.filter)));
127-
logv(c, fmt!("runtool: %s", opt_str(config.runtool)));
128-
logv(c, fmt!("rustcflags: %s", opt_str(config.rustcflags)));
125+
logv(c, fmt!("filter: %s", opt_str(&config.filter)));
126+
logv(c, fmt!("runtool: %s", opt_str(&config.runtool)));
127+
logv(c, fmt!("rustcflags: %s", opt_str(&config.rustcflags)));
129128
logv(c, fmt!("jit: %b", config.jit));
130129
logv(c, fmt!("newrt: %b", config.newrt));
131130
logv(c, fmt!("target: %s", config.target));
@@ -136,8 +135,18 @@ pub fn log_config(config: config) {
136135
logv(c, fmt!("\n"));
137136
}
138137

139-
pub fn opt_str(maybestr: Option<~str>) -> ~str {
140-
match maybestr { option::Some(s) => s, option::None => ~"(none)" }
138+
pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str {
139+
match *maybestr {
140+
option::None => "(none)",
141+
option::Some(ref s) => {
142+
let s: &'a str = *s;
143+
s
144+
}
145+
}
146+
}
147+
148+
pub fn opt_str2(maybestr: Option<~str>) -> ~str {
149+
match maybestr { None => ~"(none)", Some(s) => { s } }
141150
}
142151

143152
pub fn str_opt(maybestr: ~str) -> Option<~str> {
@@ -165,16 +174,16 @@ pub fn mode_str(mode: mode) -> ~str {
165174
}
166175
}
167176

168-
pub fn run_tests(config: config) {
177+
pub fn run_tests(config: &config) {
169178
let opts = test_opts(config);
170179
let tests = make_tests(config);
171180
let res = test::run_tests_console(&opts, tests);
172181
if !res { fail!("Some tests failed"); }
173182
}
174183

175-
pub fn test_opts(config: config) -> test::TestOpts {
184+
pub fn test_opts(config: &config) -> test::TestOpts {
176185
test::TestOpts {
177-
filter: config.filter,
186+
filter: copy config.filter,
178187
run_ignored: config.run_ignored,
179188
logfile: copy config.logfile,
180189
run_tests: true,
@@ -184,7 +193,7 @@ pub fn test_opts(config: config) -> test::TestOpts {
184193
}
185194
}
186195

187-
pub fn make_tests(config: config) -> ~[test::TestDescAndFn] {
196+
pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] {
188197
debug!("making tests from %s",
189198
config.src_base.to_str());
190199
let mut tests = ~[];
@@ -198,7 +207,7 @@ pub fn make_tests(config: config) -> ~[test::TestDescAndFn] {
198207
tests
199208
}
200209

201-
pub fn is_test(config: config, testfile: &Path) -> bool {
210+
pub fn is_test(config: &config, testfile: &Path) -> bool {
202211
// Pretty-printer does not work with .rc files yet
203212
let valid_extensions =
204213
match config.mode {
@@ -221,7 +230,7 @@ pub fn is_test(config: config, testfile: &Path) -> bool {
221230
return valid;
222231
}
223232

224-
pub fn make_test(config: config, testfile: &Path) -> test::TestDescAndFn {
233+
pub fn make_test(config: &config, testfile: &Path) -> test::TestDescAndFn {
225234
test::TestDescAndFn {
226235
desc: test::TestDesc {
227236
name: make_test_name(config, testfile),
@@ -232,13 +241,15 @@ pub fn make_test(config: config, testfile: &Path) -> test::TestDescAndFn {
232241
}
233242
}
234243

235-
pub fn make_test_name(config: config, testfile: &Path) -> test::TestName {
244+
pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
236245
test::DynTestName(fmt!("[%s] %s",
237246
mode_str(config.mode),
238247
testfile.to_str()))
239248
}
240249

241-
pub fn make_test_closure(config: config, testfile: &Path) -> test::TestFn {
242-
let testfile = testfile.to_str();
243-
test::DynTestFn(|| runtest::run(config, testfile))
250+
pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
251+
use core::cell::Cell;
252+
let config = Cell(copy *config);
253+
let testfile = Cell(testfile.to_str());
254+
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
244255
}

Diff for: src/compiletest/header.rs

+22-17
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ pub fn load_props(testfile: &Path) -> TestProps {
5252
pp_exact = parse_pp_exact(ln, testfile);
5353
}
5454

55-
for parse_aux_build(ln).each |ab| {
56-
aux_builds.push(*ab);
55+
match parse_aux_build(ln) {
56+
Some(ab) => { aux_builds.push(ab); }
57+
None => {}
5758
}
5859

59-
for parse_exec_env(ln).each |ee| {
60-
exec_env.push(*ee);
60+
match parse_exec_env(ln) {
61+
Some(ee) => { exec_env.push(ee); }
62+
None => {}
6163
}
6264

6365
match parse_debugger_cmd(ln) {
@@ -81,7 +83,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
8183
};
8284
}
8385

84-
pub fn is_test_ignored(config: config, testfile: &Path) -> bool {
86+
pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
8587
for iter_header(testfile) |ln| {
8688
if parse_name_directive(ln, ~"xfail-test") { return true; }
8789
if parse_name_directive(ln, xfail_target()) { return true; }
@@ -111,44 +113,47 @@ fn iter_header(testfile: &Path, it: &fn(~str) -> bool) -> bool {
111113
return true;
112114
}
113115

114-
fn parse_error_pattern(line: ~str) -> Option<~str> {
116+
fn parse_error_pattern(line: &str) -> Option<~str> {
115117
parse_name_value_directive(line, ~"error-pattern")
116118
}
117119

118-
fn parse_aux_build(line: ~str) -> Option<~str> {
120+
fn parse_aux_build(line: &str) -> Option<~str> {
119121
parse_name_value_directive(line, ~"aux-build")
120122
}
121123

122-
fn parse_compile_flags(line: ~str) -> Option<~str> {
124+
fn parse_compile_flags(line: &str) -> Option<~str> {
123125
parse_name_value_directive(line, ~"compile-flags")
124126
}
125127

126-
fn parse_debugger_cmd(line: ~str) -> Option<~str> {
128+
fn parse_debugger_cmd(line: &str) -> Option<~str> {
127129
parse_name_value_directive(line, ~"debugger")
128130
}
129131

130-
fn parse_check_line(line: ~str) -> Option<~str> {
132+
fn parse_check_line(line: &str) -> Option<~str> {
131133
parse_name_value_directive(line, ~"check")
132134
}
133135

134-
fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
136+
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
135137
do parse_name_value_directive(line, ~"exec-env").map |nv| {
136138
// nv is either FOO or FOO=BAR
137139
let mut strs = ~[];
138140
for str::each_splitn_char(*nv, '=', 1u) |s| { strs.push(s.to_owned()); }
139141
match strs.len() {
140-
1u => (strs[0], ~""),
141-
2u => (strs[0], strs[1]),
142+
1u => (strs.pop(), ~""),
143+
2u => {
144+
let end = strs.pop();
145+
(strs.pop(), end)
146+
}
142147
n => fail!("Expected 1 or 2 strings, not %u", n)
143148
}
144149
}
145150
}
146151

147-
fn parse_pp_exact(line: ~str, testfile: &Path) -> Option<Path> {
152+
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
148153
match parse_name_value_directive(line, ~"pp-exact") {
149154
Some(s) => Some(Path(s)),
150155
None => {
151-
if parse_name_directive(line, ~"pp-exact") {
156+
if parse_name_directive(line, "pp-exact") {
152157
Some(testfile.file_path())
153158
} else {
154159
None
@@ -157,11 +162,11 @@ fn parse_pp_exact(line: ~str, testfile: &Path) -> Option<Path> {
157162
}
158163
}
159164

160-
fn parse_name_directive(line: ~str, directive: ~str) -> bool {
165+
fn parse_name_directive(line: &str, directive: &str) -> bool {
161166
str::contains(line, directive)
162167
}
163168

164-
fn parse_name_value_directive(line: ~str,
169+
fn parse_name_value_directive(line: &str,
165170
directive: ~str) -> Option<~str> {
166171
let keycolon = directive + ~":";
167172
match str::find_str(line, keycolon) {

Diff for: src/compiletest/procsrv.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::run::spawn_process;
1414
use core::run;
1515

1616
#[cfg(target_os = "win32")]
17-
fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
17+
fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] {
1818

1919
let mut env = os::env();
2020

@@ -27,7 +27,7 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
2727
if k == ~"PATH" { (~"PATH", v + ~";" + lib_path + ~";" + aux_path) }
2828
else { (k,v) }
2929
};
30-
if str::ends_with(prog, ~"rustc.exe") {
30+
if str::ends_with(prog, "rustc.exe") {
3131
env.push((~"RUST_THREADS", ~"1"));
3232
}
3333
return env;
@@ -36,16 +36,16 @@ fn target_env(lib_path: ~str, prog: ~str) -> ~[(~str,~str)] {
3636
#[cfg(target_os = "linux")]
3737
#[cfg(target_os = "macos")]
3838
#[cfg(target_os = "freebsd")]
39-
fn target_env(_lib_path: ~str, _prog: ~str) -> ~[(~str,~str)] {
39+
fn target_env(_lib_path: &str, _prog: &str) -> ~[(~str,~str)] {
4040
~[]
4141
}
4242
43-
struct Result {status: int, out: ~str, err: ~str}
43+
pub struct Result {status: int, out: ~str, err: ~str}
4444
4545
// FIXME (#2659): This code is duplicated in core::run::program_output
46-
pub fn run(lib_path: ~str,
47-
prog: ~str,
48-
args: ~[~str],
46+
pub fn run(lib_path: &str,
47+
prog: &str,
48+
args: &[~str],
4949
env: ~[(~str, ~str)],
5050
input: Option<~str>) -> Result {
5151
let pipe_in = os::pipe();

0 commit comments

Comments
 (0)