Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

Sync with rust HEAD (525aa610) #42

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions syntex_syntax/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Encodable for Name {

impl Decodable for Name {
fn decode<D: Decoder>(d: &mut D) -> Result<Name, D::Error> {
Ok(token::intern(&try!(d.read_str())[..]))
Ok(token::intern(&d.read_str()?[..]))
}
}

Expand Down Expand Up @@ -152,7 +152,7 @@ impl Encodable for Ident {

impl Decodable for Ident {
fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
Ok(Ident::with_empty_ctxt(try!(Name::decode(d))))
Ok(Ident::with_empty_ctxt(Name::decode(d)?))
}
}

Expand Down
3 changes: 1 addition & 2 deletions syntex_syntax/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ pub fn mark_used(attr: &Attribute) {
let idx = (id / 64) as usize;
let shift = id % 64;
if slot.borrow().len() <= idx {
let len = slot.borrow().len();
slot.borrow_mut().extend((0 .. (idx + 1 - len)).map(|_| 0));
slot.borrow_mut().resize(idx + 1, 0);
}
slot.borrow_mut()[idx] |= 1 << shift;
});
Expand Down
74 changes: 36 additions & 38 deletions syntex_syntax/src/codemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Encodable for BytePos {

impl Decodable for BytePos {
fn decode<D: Decoder>(d: &mut D) -> Result<BytePos, D::Error> {
Ok(BytePos(try!(d.read_u32())))
Ok(BytePos(d.read_u32()?))
}
}

Expand Down Expand Up @@ -203,9 +203,9 @@ pub struct Spanned<T> {
impl Encodable for Span {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_struct("Span", 2, |s| {
try!(s.emit_struct_field("lo", 0, |s| {
s.emit_struct_field("lo", 0, |s| {
self.lo.encode(s)
}));
})?;

s.emit_struct_field("hi", 1, |s| {
self.hi.encode(s)
Expand All @@ -217,13 +217,13 @@ impl Encodable for Span {
impl Decodable for Span {
fn decode<D: Decoder>(d: &mut D) -> Result<Span, D::Error> {
d.read_struct("Span", 2, |d| {
let lo = try!(d.read_struct_field("lo", 0, |d| {
let lo = d.read_struct_field("lo", 0, |d| {
BytePos::decode(d)
}));
})?;

let hi = try!(d.read_struct_field("hi", 1, |d| {
let hi = d.read_struct_field("hi", 1, |d| {
BytePos::decode(d)
}));
})?;

Ok(mk_sp(lo, hi))
})
Expand Down Expand Up @@ -526,13 +526,13 @@ pub struct FileMap {
impl Encodable for FileMap {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
s.emit_struct("FileMap", 5, |s| {
try!(s.emit_struct_field("name", 0, |s| self.name.encode(s)));
try!(s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s)));
try!(s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s)));
try!(s.emit_struct_field("lines", 3, |s| {
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
s.emit_struct_field("start_pos", 1, |s| self.start_pos.encode(s))?;
s.emit_struct_field("end_pos", 2, |s| self.end_pos.encode(s))?;
s.emit_struct_field("lines", 3, |s| {
let lines = self.lines.borrow();
// store the length
try!(s.emit_u32(lines.len() as u32));
s.emit_u32(lines.len() as u32)?;

if !lines.is_empty() {
// In order to preserve some space, we exploit the fact that
Expand All @@ -557,24 +557,24 @@ impl Encodable for FileMap {
};

// Encode the number of bytes used per diff.
try!(bytes_per_diff.encode(s));
bytes_per_diff.encode(s)?;

// Encode the first element.
try!(lines[0].encode(s));
lines[0].encode(s)?;

let diff_iter = (&lines[..]).windows(2)
.map(|w| (w[1] - w[0]));

match bytes_per_diff {
1 => for diff in diff_iter { try!((diff.0 as u8).encode(s)) },
2 => for diff in diff_iter { try!((diff.0 as u16).encode(s)) },
4 => for diff in diff_iter { try!(diff.0.encode(s)) },
1 => for diff in diff_iter { (diff.0 as u8).encode(s)? },
2 => for diff in diff_iter { (diff.0 as u16).encode(s)? },
4 => for diff in diff_iter { diff.0.encode(s)? },
_ => unreachable!()
}
}

Ok(())
}));
})?;
s.emit_struct_field("multibyte_chars", 4, |s| {
(*self.multibyte_chars.borrow()).encode(s)
})
Expand All @@ -586,26 +586,26 @@ impl Decodable for FileMap {
fn decode<D: Decoder>(d: &mut D) -> Result<FileMap, D::Error> {

d.read_struct("FileMap", 5, |d| {
let name: String = try!(d.read_struct_field("name", 0, |d| Decodable::decode(d)));
let start_pos: BytePos = try!(d.read_struct_field("start_pos", 1, |d| Decodable::decode(d)));
let end_pos: BytePos = try!(d.read_struct_field("end_pos", 2, |d| Decodable::decode(d)));
let lines: Vec<BytePos> = try!(d.read_struct_field("lines", 3, |d| {
let num_lines: u32 = try!(Decodable::decode(d));
let name: String = d.read_struct_field("name", 0, |d| Decodable::decode(d))?;
let start_pos: BytePos = d.read_struct_field("start_pos", 1, |d| Decodable::decode(d))?;
let end_pos: BytePos = d.read_struct_field("end_pos", 2, |d| Decodable::decode(d))?;
let lines: Vec<BytePos> = d.read_struct_field("lines", 3, |d| {
let num_lines: u32 = Decodable::decode(d)?;
let mut lines = Vec::with_capacity(num_lines as usize);

if num_lines > 0 {
// Read the number of bytes used per diff.
let bytes_per_diff: u8 = try!(Decodable::decode(d));
let bytes_per_diff: u8 = Decodable::decode(d)?;

// Read the first element.
let mut line_start: BytePos = try!(Decodable::decode(d));
let mut line_start: BytePos = Decodable::decode(d)?;
lines.push(line_start);

for _ in 1..num_lines {
let diff = match bytes_per_diff {
1 => try!(d.read_u8()) as u32,
2 => try!(d.read_u16()) as u32,
4 => try!(d.read_u32()),
1 => d.read_u8()? as u32,
2 => d.read_u16()? as u32,
4 => d.read_u32()?,
_ => unreachable!()
};

Expand All @@ -616,9 +616,9 @@ impl Decodable for FileMap {
}

Ok(lines)
}));
})?;
let multibyte_chars: Vec<MultiByteChar> =
try!(d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d)));
d.read_struct_field("multibyte_chars", 4, |d| Decodable::decode(d))?;
Ok(FileMap {
name: name,
start_pos: start_pos,
Expand Down Expand Up @@ -720,7 +720,7 @@ impl FileLoader for RealFileLoader {

fn read_file(&self, path: &Path) -> io::Result<String> {
let mut src = String::new();
try!(try!(fs::File::open(path)).read_to_string(&mut src));
fs::File::open(path)?.read_to_string(&mut src)?;
Ok(src)
}
}
Expand Down Expand Up @@ -757,7 +757,7 @@ impl CodeMap {
}

pub fn load_file(&self, path: &Path) -> io::Result<Rc<FileMap>> {
let src = try!(self.file_loader.read_file(path));
let src = self.file_loader.read_file(path)?;
Ok(self.new_filemap(path.to_str().unwrap().to_string(), src))
}

Expand All @@ -773,16 +773,14 @@ impl CodeMap {

/// Creates a new filemap without setting its line information. If you don't
/// intend to set the line information yourself, you should use new_filemap_and_lines.
pub fn new_filemap(&self, filename: FileName, src: String) -> Rc<FileMap> {
pub fn new_filemap(&self, filename: FileName, mut src: String) -> Rc<FileMap> {
let start_pos = self.next_start_pos();
let mut files = self.files.borrow_mut();

// Remove utf-8 BOM if any.
let src = if src.starts_with("\u{feff}") {
String::from(&src[3..])
} else {
src
};
if src.starts_with("\u{feff}") {
src.drain(..3);
}

let end_pos = start_pos + src.len();

Expand Down
8 changes: 4 additions & 4 deletions syntex_syntax/src/diagnostics/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorM
{
// Create the directory to place the file in.
let metadata_dir = get_metadata_dir(prefix);
try!(create_dir_all(&metadata_dir));
create_dir_all(&metadata_dir)?;

// Open the metadata file.
let metadata_path = get_metadata_path(metadata_dir, name);
let mut metadata_file = try!(File::create(&metadata_path));
let mut metadata_file = File::create(&metadata_path)?;

// Construct a serializable map.
let json_map = err_map.iter().map(|(k, &ErrorInfo { description, use_site })| {
Expand All @@ -95,7 +95,7 @@ pub fn output_metadata(ecx: &ExtCtxt, prefix: &str, name: &str, err_map: &ErrorM
// Write the data to the file, deleting it if the write fails.
let result = write!(&mut metadata_file, "{}", as_json(&json_map));
if result.is_err() {
try!(remove_file(&metadata_path));
remove_file(&metadata_path)?;
}
result.map_err(|e| e.into())
Ok(result?)
}
Loading