Skip to content

Commit 842fb1c

Browse files
committed
Update serialize after rebasing.
1 parent 6f4e504 commit 842fb1c

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

src/libserialize/json_stage0.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ use std::string;
211211
use std::ops;
212212
use unicode::str as unicode_str;
213213
use unicode::str::Utf16Item;
214+
use std::ops::Index as IndexOp;
214215

215216
use Encodable;
216217

@@ -386,7 +387,7 @@ fn escape_str(wr: &mut fmt::Writer, v: &str) -> fmt::Result {
386387
};
387388

388389
if start < i {
389-
try!(wr.write_str(v[start..i]));
390+
try!(wr.write_str(v.index(&(start..i))));
390391
}
391392

392393
try!(wr.write_str(escaped));
@@ -395,7 +396,7 @@ fn escape_str(wr: &mut fmt::Writer, v: &str) -> fmt::Result {
395396
}
396397

397398
if start != v.len() {
398-
try!(wr.write_str(v[start..]));
399+
try!(wr.write_str(v.index(&(start..))));
399400
}
400401

401402
wr.write_str("\"")
@@ -404,7 +405,7 @@ fn escape_str(wr: &mut fmt::Writer, v: &str) -> fmt::Result {
404405
fn escape_char(writer: &mut fmt::Writer, v: char) -> fmt::Result {
405406
let mut buf = [0; 4];
406407
let n = v.encode_utf8(&mut buf).unwrap();
407-
let buf = unsafe { str::from_utf8_unchecked(buf[0..n]) };
408+
let buf = unsafe { str::from_utf8_unchecked(buf.index(&(0..n))) };
408409
escape_str(writer, buf)
409410
}
410411

@@ -417,7 +418,7 @@ fn spaces(wr: &mut fmt::Writer, mut n: uint) -> fmt::Result {
417418
}
418419

419420
if n > 0 {
420-
wr.write_str(BUF[..n])
421+
wr.write_str(BUF.index(&(..n)))
421422
} else {
422423
Ok(())
423424
}
@@ -624,7 +625,7 @@ impl<'a> ::Encoder<fmt::Error> for Encoder<'a> {
624625
let mut check_encoder = Encoder::new(&mut buf);
625626
try!(f(transmute(&mut check_encoder)));
626627
}
627-
let out = str::from_utf8(buf[]).unwrap();
628+
let out = str::from_utf8(buf.index(&FullRange)).unwrap();
628629
let needs_wrapping = out.char_at(0) != '"' && out.char_at_reverse(out.len()) != '"';
629630
if needs_wrapping { try!(write!(self.writer, "\"")); }
630631
try!(f(self));
@@ -893,7 +894,7 @@ impl<'a> ::Encoder<fmt::Error> for PrettyEncoder<'a> {
893894
let mut check_encoder = PrettyEncoder::new(&mut buf);
894895
try!(f(transmute(&mut check_encoder)));
895896
}
896-
let out = str::from_utf8(buf[]).unwrap();
897+
let out = str::from_utf8(buf.index(&FullRange)).unwrap();
897898
let needs_wrapping = out.char_at(0) != '"' && out.char_at_reverse(out.len()) != '"';
898899
if needs_wrapping { try!(write!(self.writer, "\"")); }
899900
try!(f(self));
@@ -1026,7 +1027,7 @@ impl Json {
10261027
/// Returns None otherwise.
10271028
pub fn as_string<'a>(&'a self) -> Option<&'a str> {
10281029
match *self {
1029-
Json::String(ref s) => Some(s[]),
1030+
Json::String(ref s) => Some(s.index(&FullRange)),
10301031
_ => None
10311032
}
10321033
}
@@ -1241,7 +1242,8 @@ impl Stack {
12411242
InternalIndex(i) => Index(i),
12421243
InternalKey(start, size) => {
12431244
Key(str::from_utf8(
1244-
self.str_buffer[start as uint .. start as uint + size as uint]).unwrap())
1245+
self.str_buffer.index(
1246+
&((start as uint) .. (start as uint + size as uint)))).unwrap())
12451247
}
12461248
}
12471249
}
@@ -1283,7 +1285,7 @@ impl Stack {
12831285
Some(&InternalIndex(i)) => Some(Index(i)),
12841286
Some(&InternalKey(start, size)) => {
12851287
Some(Key(str::from_utf8(
1286-
self.str_buffer[start as uint .. (start+size) as uint]
1288+
self.str_buffer.index(&(start as uint) .. ((start+size) as uint))
12871289
).unwrap()))
12881290
}
12891291
}
@@ -2160,7 +2162,7 @@ impl ::Decoder<DecoderError> for Decoder {
21602162
return Err(ExpectedError("String or Object".to_string(), format!("{}", json)))
21612163
}
21622164
};
2163-
let idx = match names.iter().position(|n| *n == name[]) {
2165+
let idx = match names.iter().position(|n| *n == name.index(&FullRange)) {
21642166
Some(idx) => idx,
21652167
None => return Err(UnknownVariantError(name))
21662168
};
@@ -3373,7 +3375,7 @@ mod tests {
33733375
hm.insert(1, true);
33743376
let mut mem_buf = Vec::new();
33753377
write!(&mut mem_buf, "{}", super::as_pretty_json(&hm)).unwrap();
3376-
let json_str = from_utf8(mem_buf[]).unwrap();
3378+
let json_str = from_utf8(&mem_buf.index(&FullRange)).unwrap();
33773379
match from_str(json_str) {
33783380
Err(_) => panic!("Unable to parse json_str: {}", json_str),
33793381
_ => {} // it parsed and we are good to go
@@ -3389,7 +3391,7 @@ mod tests {
33893391
hm.insert(1, true);
33903392
let mut mem_buf = Vec::new();
33913393
write!(&mut mem_buf, "{}", super::as_pretty_json(&hm)).unwrap();
3392-
let json_str = from_utf8(mem_buf[]).unwrap();
3394+
let json_str = from_utf8(&mem_buf.index(&FullRange)).unwrap();
33933395
match from_str(json_str) {
33943396
Err(_) => panic!("Unable to parse json_str: {}", json_str),
33953397
_ => {} // it parsed and we are good to go
@@ -3429,7 +3431,7 @@ mod tests {
34293431
write!(&mut writer, "{}",
34303432
super::as_pretty_json(&json).indent(i)).unwrap();
34313433

3432-
let printed = from_utf8(writer[]).unwrap();
3434+
let printed = from_utf8(&writer.index(&FullRange)).unwrap();
34333435

34343436
// Check for indents at each line
34353437
let lines: Vec<&str> = printed.lines().collect();

src/libserialize/serialize_stage0.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Core encoding and decoding interfaces.
1515
*/
1616

17+
use std::ops::FullRange;
1718
use std::path;
1819
use std::rc::Rc;
1920
use std::cell::{Cell, RefCell};
@@ -308,7 +309,7 @@ impl<E, S:Encoder<E>> Encodable<S, E> for str {
308309

309310
impl<E, S:Encoder<E>> Encodable<S, E> for String {
310311
fn encode(&self, s: &mut S) -> Result<(), E> {
311-
s.emit_str(self[])
312+
s.emit_str(self.index(&FullRange))
312313
}
313314
}
314315

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<D: Decoder<E>, E> Decodable<D, E> for Ident {
206206
#[cfg(not(stage0))]
207207
impl Decodable for Ident {
208208
fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
209-
Ok(str_to_ident(try!(d.read_str())[]))
209+
Ok(str_to_ident(try!(d.read_str()).index(&FullRange)))
210210
}
211211
}
212212

src/libsyntax/parse/token.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,7 @@ impl<D:Decoder<E>, E> Decodable<D, E> for InternedString {
664664
#[cfg(not(stage0))]
665665
impl Decodable for InternedString {
666666
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
667-
Ok(get_name(get_ident_interner().intern(
668-
try!(d.read_str())[])))
667+
Ok(get_name(get_ident_interner().intern(try!(d.read_str()).index(&FullRange))))
669668
}
670669
}
671670

@@ -679,7 +678,7 @@ impl<S:Encoder<E>, E> Encodable<S, E> for InternedString {
679678
#[cfg(not(stage0))]
680679
impl Encodable for InternedString {
681680
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
682-
s.emit_str(self.string[])
681+
s.emit_str(self.string.index(&FullRange))
683682
}
684683
}
685684

0 commit comments

Comments
 (0)