Skip to content

Commit 95d9046

Browse files
committed
std: Deprecate std::old_io::fs
This commit deprecates the majority of std::old_io::fs in favor of std::fs and its new functionality. Some functions remain non-deprecated but are now behind a feature gate called `old_fs`. These functions will be deprecated once suitable replacements have been implemented. The compiler has been migrated to new `std::fs` and `std::path` APIs where appropriate as part of this change.
1 parent 3b3bb0e commit 95d9046

Some content is hidden

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

80 files changed

+1430
-1209
lines changed

mk/docs.mk

+2
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,13 @@ compiler-docs: $(COMPILER_DOC_TARGETS)
273273
trpl: doc/book/index.html
274274

275275
doc/book/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/trpl/*.md) | doc/
276+
@$(call E, rustbook: $@)
276277
$(Q)rm -rf doc/book
277278
$(Q)$(RUSTBOOK) build $(S)src/doc/trpl doc/book
278279

279280
style: doc/style/index.html
280281

281282
doc/style/index.html: $(RUSTBOOK_EXE) $(wildcard $(S)/src/doc/style/*.md) | doc/
283+
@$(call E, rustbook: $@)
282284
$(Q)rm -rf doc/style
283285
$(Q)$(RUSTBOOK) build $(S)src/doc/style doc/style

src/compiletest/common.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub use self::Mode::*;
1111

1212
use std::fmt;
1313
use std::str::FromStr;
14+
use std::path::PathBuf;
1415

1516
#[derive(Clone, Copy, PartialEq, Debug)]
1617
pub enum Mode {
@@ -68,13 +69,13 @@ pub struct Config {
6869
pub run_lib_path: String,
6970

7071
// The rustc executable
71-
pub rustc_path: Path,
72+
pub rustc_path: PathBuf,
7273

7374
// The clang executable
74-
pub clang_path: Option<Path>,
75+
pub clang_path: Option<PathBuf>,
7576

7677
// The llvm binaries path
77-
pub llvm_bin_path: Option<Path>,
78+
pub llvm_bin_path: Option<PathBuf>,
7879

7980
// The valgrind path
8081
pub valgrind_path: Option<String>,
@@ -84,13 +85,13 @@ pub struct Config {
8485
pub force_valgrind: bool,
8586

8687
// The directory containing the tests to run
87-
pub src_base: Path,
88+
pub src_base: PathBuf,
8889

8990
// The directory where programs should be built
90-
pub build_base: Path,
91+
pub build_base: PathBuf,
9192

9293
// Directory for auxiliary libraries
93-
pub aux_base: Path,
94+
pub aux_base: PathBuf,
9495

9596
// The name of the stage being built (stage1, etc)
9697
pub stage_id: String,
@@ -105,7 +106,7 @@ pub struct Config {
105106
pub filter: Option<String>,
106107

107108
// Write out a parseable log of tests that were run
108-
pub logfile: Option<Path>,
109+
pub logfile: Option<PathBuf>,
109110

110111
// A command line to prefix program execution with,
111112
// for running under valgrind
@@ -133,7 +134,7 @@ pub struct Config {
133134
pub lldb_version: Option<String>,
134135

135136
// Path to the android tools
136-
pub android_cross_path: Path,
137+
pub android_cross_path: PathBuf,
137138

138139
// Extra parameter to run adb on arm-linux-androideabi
139140
pub adb_path: String,

src/compiletest/compiletest.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#![feature(test)]
2222
#![feature(unicode)]
2323
#![feature(core)]
24+
#![feature(path)]
25+
#![feature(os)]
26+
#![feature(io)]
27+
#![feature(fs)]
28+
#![feature(net)]
2429

2530
#![deny(warnings)]
2631

@@ -31,8 +36,9 @@ extern crate getopts;
3136
extern crate log;
3237

3338
use std::env;
39+
use std::fs;
3440
use std::old_io;
35-
use std::old_io::fs;
41+
use std::path::{Path, PathBuf};
3642
use std::thunk::Thunk;
3743
use getopts::{optopt, optflag, reqopt};
3844
use common::Config;
@@ -114,9 +120,9 @@ pub fn parse_config(args: Vec<String> ) -> Config {
114120
panic!()
115121
}
116122

117-
fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
123+
fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf {
118124
match m.opt_str(nm) {
119-
Some(s) => Path::new(s),
125+
Some(s) => PathBuf::new(&s),
120126
None => panic!("no option (=path) found for {}", nm),
121127
}
122128
}
@@ -131,18 +137,18 @@ pub fn parse_config(args: Vec<String> ) -> Config {
131137
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
132138
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
133139
rustc_path: opt_path(matches, "rustc-path"),
134-
clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
140+
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::new(&s)),
135141
valgrind_path: matches.opt_str("valgrind-path"),
136142
force_valgrind: matches.opt_present("force-valgrind"),
137-
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
143+
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::new(&s)),
138144
src_base: opt_path(matches, "src-base"),
139145
build_base: opt_path(matches, "build-base"),
140146
aux_base: opt_path(matches, "aux-base"),
141147
stage_id: matches.opt_str("stage-id").unwrap(),
142148
mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"),
143149
run_ignored: matches.opt_present("ignored"),
144150
filter: filter,
145-
logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
151+
logfile: matches.opt_str("logfile").map(|s| PathBuf::new(&s)),
146152
runtool: matches.opt_str("runtool"),
147153
host_rustcflags: matches.opt_str("host-rustcflags"),
148154
target_rustcflags: matches.opt_str("target-rustcflags"),
@@ -276,9 +282,9 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
276282
debug!("making tests from {:?}",
277283
config.src_base.display());
278284
let mut tests = Vec::new();
279-
let dirs = fs::readdir(&config.src_base).unwrap();
280-
for file in &dirs {
281-
let file = file.clone();
285+
let dirs = fs::read_dir(&config.src_base).unwrap();
286+
for file in dirs {
287+
let file = file.unwrap().path();
282288
debug!("inspecting file {:?}", file.display());
283289
if is_test(config, &file) {
284290
let t = make_test(config, &file, || {
@@ -301,7 +307,7 @@ pub fn is_test(config: &Config, testfile: &Path) -> bool {
301307
_ => vec!(".rc".to_string(), ".rs".to_string())
302308
};
303309
let invalid_prefixes = vec!(".".to_string(), "#".to_string(), "~".to_string());
304-
let name = testfile.filename_str().unwrap();
310+
let name = testfile.file_name().unwrap().to_str().unwrap();
305311

306312
let mut valid = false;
307313

@@ -337,9 +343,9 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
337343

338344
// Try to elide redundant long paths
339345
fn shorten(path: &Path) -> String {
340-
let filename = path.filename_str();
341-
let p = path.dir_path();
342-
let dir = p.filename_str();
346+
let filename = path.file_name().unwrap().to_str();
347+
let p = path.parent().unwrap();
348+
let dir = p.file_name().unwrap().to_str();
343349
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
344350
}
345351

@@ -348,19 +354,17 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
348354

349355
pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
350356
let config = (*config).clone();
351-
// FIXME (#9639): This needs to handle non-utf8 paths
352-
let testfile = testfile.as_str().unwrap().to_string();
357+
let testfile = testfile.to_path_buf();
353358
test::DynTestFn(Thunk::new(move || {
354-
runtest::run(config, testfile)
359+
runtest::run(config, &testfile)
355360
}))
356361
}
357362

358363
pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
359364
let config = (*config).clone();
360-
// FIXME (#9639): This needs to handle non-utf8 paths
361-
let testfile = testfile.as_str().unwrap().to_string();
365+
let testfile = testfile.to_path_buf();
362366
test::DynMetricFn(box move |mm: &mut test::MetricMap| {
363-
runtest::run_metrics(config, testfile, mm)
367+
runtest::run_metrics(config, &testfile, mm)
364368
})
365369
}
366370

src/compiletest/errors.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
// except according to those terms.
1010
use self::WhichLine::*;
1111

12-
use std::old_io::{BufferedReader, File};
12+
use std::fs::File;
13+
use std::io::BufReader;
14+
use std::io::prelude::*;
15+
use std::path::Path;
1316

1417
pub struct ExpectedError {
1518
pub line: uint,
@@ -29,7 +32,7 @@ enum WhichLine { ThisLine, FollowPrevious(uint), AdjustBackward(uint) }
2932
/// //~| ERROR message two for that same line.
3033
// Load any test directives embedded in the file
3134
pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
32-
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
35+
let rdr = BufReader::new(File::open(testfile).unwrap());
3336

3437
// `last_nonfollow_error` tracks the most recently seen
3538
// line with an error template that did not use the

src/compiletest/header.rs

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

1111
use std::env;
12+
use std::fs::File;
13+
use std::io::BufReader;
14+
use std::io::prelude::*;
15+
use std::path::{Path, PathBuf};
1216

1317
use common::Config;
1418
use common;
@@ -23,7 +27,7 @@ pub struct TestProps {
2327
pub run_flags: Option<String>,
2428
// If present, the name of a file that this test should match when
2529
// pretty-printed
26-
pub pp_exact: Option<Path>,
30+
pub pp_exact: Option<PathBuf>,
2731
// Modules from aux directory that should be compiled
2832
pub aux_builds: Vec<String> ,
2933
// Environment settings to use during execution
@@ -62,7 +66,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
6266
let mut pretty_mode = None;
6367
let mut pretty_compare_only = false;
6468
let mut forbid_output = Vec::new();
65-
iter_header(testfile, |ln| {
69+
iter_header(testfile, &mut |ln| {
6670
match parse_error_pattern(ln) {
6771
Some(ep) => error_patterns.push(ep),
6872
None => ()
@@ -219,7 +223,7 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
219223
}
220224
}
221225

222-
let val = iter_header(testfile, |ln| {
226+
let val = iter_header(testfile, &mut |ln| {
223227
!parse_name_directive(ln, "ignore-test") &&
224228
!parse_name_directive(ln, &ignore_target(config)) &&
225229
!parse_name_directive(ln, &ignore_stage(config)) &&
@@ -232,12 +236,8 @@ pub fn is_test_ignored(config: &Config, testfile: &Path) -> bool {
232236
!val
233237
}
234238

235-
fn iter_header<F>(testfile: &Path, mut it: F) -> bool where
236-
F: FnMut(&str) -> bool,
237-
{
238-
use std::old_io::{BufferedReader, File};
239-
240-
let mut rdr = BufferedReader::new(File::open(testfile).unwrap());
239+
fn iter_header(testfile: &Path, it: &mut FnMut(&str) -> bool) -> bool {
240+
let rdr = BufReader::new(File::open(testfile).unwrap());
241241
for ln in rdr.lines() {
242242
// Assume that any directives will be found before the first
243243
// module or function. This doesn't seem to be an optimization
@@ -322,12 +322,12 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
322322
})
323323
}
324324

325-
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
325+
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
326326
match parse_name_value_directive(line, "pp-exact") {
327-
Some(s) => Some(Path::new(s)),
327+
Some(s) => Some(PathBuf::new(&s)),
328328
None => {
329329
if parse_name_directive(line, "pp-exact") {
330-
testfile.filename().map(|s| Path::new(s))
330+
testfile.file_name().map(|s| PathBuf::new(s))
331331
} else {
332332
None
333333
}

src/compiletest/procsrv.rs

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

11-
use std::old_io::process::{ProcessExit, Command, Process, ProcessOutput};
11+
use std::process::{ExitStatus, Command, Child, Output, Stdio};
12+
use std::io::prelude::*;
1213
use std::dynamic_lib::DynamicLibrary;
1314

1415
fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
@@ -25,10 +26,10 @@ fn add_target_env(cmd: &mut Command, lib_path: &str, aux_path: Option<&str>) {
2526
let var = DynamicLibrary::envvar();
2627
let newpath = DynamicLibrary::create_path(&path);
2728
let newpath = String::from_utf8(newpath).unwrap();
28-
cmd.env(var.to_string(), newpath);
29+
cmd.env(var, &newpath);
2930
}
3031

31-
pub struct Result {pub status: ProcessExit, pub out: String, pub err: String}
32+
pub struct Result {pub status: ExitStatus, pub out: String, pub err: String}
3233

3334
pub fn run(lib_path: &str,
3435
prog: &str,
@@ -38,24 +39,27 @@ pub fn run(lib_path: &str,
3839
input: Option<String>) -> Option<Result> {
3940

4041
let mut cmd = Command::new(prog);
41-
cmd.args(args);
42+
cmd.args(args)
43+
.stdin(Stdio::piped())
44+
.stdout(Stdio::piped())
45+
.stderr(Stdio::piped());
4246
add_target_env(&mut cmd, lib_path, aux_path);
4347
for (key, val) in env {
44-
cmd.env(key, val);
48+
cmd.env(&key, &val);
4549
}
4650

4751
match cmd.spawn() {
4852
Ok(mut process) => {
4953
if let Some(input) = input {
5054
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
5155
}
52-
let ProcessOutput { status, output, error } =
56+
let Output { status, stdout, stderr } =
5357
process.wait_with_output().unwrap();
5458

5559
Some(Result {
5660
status: status,
57-
out: String::from_utf8(output).unwrap(),
58-
err: String::from_utf8(error).unwrap()
61+
out: String::from_utf8(stdout).unwrap(),
62+
err: String::from_utf8(stderr).unwrap()
5963
})
6064
},
6165
Err(..) => None
@@ -67,13 +71,16 @@ pub fn run_background(lib_path: &str,
6771
aux_path: Option<&str>,
6872
args: &[String],
6973
env: Vec<(String, String)> ,
70-
input: Option<String>) -> Option<Process> {
74+
input: Option<String>) -> Option<Child> {
7175

7276
let mut cmd = Command::new(prog);
73-
cmd.args(args);
77+
cmd.args(args)
78+
.stdin(Stdio::piped())
79+
.stdout(Stdio::piped())
80+
.stderr(Stdio::piped());
7481
add_target_env(&mut cmd, lib_path, aux_path);
7582
for (key, val) in env {
76-
cmd.env(key, val);
83+
cmd.env(&key, &val);
7784
}
7885

7986
match cmd.spawn() {

0 commit comments

Comments
 (0)