diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 28 |
3 files changed, 38 insertions, 26 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 3ad1d96a45d..fb9e0480ceb 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -19,9 +19,8 @@ use parse::lexer::is_block_doc_comment; use parse::lexer; use print::pprust; -use std::old_io; +use std::io::Read; use std::str; -use std::string::String; use std::usize; #[derive(Clone, Copy, PartialEq)] @@ -337,9 +336,10 @@ pub struct Literal { // probably not a good thing. pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler, path: String, - srdr: &mut old_io::Reader) + srdr: &mut Read) -> (Vec<Comment>, Vec<Literal>) { - let src = srdr.read_to_end().unwrap(); + let mut src = Vec::new(); + srdr.read_to_end(&mut src).unwrap(); let src = String::from_utf8(src).unwrap(); let cm = CodeMap::new(); let filemap = cm.new_filemap(path, src); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 66589d5e3d1..def5963e6f4 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -18,11 +18,13 @@ use parse::parser::Parser; use ptr::P; use std::cell::{Cell, RefCell}; -use std::old_io::File; -use std::rc::Rc; +use std::fs::File; +use std::io::Read; +use std::iter; use std::num::Int; +use std::path::{Path, PathBuf}; +use std::rc::Rc; use std::str; -use std::iter; #[macro_use] pub mod parser; @@ -39,7 +41,7 @@ pub mod obsolete; pub struct ParseSess { pub span_diagnostic: SpanHandler, // better be the same as the one in the reader! /// Used to determine and report recursive mod inclusions - included_mod_stack: RefCell<Vec<Path>>, + included_mod_stack: RefCell<Vec<PathBuf>>, pub node_id: Cell<ast::NodeId>, } @@ -250,24 +252,24 @@ pub fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>) None => sess.span_diagnostic.handler().fatal(msg), } }; - let bytes = match File::open(path).read_to_end() { - Ok(bytes) => bytes, + let mut bytes = Vec::new(); + match File::open(path).and_then(|mut f| f.read_to_end(&mut bytes)) { + Ok(..) => {} Err(e) => { - err(&format!("couldn't read {:?}: {}", - path.display(), e)); - unreachable!() + err(&format!("couldn't read {:?}: {}", path.display(), e)); + unreachable!(); } }; match str::from_utf8(&bytes[..]).ok() { Some(s) => { - return string_to_filemap(sess, s.to_string(), - path.as_str().unwrap().to_string()) + string_to_filemap(sess, s.to_string(), + path.to_str().unwrap().to_string()) } None => { - err(&format!("{:?} is not UTF-8 encoded", path.display())) + err(&format!("{:?} is not UTF-8 encoded", path.display())); + unreachable!(); } } - unreachable!() } /// Given a session and a string, add the string to diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c1acee57cf8..88df6d6d4cd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -78,10 +78,11 @@ use ptr::P; use owned_slice::OwnedSlice; use std::collections::HashSet; -use std::old_io::fs::PathExtensions; +use std::io::prelude::*; use std::iter; use std::mem; use std::num::Float; +use std::path::{Path, PathBuf}; use std::rc::Rc; use std::slice; @@ -5248,14 +5249,23 @@ impl<'a> Parser<'a> { outer_attrs: &[ast::Attribute], id_sp: Span) -> (ast::Item_, Vec<ast::Attribute> ) { - let mut prefix = Path::new(self.sess.span_diagnostic.cm.span_to_filename(self.span)); - prefix.pop(); - let mod_path = Path::new(".").join_many(&self.mod_path_stack); - let dir_path = prefix.join(&mod_path); + let mut prefix = PathBuf::new(&self.sess.span_diagnostic.cm + .span_to_filename(self.span)); + // FIXME(acrichto): right now "a".pop() == "a", but need to confirm with + // aturon whether this is expected or not. + if prefix.parent().is_some() { + prefix.pop(); + } else { + prefix = PathBuf::new(""); + } + let mut dir_path = prefix; + for part in &self.mod_path_stack { + dir_path.push(&**part); + } let mod_string = token::get_ident(id); let (file_path, owns_directory) = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { - Some(d) => (dir_path.join(d), true), + Some(d) => (dir_path.join(&*d), true), None => { let mod_name = mod_string.to_string(); let default_path_str = format!("{}.rs", mod_name); @@ -5319,7 +5329,7 @@ impl<'a> Parser<'a> { } fn eval_src_mod_from_path(&mut self, - path: Path, + path: PathBuf, owns_directory: bool, name: String, id_sp: Span) -> (ast::Item_, Vec<ast::Attribute> ) { @@ -5329,10 +5339,10 @@ impl<'a> Parser<'a> { let mut err = String::from_str("circular modules: "); let len = included_mod_stack.len(); for p in &included_mod_stack[i.. len] { - err.push_str(&p.display().as_cow()); + err.push_str(&p.to_string_lossy()); err.push_str(" -> "); } - err.push_str(&path.display().as_cow()); + err.push_str(&path.to_string_lossy()); self.span_fatal(id_sp, &err[..]); } None => () |
