diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-02-26 21:00:43 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-04 15:59:30 -0800 |
| commit | 95d904625b4d45af80b4e40d51a3a0fde1abaa8a (patch) | |
| tree | b0872e63b8d75543ce5141ceba44c12c459474f2 /src/librustc_driver | |
| parent | 3b3bb0e682c2d252e9f62dd9df5cff9552af91ad (diff) | |
| download | rust-95d904625b4d45af80b4e40d51a3a0fde1abaa8a.tar.gz rust-95d904625b4d45af80b4e40d51a3a0fde1abaa8a.zip | |
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.
Diffstat (limited to 'src/librustc_driver')
| -rw-r--r-- | src/librustc_driver/driver.rs | 51 | ||||
| -rw-r--r-- | src/librustc_driver/lib.rs | 54 | ||||
| -rw-r--r-- | src/librustc_driver/pretty.rs | 76 |
3 files changed, 95 insertions, 86 deletions
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 425ec7ec452..73682faf1a7 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -32,10 +32,10 @@ use super::Compilation; use serialize::json; use std::env; -use std::os; use std::ffi::OsString; -use std::old_io::fs; -use std::old_io; +use std::fs; +use std::io::{self, Write}; +use std::path::{Path, PathBuf}; use syntax::ast; use syntax::ast_map; use syntax::attr; @@ -48,8 +48,8 @@ use syntax; pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input, - outdir: &Option<Path>, - output: &Option<Path>, + outdir: &Option<PathBuf>, + output: &Option<PathBuf>, addl_plugins: Option<Vec<String>>, control: CompileController) { macro_rules! controller_entry_point{($point: ident, $make_state: expr) => ({ @@ -166,7 +166,7 @@ pub fn anon_src() -> String { pub fn source_name(input: &Input) -> String { match *input { // FIXME (#9639): This needs to handle non-utf8 paths - Input::File(ref ifile) => ifile.as_str().unwrap().to_string(), + Input::File(ref ifile) => ifile.to_str().unwrap().to_string(), Input::Str(_) => anon_src() } } @@ -243,12 +243,12 @@ pub struct CompileState<'a, 'ast: 'a, 'tcx: 'a> { impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { fn empty(input: &'a Input, session: &'a Session, - out_dir: &'a Option<Path>) + out_dir: &'a Option<PathBuf>) -> CompileState<'a, 'ast, 'tcx> { CompileState { input: input, session: session, - out_dir: out_dir.as_ref(), + out_dir: out_dir.as_ref().map(|s| &**s), cfg: None, krate: None, crate_name: None, @@ -263,7 +263,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { fn state_after_parse(input: &'a Input, session: &'a Session, - out_dir: &'a Option<Path>, + out_dir: &'a Option<PathBuf>, krate: &'a ast::Crate) -> CompileState<'a, 'ast, 'tcx> { CompileState { @@ -274,7 +274,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { fn state_after_expand(input: &'a Input, session: &'a Session, - out_dir: &'a Option<Path>, + out_dir: &'a Option<PathBuf>, expanded_crate: &'a ast::Crate, crate_name: &'a str) -> CompileState<'a, 'ast, 'tcx> { @@ -287,7 +287,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { fn state_after_write_deps(input: &'a Input, session: &'a Session, - out_dir: &'a Option<Path>, + out_dir: &'a Option<PathBuf>, ast_map: &'a ast_map::Map<'ast>, expanded_crate: &'a ast::Crate, crate_name: &'a str) @@ -302,7 +302,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { fn state_after_analysis(input: &'a Input, session: &'a Session, - out_dir: &'a Option<Path>, + out_dir: &'a Option<PathBuf>, expanded_crate: &'a ast::Crate, analysis: &'a ty::CrateAnalysis<'tcx>, tcx: &'a ty::ctxt<'tcx>) @@ -318,7 +318,7 @@ impl<'a, 'ast, 'tcx> CompileState<'a, 'ast, 'tcx> { fn state_after_llvm(input: &'a Input, session: &'a Session, - out_dir: &'a Option<Path>, + out_dir: &'a Option<PathBuf>, trans: &'a trans::CrateTranslation) -> CompileState<'a, 'ast, 'tcx> { CompileState { @@ -472,7 +472,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, if cfg!(windows) { _old_path = env::var_os("PATH").unwrap_or(_old_path); let mut new_path = sess.host_filesearch(PathKind::All).get_dylib_search_paths(); - new_path.extend(os::split_paths(_old_path.to_str().unwrap()).into_iter()); + new_path.extend(env::split_paths(&_old_path)); env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap()); } let features = sess.features.borrow(); @@ -717,7 +717,7 @@ pub fn phase_5_run_llvm_passes(sess: &Session, // Remove assembly source, unless --save-temps was specified if !sess.opts.cg.save_temps { - fs::unlink(&outputs.temp_path(config::OutputTypeAssembly)).unwrap(); + fs::remove_file(&outputs.temp_path(config::OutputTypeAssembly)).unwrap(); } } else { time(sess.time_passes(), "LLVM passes", (), |_| @@ -737,7 +737,7 @@ pub fn phase_6_link_output(sess: &Session, outputs: &OutputFilenames) { let old_path = env::var_os("PATH").unwrap_or(OsString::from_str("")); let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(); - new_path.extend(os::split_paths(old_path.to_str().unwrap()).into_iter()); + new_path.extend(env::split_paths(&old_path)); env::set_var("PATH", &env::join_paths(new_path.iter()).unwrap()); time(sess.time_passes(), "linking", (), |_| @@ -793,17 +793,17 @@ fn write_out_deps(sess: &Session, _ => return, }; - let result = (|| -> old_io::IoResult<()> { + let result = (|| -> io::Result<()> { // Build a list of files used to compile the output and // write Makefile-compatible dependency rules let files: Vec<String> = sess.codemap().files.borrow() .iter().filter(|fmap| fmap.is_real_file()) .map(|fmap| escape_dep_filename(&fmap.name)) .collect(); - let mut file = try!(old_io::File::create(&deps_filename)); + let mut file = try!(fs::File::create(&deps_filename)); for path in &out_filenames { - try!(write!(&mut file as &mut Writer, - "{}: {}\n\n", path.display(), files.connect(" "))); + try!(write!(&mut file, + "{}: {}\n\n", path.display(), files.connect(" "))); } Ok(()) })(); @@ -896,8 +896,8 @@ pub fn collect_crate_metadata(session: &Session, } pub fn build_output_filenames(input: &Input, - odir: &Option<Path>, - ofile: &Option<Path>, + odir: &Option<PathBuf>, + ofile: &Option<PathBuf>, attrs: &[ast::Attribute], sess: &Session) -> OutputFilenames { @@ -908,7 +908,7 @@ pub fn build_output_filenames(input: &Input, // We want to toss everything after the final '.' let dirpath = match *odir { Some(ref d) => d.clone(), - None => Path::new(".") + None => PathBuf::new(".") }; // If a crate name is present, we use it as the link name @@ -936,8 +936,9 @@ pub fn build_output_filenames(input: &Input, sess.warn("ignoring --out-dir flag due to -o flag."); } OutputFilenames { - out_directory: out_file.dir_path(), - out_filestem: out_file.filestem_str().unwrap().to_string(), + out_directory: out_file.parent().unwrap().to_path_buf(), + out_filestem: out_file.file_stem().unwrap() + .to_str().unwrap().to_string(), single_output_file: ofile, extra: sess.opts.cg.extra_filename.clone(), } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 15fae351ddb..aa8b7c7785d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -30,7 +30,6 @@ #![feature(old_io)] #![feature(libc)] #![feature(os)] -#![feature(old_path)] #![feature(quote)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_private)] @@ -38,6 +37,9 @@ #![feature(staged_api)] #![feature(unicode)] #![feature(exit_status)] +#![feature(path)] +#![feature(io)] +#![feature(fs)] extern crate arena; extern crate flate; @@ -73,9 +75,10 @@ use rustc::metadata; use rustc::util::common::time; use std::cmp::Ordering::Equal; -use std::old_io::{self, stdio}; -use std::iter::repeat; use std::env; +use std::iter::repeat; +use std::old_io::{self, stdio}; +use std::path::PathBuf; use std::sync::mpsc::channel; use std::thread; @@ -159,14 +162,14 @@ pub fn run_compiler<'a>(args: &[String], } // Extract output directory and file from matches. -fn make_output(matches: &getopts::Matches) -> (Option<Path>, Option<Path>) { - let odir = matches.opt_str("out-dir").map(|o| Path::new(o)); - let ofile = matches.opt_str("o").map(|o| Path::new(o)); +fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>) { + let odir = matches.opt_str("out-dir").map(|o| PathBuf::new(&o)); + let ofile = matches.opt_str("o").map(|o| PathBuf::new(&o)); (odir, ofile) } // Extract input (string or file and optional path) from matches. -fn make_input(free_matches: &[String]) -> Option<(Input, Option<Path>)> { +fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>)> { if free_matches.len() == 1 { let ifile = &free_matches[0][..]; if ifile == "-" { @@ -174,7 +177,7 @@ fn make_input(free_matches: &[String]) -> Option<(Input, Option<Path>)> { let src = String::from_utf8(contents).unwrap(); Some((Input::Str(src), None)) } else { - Some((Input::File(Path::new(ifile)), Some(Path::new(ifile)))) + Some((Input::File(PathBuf::new(ifile)), Some(PathBuf::new(ifile)))) } } else { None @@ -215,14 +218,15 @@ pub trait CompilerCalls<'a> { &getopts::Matches, &Session, &Input, - &Option<Path>, - &Option<Path>) + &Option<PathBuf>, + &Option<PathBuf>) -> Compilation; // Called after we extract the input from the arguments. Gives the implementer // an opportunity to change the inputs or to add some custom input handling. // The default behaviour is to simply pass through the inputs. - fn some_input(&mut self, input: Input, input_path: Option<Path>) -> (Input, Option<Path>) { + fn some_input(&mut self, input: Input, input_path: Option<PathBuf>) + -> (Input, Option<PathBuf>) { (input, input_path) } @@ -234,10 +238,10 @@ pub trait CompilerCalls<'a> { fn no_input(&mut self, &getopts::Matches, &config::Options, - &Option<Path>, - &Option<Path>, + &Option<PathBuf>, + &Option<PathBuf>, &diagnostics::registry::Registry) - -> Option<(Input, Option<Path>)>; + -> Option<(Input, Option<PathBuf>)>; // Parse pretty printing information from the arguments. The implementer can // choose to ignore this (the default will return None) which will skip pretty @@ -293,10 +297,10 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { fn no_input(&mut self, matches: &getopts::Matches, sopts: &config::Options, - odir: &Option<Path>, - ofile: &Option<Path>, + odir: &Option<PathBuf>, + ofile: &Option<PathBuf>, descriptions: &diagnostics::registry::Registry) - -> Option<(Input, Option<Path>)> { + -> Option<(Input, Option<PathBuf>)> { match matches.free.len() { 0 => { if sopts.describe_lints { @@ -346,8 +350,8 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls { matches: &getopts::Matches, sess: &Session, input: &Input, - odir: &Option<Path>, - ofile: &Option<Path>) + odir: &Option<PathBuf>, + ofile: &Option<PathBuf>) -> Compilation { RustcDefaultCalls::print_crate_info(sess, Some(input), odir, ofile).and_then( || RustcDefaultCalls::list_metadata(sess, matches, input)) @@ -400,11 +404,12 @@ impl RustcDefaultCalls { if r.contains(&("ls".to_string())) { match input { &Input::File(ref ifile) => { - let mut stdout = old_io::stdout(); let path = &(*ifile); + let mut v = Vec::new(); metadata::loader::list_file_metadata(sess.target.target.options.is_like_osx, path, - &mut stdout).unwrap(); + &mut v).unwrap(); + println!("{}", String::from_utf8(v).unwrap()); } &Input::Str(_) => { early_error("cannot list metadata for stdin"); @@ -419,8 +424,8 @@ impl RustcDefaultCalls { fn print_crate_info(sess: &Session, input: Option<&Input>, - odir: &Option<Path>, - ofile: &Option<Path>) + odir: &Option<PathBuf>, + ofile: &Option<PathBuf>) -> Compilation { if sess.opts.prints.len() == 0 { return Compilation::Continue; @@ -457,7 +462,8 @@ impl RustcDefaultCalls { style, &id, &t_outputs.with_extension("")); - println!("{}", fname.filename_display()); + println!("{}", fname.file_name().unwrap() + .to_string_lossy()); } } } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index f433e67d878..ffb2a05e437 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -38,8 +38,11 @@ use syntax::ptr::P; use graphviz as dot; -use std::old_io::{self, MemReader}; +use std::fs::File; +use std::io::{self, Write}; +use std::old_io; use std::option; +use std::path::PathBuf; use std::str::FromStr; #[derive(Copy, PartialEq, Debug)] @@ -208,7 +211,7 @@ impl<'ast> PrinterSupport<'ast> for IdentifiedAnnotation<'ast> { impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { fn pre(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> old_io::IoResult<()> { + node: pprust::AnnNode) -> io::Result<()> { match node { pprust::NodeExpr(_) => s.popen(), _ => Ok(()) @@ -216,7 +219,7 @@ impl<'ast> pprust::PpAnn for IdentifiedAnnotation<'ast> { } fn post(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> old_io::IoResult<()> { + node: pprust::AnnNode) -> io::Result<()> { match node { pprust::NodeIdent(_) | pprust::NodeName(_) => Ok(()), @@ -259,7 +262,7 @@ impl<'ast> PrinterSupport<'ast> for HygieneAnnotation<'ast> { impl<'ast> pprust::PpAnn for HygieneAnnotation<'ast> { fn post(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> old_io::IoResult<()> { + node: pprust::AnnNode) -> io::Result<()> { match node { pprust::NodeIdent(&ast::Ident { name: ast::Name(nm), ctxt }) => { try!(pp::space(&mut s.s)); @@ -294,7 +297,7 @@ impl<'tcx> PrinterSupport<'tcx> for TypedAnnotation<'tcx> { impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> { fn pre(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> old_io::IoResult<()> { + node: pprust::AnnNode) -> io::Result<()> { match node { pprust::NodeExpr(_) => s.popen(), _ => Ok(()) @@ -302,7 +305,7 @@ impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> { } fn post(&self, s: &mut pprust::State, - node: pprust::AnnNode) -> old_io::IoResult<()> { + node: pprust::AnnNode) -> io::Result<()> { let tcx = &self.analysis.ty_cx; match node { pprust::NodeExpr(expr) => { @@ -507,7 +510,7 @@ pub fn pretty_print_input(sess: Session, input: &Input, ppm: PpMode, opt_uii: Option<UserIdentifiedItem>, - ofile: Option<Path>) { + ofile: Option<PathBuf>) { let krate = driver::phase_1_parse_input(&sess, cfg, input); let krate = if let PpmSource(PpmEveryBodyLoops) = ppm { @@ -547,24 +550,15 @@ pub fn pretty_print_input(sess: Session, .unwrap() .as_bytes() .to_vec(); - let mut rdr = MemReader::new(src); + let mut rdr = &src[..]; - let out = match ofile { - None => box old_io::stdout() as Box<Writer+'static>, - Some(p) => { - let r = old_io::File::create(&p); - match r { - Ok(w) => box w as Box<Writer+'static>, - Err(e) => panic!("print-print failed to open {} due to {}", - p.display(), e), - } - } - }; + let mut out = Vec::new(); match (ppm, opt_uii) { - (PpmSource(s), None) => + (PpmSource(s), None) => { + let out: &mut Write = &mut out; s.call_with_pp_support( - sess, ast_map, &arenas, id, out, |annotation, out| { + sess, ast_map, &arenas, id, box out, |annotation, out| { debug!("pretty printing source code {:?}", s); let sess = annotation.sess(); pprust::print_crate(sess.codemap(), @@ -575,9 +569,11 @@ pub fn pretty_print_input(sess: Session, out, annotation.pp_ann(), is_expanded) - }), + }) + } - (PpmSource(s), Some(uii)) => + (PpmSource(s), Some(uii)) => { + let out: &mut Write = &mut out; s.call_with_pp_support( sess, ast_map, &arenas, id, (out,uii), |annotation, (out,uii)| { debug!("pretty printing source code {:?}", s); @@ -589,7 +585,7 @@ pub fn pretty_print_input(sess: Session, sess.diagnostic(), src_name.to_string(), &mut rdr, - out, + box out, annotation.pp_ann(), is_expanded); for node_id in uii.all_matching_node_ids(ast_map) { @@ -600,7 +596,8 @@ pub fn pretty_print_input(sess: Session, try!(pp::hardbreak(&mut pp_state.s)); } pp::eof(&mut pp_state.s) - }), + }) + } (PpmFlowGraph(mode), opt_uii) => { debug!("pretty printing flow graph for {:?}", opt_uii); @@ -618,6 +615,7 @@ pub fn pretty_print_input(sess: Session, }); let code = blocks::Code::from_node(node); + let out: &mut Writer = &mut out; match code { Some(code) => { let variants = gather_flowgraph_variants(&sess); @@ -642,14 +640,25 @@ pub fn pretty_print_input(sess: Session, } } } - }.unwrap() + }.unwrap(); + + match ofile { + None => print!("{}", String::from_utf8(out).unwrap()), + Some(p) => { + match File::create(&p) { + Ok(mut w) => w.write_all(&out).unwrap(), + Err(e) => panic!("print-print failed to open {} due to {}", + p.display(), e), + } + } + } } fn print_flowgraph<W:old_io::Writer>(variants: Vec<borrowck_dot::Variant>, analysis: ty::CrateAnalysis, code: blocks::Code, mode: PpFlowGraphMode, - mut out: W) -> old_io::IoResult<()> { + mut out: W) -> io::Result<()> { let ty_cx = &analysis.ty_cx; let cfg = match code { blocks::BlockCode(block) => cfg::CFG::new(ty_cx, &*block), @@ -689,17 +698,10 @@ fn print_flowgraph<W:old_io::Writer>(variants: Vec<borrowck_dot::Variant>, } } - fn expand_err_details(r: old_io::IoResult<()>) -> old_io::IoResult<()> { + fn expand_err_details(r: old_io::IoResult<()>) -> io::Result<()> { r.map_err(|ioerr| { - let orig_detail = ioerr.detail.clone(); - let m = "graphviz::render failed"; - old_io::IoError { - detail: Some(match orig_detail { - None => m.to_string(), - Some(d) => format!("{}: {}", m, d) - }), - ..ioerr - } + io::Error::new(io::ErrorKind::Other, "graphviz::render failed", + Some(ioerr.to_string())) }) } } |
