Skip to content

Commit 02312cb

Browse files
committed
Remove usage of some unstable features.
1 parent 744e411 commit 02312cb

File tree

8 files changed

+22
-23
lines changed

8 files changed

+22
-23
lines changed

macros/src/named_entities.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct CharRef {
3333
}
3434

3535
// Build the map from entity names (and their prefixes) to characters.
36-
fn build_map(js: Json) -> Option<HashMap<String, [u32; 2]>> {
36+
fn build_map(js: Json) -> Option<HashMap<String, (u32, u32)>> {
3737
let mut map = HashMap::new();
3838
let json_map = match js {
3939
Json::Object(m) => m,
@@ -47,24 +47,23 @@ fn build_map(js: Json) -> Option<HashMap<String, [u32; 2]>> {
4747
= Decodable::decode(&mut decoder).ok().expect("bad CharRef");
4848

4949
assert!((codepoints.len() >= 1) && (codepoints.len() <= 2));
50-
let mut codepoint_pair = [0, 0];
51-
for (i,n) in codepoints.into_iter().enumerate() {
52-
codepoint_pair[i] = n;
53-
}
50+
let mut codepoints = codepoints.into_iter();
51+
let codepoint_pair = (codepoints.next().unwrap(), codepoints.next().unwrap_or(0));
52+
assert!(codepoints.next().is_none());
5453

5554
// Slice off the initial '&'
5655
assert!(k.chars().next() == Some('&'));
5756
map.insert(k[1..].to_string(), codepoint_pair);
5857
}
5958

6059
// Add every missing prefix of those keys, mapping to NULL characters.
61-
map.insert("".to_string(), [0, 0]);
60+
map.insert("".to_string(), (0, 0));
6261
let keys: Vec<String> = map.keys().map(|k| k.to_string()).collect();
6362
for k in keys.into_iter() {
6463
for n in 1 .. k.len() {
6564
let pfx = k[..n].to_string();
6665
if !map.contains_key(&pfx) {
67-
map.insert(pfx, [0, 0]);
66+
map.insert(pfx, (0, 0));
6867
}
6968
}
7069
}
@@ -111,9 +110,9 @@ pub fn expand(cx: &mut ExtCtxt, sp: Span, tt: &[TokenTree]) -> Box<MacResult+'st
111110
// Emit a macro invocation of the form
112111
//
113112
// phf_map!(k => v, k => v, ...)
114-
let toks: Vec<_> = map.into_iter().flat_map(|(k, [c0, c1])| {
113+
let toks: Vec<_> = map.into_iter().flat_map(|(k, (c0, c1))| {
115114
let k = &k[..];
116-
(quote_tokens!(&mut *cx, $k => [$c0, $c1],)).into_iter()
115+
(quote_tokens!(&mut *cx, $k => ($c0, $c1),)).into_iter()
117116
}).collect();
118117
MacEager::expr(quote_expr!(&mut *cx, phf_map!($toks)))
119118
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#![crate_name="html5ever"]
1111
#![crate_type="dylib"]
1212

13-
#![feature(plugin, box_syntax, str_char, slice_patterns, iter_arith, str_escape)]
13+
#![feature(plugin)]
1414
#![cfg_attr(test, deny(warnings))]
1515
#![allow(unused_parens)]
1616

src/tokenizer/buffer_queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl BufferQueue {
5757
/// Look at the next available character, if any.
5858
pub fn peek(&mut self) -> Option<char> {
5959
// Invariant: all buffers in the queue are non-empty.
60-
self.buffers.front().map(|b| b.char_at(0))
60+
self.buffers.front().map(|b| b.chars().next().unwrap())
6161
}
6262

6363
/// Get the next character, if one is available.

src/tokenizer/char_ref/data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ pub static C1_REPLACEMENTS: [Option<char>; 32] = [
2424
];
2525

2626
// The named_entities! macro is defined in html5/macros/named_entities.rs.
27-
pub static NAMED_ENTITIES: Map<&'static str, [u32; 2]>
27+
pub static NAMED_ENTITIES: Map<&'static str, (u32, u32)>
2828
= named_entities!("../../../data/entities.json");

src/tokenizer/char_ref/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct CharRefTokenizer {
5757
hex_marker: Option<char>,
5858

5959
name_buf_opt: Option<StrTendril>,
60-
name_match: Option<&'static [u32; 2]>,
60+
name_match: Option<(u32, u32)>,
6161
name_len: usize,
6262
}
6363

@@ -250,8 +250,8 @@ impl CharRefTokenizer {
250250
self.name_buf_mut().push_char(c);
251251
match data::NAMED_ENTITIES.get(&self.name_buf()[..]) {
252252
// We have either a full match or a prefix of one.
253-
Some(m) => {
254-
if m[0] != 0 {
253+
Some(&m) => {
254+
if m.0 != 0 {
255255
// We have a full match, but there might be a longer one to come.
256256
self.name_match = Some(m);
257257
self.name_len = self.name_buf().len();
@@ -299,7 +299,7 @@ impl CharRefTokenizer {
299299
self.finish_none()
300300
}
301301

302-
Some(&[c1, c2]) => {
302+
Some((c1, c2)) => {
303303
// We have a complete match, but we may have consumed
304304
// additional characters into self.name_buf. Usually
305305
// at least one, but several in cases like
@@ -310,14 +310,14 @@ impl CharRefTokenizer {
310310

311311
let name_len = self.name_len;
312312
assert!(name_len > 0);
313-
let last_matched = self.name_buf().char_at(name_len-1);
313+
let last_matched = self.name_buf()[name_len-1..].chars().next().unwrap();
314314

315315
// There might not be a next character after the match, if
316316
// we had a full match and then hit EOF.
317317
let next_after = if name_len == self.name_buf().len() {
318318
None
319319
} else {
320-
Some(self.name_buf().char_at(name_len))
320+
Some(self.name_buf()[name_len..].chars().next().unwrap())
321321
};
322322

323323
// "If the character reference is being consumed as part of an

src/tokenizer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> {
213213
return;
214214
}
215215

216-
if self.discard_bom && input.char_at(0) == '\u{feff}' {
216+
if self.discard_bom && input.starts_with("\u{feff}") {
217217
input.pop_front(3);
218218
};
219219

@@ -488,7 +488,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> {
488488
fn consume_char_ref(&mut self, addnl_allowed: Option<char>) {
489489
// NB: The char ref tokenizer assumes we have an additional allowed
490490
// character iff we're tokenizing in an attribute value.
491-
self.char_ref_tokenizer = Some(box CharRefTokenizer::new(addnl_allowed));
491+
self.char_ref_tokenizer = Some(Box::new(CharRefTokenizer::new(addnl_allowed)));
492492
}
493493

494494
fn emit_eof(&mut self) {
@@ -1235,7 +1235,7 @@ impl<Sink: TokenSink> Tokenizer<Sink> {
12351235
= self.state_profile.iter().map(|(s, t)| (*s, *t)).collect();
12361236
results.sort_by(|&(_, x), &(_, y)| y.cmp(&x));
12371237

1238-
let total: u64 = results.iter().map(|&(_, t)| t).sum();
1238+
let total: u64 = results.iter().map(|&(_, t)| t).fold(0, ::std::ops::Add::add);
12391239
println!("\nTokenizer profile, in nanoseconds");
12401240
println!("\n{:12} total in token sink", self.time_in_sink);
12411241
println!("\n{:12} total in tokenizer", total);

src/tree_builder/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl<Handle, Sink> TokenSink
415415
tokenizer::EOFToken => EOFToken,
416416

417417
tokenizer::CharacterTokens(mut x) => {
418-
if !x.is_empty() && ignore_lf && x.char_at(0) == '\n' {
418+
if ignore_lf && x.starts_with("\n") {
419419
x.pop_front(1);
420420
}
421421
if x.is_empty() {

src/util/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn to_escaped_string<T: fmt::Debug>(x: &T) -> String {
1616
let mut buf = String::new();
1717
let _ = buf.write_fmt(format_args!("{:?}", x));
1818
buf.shrink_to_fit();
19-
buf.escape_default()
19+
buf.chars().flat_map(|c| c.escape_default()).collect()
2020
}
2121

2222
/// If `c` is an ASCII letter, return the corresponding lowercase

0 commit comments

Comments
 (0)