#![feature(drain_filter)]
#![feature(dyn_trait)]
#![feature(from_ref)]
+#![feature(fs_read_write)]
#![feature(i128)]
#![feature(i128_type)]
#![feature(inclusive_range)]
// Memory reporting
#[cfg(unix)]
fn get_resident() -> Option<usize> {
- use std::fs::File;
- use std::io::Read;
+ use std::fs;
let field = 1;
- let mut f = File::open("/proc/self/statm").ok()?;
- let mut contents = String::new();
- f.read_to_string(&mut contents).ok()?;
+ let contents = fs::read_string("/proc/self/statm").ok()?;
let s = contents.split_whitespace().nth(field)?;
let npages = s.parse::<usize>().ok()?;
Some(npages * 4096)
#![feature(box_syntax)]
#![feature(const_fn)]
+#![feature(fs_read_write)]
extern crate syntax;
extern crate rand;
use serialize::json::{Json, ToJson};
use std::collections::BTreeMap;
use std::default::Default;
-use std::io::prelude::*;
use syntax::abi::{Abi, lookup as lookup_abi};
use {LinkerFlavor, PanicStrategy, RelroLevel};
pub fn search(target: &str) -> Result<Target, String> {
use std::env;
use std::ffi::OsString;
- use std::fs::File;
+ use std::fs;
use std::path::{Path, PathBuf};
use serialize::json;
fn load_file(path: &Path) -> Result<Target, String> {
- let mut f = File::open(path).map_err(|e| e.to_string())?;
- let mut contents = Vec::new();
- f.read_to_end(&mut contents).map_err(|e| e.to_string())?;
+ let contents = fs::read(path).map_err(|e| e.to_string())?;
let obj = json::from_reader(&mut &contents[..])
.map_err(|e| e.to_string())?;
Target::from_json(obj)
use rustc::ich::{ATTR_IF_THIS_CHANGED, ATTR_THEN_THIS_WOULD_NEED};
use graphviz::IntoCow;
use std::env;
-use std::fs::File;
+use std::fs::{self, File};
use std::io::Write;
use syntax::ast;
use syntax_pos::Span;
let dot_path = format!("{}.dot", path);
let mut v = Vec::new();
dot::render(&GraphvizDepGraph(nodes, edges), &mut v).unwrap();
- File::create(&dot_path).and_then(|mut f| f.write_all(&v)).unwrap();
+ fs::write(dot_path, v).unwrap();
}
}
#![deny(warnings)]
#![feature(conservative_impl_trait)]
+#![feature(fs_read_write)]
#![feature(i128_type)]
#![feature(inclusive_range_syntax)]
#![feature(specialization)]
use std::io::{self, Read};
use std::path::Path;
-use std::fs::File;
+use std::fs;
use std::env;
use rustc::session::config::nightly_options;
return Ok(None);
}
- let mut file = File::open(path)?;
- let file_size = file.metadata()?.len() as usize;
-
- let mut data = Vec::with_capacity(file_size);
- file.read_to_end(&mut data)?;
+ let data = fs::read(path)?;
let mut file = io::Cursor::new(data);
use rustc_data_structures::fx::FxHashMap;
use rustc_serialize::Encodable as RustcEncodable;
use rustc_serialize::opaque::Encoder;
-use std::io::{self, Cursor, Write};
-use std::fs::{self, File};
+use std::io::{self, Cursor};
+use std::fs;
use std::path::PathBuf;
use super::data::*;
// write the data out
let data = wr.into_inner();
- match File::create(&path_buf).and_then(|mut file| file.write_all(&data)) {
+ match fs::write(&path_buf, data) {
Ok(_) => {
debug!("save: data written to disk successfully");
}
#![feature(box_patterns)]
#![feature(conservative_impl_trait)]
+#![feature(fs_read_write)]
#![feature(i128_type)]
#![feature(libc)]
#![feature(proc_macro_internals)]
use std::cmp;
use std::fmt;
-use std::fs::{self, File};
+use std::fs;
use std::io::{self, Read};
use std::path::{Path, PathBuf};
use std::time::Instant;
}
}
CrateFlavor::Rmeta => {
- let mut file = File::open(filename).map_err(|_|
- format!("could not open file: '{}'", filename.display()))?;
- let mut buf = vec![];
- file.read_to_end(&mut buf).map_err(|_|
+ let buf = fs::read(filename).map_err(|_|
format!("failed to read rmeta metadata: '{}'", filename.display()))?;
OwningRef::new(buf).map_owner_box().erase_owner()
}
use dot;
use dot::IntoCow;
-use std::fs::File;
+use std::fs;
use std::io;
use std::io::prelude::*;
use std::marker::PhantomData;
dot::render(&g, &mut v)?;
debug!("print_borrowck_graph_to path: {} node_id: {}",
path.display(), mbcx.node_id);
- File::create(path).and_then(|mut f| f.write_all(&v))
+ fs::write(path, v)
}
pub type Node = BasicBlock;
#![feature(core_intrinsics)]
#![feature(decl_macro)]
#![feature(dyn_trait)]
+#![feature(fs_read_write)]
#![feature(i128_type)]
#![feature(inclusive_range_syntax)]
#![feature(inclusive_range)]
fn emit_metadata<'a>(sess: &'a Session, trans: &CrateTranslation, tmpdir: &TempDir)
-> PathBuf {
let out_filename = tmpdir.path().join(METADATA_FILENAME);
- let result = fs::File::create(&out_filename).and_then(|mut f| {
- f.write_all(&trans.metadata.raw_data)
- });
+ let result = fs::write(&out_filename, &trans.metadata.raw_data);
if let Err(e) = result {
sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
use std::any::Any;
use std::ffi::{CString, CStr};
-use std::fs::{self, File};
-use std::io;
-use std::io::{Read, Write};
+use std::fs;
+use std::io::{self, Write};
use std::mem;
use std::path::{Path, PathBuf};
use std::str;
timeline.record("make-bc");
if write_bc {
- if let Err(e) = File::create(&bc_out).and_then(|mut f| f.write_all(data)) {
+ if let Err(e) = fs::write(&bc_out, data) {
diag_handler.err(&format!("failed to write bytecode: {}", e));
}
timeline.record("write-bc");
if config.emit_bc_compressed {
let dst = bc_out.with_extension(RLIB_BYTECODE_EXTENSION);
let data = bytecode::encode(&mtrans.llmod_id, data);
- if let Err(e) = File::create(&dst).and_then(|mut f| f.write_all(&data)) {
+ if let Err(e) = fs::write(&dst, data) {
diag_handler.err(&format!("failed to write bytecode: {}", e));
}
timeline.record("compress-bc");
object: &Path) {
use rustc_binaryen::{Module, ModuleOptions};
- let input = File::open(&assembly).and_then(|mut f| {
- let mut contents = Vec::new();
- f.read_to_end(&mut contents)?;
+ let input = fs::read(&assembly).and_then(|contents| {
Ok(CString::new(contents)?)
});
let mut options = ModuleOptions::new();
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))
});
let err = assembled.and_then(|binary| {
- File::create(&object).and_then(|mut f| f.write_all(binary.data()))
+ fs::write(&object, binary.data())
});
if let Err(e) = err {
handler.err(&format!("failed to run binaryen assembler: {}", e));
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(custom_attribute)]
+#![feature(fs_read_write)]
#![allow(unused_attributes)]
#![feature(i128_type)]
#![feature(i128)]
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::fs::File;
-use std::io::prelude::*;
+use std::fs;
use std::path::Path;
use std::str;
use html::markdown::{Markdown, RenderType};
pub fn load_string<P: AsRef<Path>>(file_path: P) -> Result<String, LoadStringError> {
let file_path = file_path.as_ref();
- let mut contents = vec![];
- let result = File::open(file_path)
- .and_then(|mut f| f.read_to_end(&mut contents));
- if let Err(e) = result {
- eprintln!("error reading `{}`: {}", file_path.display(), e);
- return Err(LoadStringError::ReadFail);
- }
+ let contents = match fs::read(file_path) {
+ Ok(bytes) => bytes,
+ Err(e) => {
+ eprintln!("error reading `{}`: {}", file_path.display(), e);
+ return Err(LoadStringError::ReadFail);
+ }
+ };
match str::from_utf8(&contents) {
Ok(s) => Ok(s.to_string()),
Err(_) => {
write(cx.dst.join("main.css"),
include_bytes!("static/styles/main.css"))?;
if let Some(ref css) = cx.shared.css_file_extension {
- let mut content = String::new();
- let css = css.as_path();
- let mut f = try_err!(File::open(css), css);
-
- try_err!(f.read_to_string(&mut content), css);
- let css = cx.dst.join("theme.css");
- let css = css.as_path();
- let mut f = try_err!(File::create(css), css);
- try_err!(write!(f, "{}", &content), css);
+ let out = cx.dst.join("theme.css");
+ try_err!(fs::copy(css, out), css);
}
write(cx.dst.join("normalize.css"),
include_bytes!("static/normalize.css"))?;
/// Writes the entire contents of a string to a destination, not attempting to
/// catch any errors.
fn write(dst: PathBuf, contents: &[u8]) -> Result<(), Error> {
- Ok(try_err!(try_err!(File::create(&dst), &dst).write_all(contents), &dst))
+ Ok(try_err!(fs::write(&dst, contents), &dst))
}
/// Takes a path to a source file and cleans the path to it. This canonicalizes
return Ok(());
}
- let mut contents = Vec::new();
- File::open(&p).and_then(|mut f| f.read_to_end(&mut contents))?;
-
- let contents = str::from_utf8(&contents).unwrap();
+ let contents = fs::read_string(&p)?;
// Remove the utf-8 BOM if any
let contents = if contents.starts_with("\u{feff}") {
&contents[3..]
} else {
- contents
+ &contents[..]
};
// Create the intermediate directories
#![feature(rustc_private)]
#![feature(box_patterns)]
#![feature(box_syntax)]
+#![feature(fs_read_write)]
#![feature(libc)]
#![feature(set_stdio)]
#![feature(slice_patterns)]