Skip to content

Commit b359bf1

Browse files
committed
Upgrade to latest Rust.
1 parent 6e3fbbe commit b359bf1

File tree

6 files changed

+71
-72
lines changed

6 files changed

+71
-72
lines changed

ast.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,23 @@ impl ToStr for SyntaxError {
126126
}
127127

128128

129-
pub trait SkipWhitespaceIterable<'self> {
130-
fn skip_whitespace(self) -> SkipWhitespaceIterator<'self>;
129+
pub trait SkipWhitespaceIterable<'a> {
130+
fn skip_whitespace(self) -> SkipWhitespaceIterator<'a>;
131131
}
132132

133-
impl<'self> SkipWhitespaceIterable<'self> for &'self [ComponentValue] {
134-
fn skip_whitespace(self) -> SkipWhitespaceIterator<'self> {
133+
impl<'a> SkipWhitespaceIterable<'a> for &'a [ComponentValue] {
134+
fn skip_whitespace(self) -> SkipWhitespaceIterator<'a> {
135135
SkipWhitespaceIterator{ iter_with_whitespace: self.iter() }
136136
}
137137
}
138138

139139
#[deriving(Clone)]
140-
pub struct SkipWhitespaceIterator<'self> {
141-
iter_with_whitespace: vec::VecIterator<'self, ComponentValue>,
140+
pub struct SkipWhitespaceIterator<'a> {
141+
iter_with_whitespace: vec::VecIterator<'a, ComponentValue>,
142142
}
143143

144-
impl<'self> Iterator<&'self ComponentValue> for SkipWhitespaceIterator<'self> {
145-
fn next(&mut self) -> Option<&'self ComponentValue> {
144+
impl<'a> Iterator<&'a ComponentValue> for SkipWhitespaceIterator<'a> {
145+
fn next(&mut self) -> Option<&'a ComponentValue> {
146146
for component_value in self.iter_with_whitespace {
147147
if component_value != &WhiteSpace { return Some(component_value) }
148148
}

lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
#[link(name = "cssparser", vers = "0.1")];
6-
5+
#[crate_id = "github.com/mozilla-servo/rust-cssparser#cssparser:0.1"];
76
#[feature(globs, macro_rules)];
87

98
extern mod extra;

nth.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub fn parse_nth(input: &[ComponentValue]) -> Option<(i32, i32)> {
7070

7171

7272
type Nth = Option<(i32, i32)>;
73-
type Iter<'self> = SkipWhitespaceIterator<'self>;
73+
type Iter<'a> = SkipWhitespaceIterator<'a>;
7474

7575
fn parse_b(iter: &mut Iter, a: i32) -> Nth {
7676
match iter.next() {
@@ -105,7 +105,7 @@ fn parse_end(iter: &mut Iter, a: i32, b: i32) -> Nth {
105105
fn parse_n_dash_digits(string: &str) -> Option<i32> {
106106
if string.len() >= 3
107107
&& string.starts_with("n-")
108-
&& string.slice_from(2).iter().all(|c| match c { '0'..'9' => true, _ => false })
108+
&& string.slice_from(2).chars().all(|c| match c { '0'..'9' => true, _ => false })
109109
{
110110
let result = from_str(string.slice_from(1)); // Include the minus sign
111111
assert!(result.is_some());

serializer.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl ast::ComponentValue {
2222
},
2323
Hash(ref value) => {
2424
css.push_char('#');
25-
for c in value.iter() {
25+
for c in value.chars() {
2626
serialize_char(c, css, /* is_identifier_start = */ false);
2727
}
2828
},
@@ -49,7 +49,7 @@ impl ast::ComponentValue {
4949
let unit = unit.as_slice();
5050
if unit == "e" || unit == "E" || unit.starts_with("e-") || unit.starts_with("E-") {
5151
css.push_str("\\65 ");
52-
for c in unit.slice_from(1).iter() {
52+
for c in unit.slice_from(1).chars() {
5353
serialize_char(c, css, /* is_identifier_start = */ false);
5454
}
5555
} else {
@@ -111,7 +111,7 @@ impl ast::ComponentValue {
111111

112112
pub fn serialize_identifier(value: &str, css: &mut ~str) {
113113
// TODO: avoid decoding/re-encoding UTF-8?
114-
let mut iter = value.iter();
114+
let mut iter = value.chars();
115115
let mut c = iter.next().unwrap();
116116
if c == '-' {
117117
c = match iter.next() {
@@ -144,7 +144,7 @@ fn serialize_char(c: char, css: &mut ~str, is_identifier_start: bool) {
144144
pub fn serialize_string(value: &str, css: &mut ~str) {
145145
css.push_char('"');
146146
// TODO: avoid decoding/re-encoding UTF-8?
147-
for c in value.iter() {
147+
for c in value.chars() {
148148
match c {
149149
'"' => css.push_str("\\\""),
150150
'\\' => css.push_str("\\\\"),
@@ -169,7 +169,7 @@ pub trait ToCss {
169169
}
170170

171171

172-
impl<'self, I: Iterator<&'self ComponentValue>> ToCss for I {
172+
impl<'a, I: Iterator<&'a ComponentValue>> ToCss for I {
173173
fn to_css_push(&mut self, css: &mut ~str) {
174174
let mut previous = match self.next() {
175175
None => return,
@@ -184,29 +184,29 @@ impl<'self, I: Iterator<&'self ComponentValue>> ToCss for I {
184184
loop { match self.next() { None => break, Some(component_value) => {
185185
let (a, b) = (previous, component_value);
186186
if (
187-
matches!(*a, Ident(*) | AtKeyword(*) | Hash(*) | IDHash(*) |
188-
Dimension(*) | Delim('#') | Delim('-') | Number(*)) &&
189-
matches!(*b, Ident(*) | Function(*) | URL(*) | BadURL(*) |
190-
Number(*) | Percentage(*) | Dimension(*) | UnicodeRange(*))
187+
matches!(*a, Ident(..) | AtKeyword(..) | Hash(..) | IDHash(..) |
188+
Dimension(..) | Delim('#') | Delim('-') | Number(..)) &&
189+
matches!(*b, Ident(..) | Function(..) | URL(..) | BadURL(..) |
190+
Number(..) | Percentage(..) | Dimension(..) | UnicodeRange(..))
191191
) || (
192-
matches!(*a, Ident(*)) &&
193-
matches!(*b, ParenthesisBlock(*))
192+
matches!(*a, Ident(..)) &&
193+
matches!(*b, ParenthesisBlock(..))
194194
) || (
195-
matches!(*a, Ident(*) | AtKeyword(*) | Hash(*) | IDHash(*) | Dimension(*)) &&
195+
matches!(*a, Ident(..) | AtKeyword(..) | Hash(..) | IDHash(..) | Dimension(..)) &&
196196
matches!(*b, Delim('-') | CDC)
197197
) || (
198-
matches!(*a, Delim('#') | Delim('-') | Number(*) | Delim('@')) &&
199-
matches!(*b, Ident(*) | Function(*) | URL(*) | BadURL(*))
198+
matches!(*a, Delim('#') | Delim('-') | Number(..) | Delim('@')) &&
199+
matches!(*b, Ident(..) | Function(..) | URL(..) | BadURL(..))
200200
) || (
201201
matches!(*a, Delim('@')) &&
202-
matches!(*b, Ident(*) | Function(*) | URL(*) | BadURL(*) |
203-
UnicodeRange(*) | Delim('-'))
202+
matches!(*b, Ident(..) | Function(..) | URL(..) | BadURL(..) |
203+
UnicodeRange(..) | Delim('-'))
204204
) || (
205-
matches!(*a, UnicodeRange(*) | Delim('.') | Delim('+')) &&
206-
matches!(*b, Number(*) | Percentage(*) | Dimension(*))
205+
matches!(*a, UnicodeRange(..) | Delim('.') | Delim('+')) &&
206+
matches!(*b, Number(..) | Percentage(..) | Dimension(..))
207207
) || (
208-
matches!(*a, UnicodeRange(*)) &&
209-
matches!(*b, Ident(*) | Function(*) | Delim('?'))
208+
matches!(*a, UnicodeRange(..)) &&
209+
matches!(*b, Ident(..) | Function(..) | Delim('?'))
210210
) || (match (a, b) { (&Delim(a), &Delim(b)) => matches!((a, b),
211211
('#', '-') |
212212
('$', '=') |

tests.rs

+38-38
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use std::{str, run, task};
6-
use std::rt::io;
7-
use std::rt::io::Writer;
6+
use std::io;
7+
use std::io::{File, Writer};
88
use extra::{tempfile, json};
99
use extra::json::ToJson;
1010
use extra::test;
@@ -16,7 +16,7 @@ use ast::*;
1616

1717

1818
fn write_whole_file(path: &Path, data: &str) {
19-
match io::file::open(path, io::Create, io::Write) {
19+
match File::open_mode(path, io::Open, io::Write) {
2020
Some(mut writer) => writer.write(data.as_bytes()),
2121
None => fail!("could not open file"),
2222
}
@@ -42,7 +42,7 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) {
4242
let temp = tempfile::TempDir::new("rust-cssparser-tests").unwrap();
4343
let results = results.to_pretty_str() + "\n";
4444
let expected = expected.to_pretty_str() + "\n";
45-
do task::try {
45+
task::try(proc() {
4646
let mut result_path = temp.path().clone();
4747
result_path.push("results.json");
4848
let mut expected_path = temp.path().clone();
@@ -51,14 +51,14 @@ fn assert_json_eq(results: json::Json, expected: json::Json, message: ~str) {
5151
write_whole_file(&expected_path, expected);
5252
run::process_status("colordiff", [~"-u1000", result_path.display().to_str(),
5353
expected_path.display().to_str()]);
54-
};
54+
});
5555
5656
fail!(message)
5757
}
5858
}
5959
6060
61-
fn run_raw_json_tests(json_data: &str, run: &fn (json::Json, json::Json)) {
61+
fn run_raw_json_tests(json_data: &str, run: |json::Json, json::Json|) {
6262
let items = match json::from_str(json_data) {
6363
Ok(json::List(items)) => items,
6464
_ => fail!("Invalid JSON")
@@ -77,86 +77,86 @@ fn run_raw_json_tests(json_data: &str, run: &fn (json::Json, json::Json)) {
7777
}
7878
7979
80-
fn run_json_tests<T: ToJson>(json_data: &str, parse: &fn (input: ~str) -> T) {
81-
do run_raw_json_tests(json_data) |input, expected| {
80+
fn run_json_tests<T: ToJson>(json_data: &str, parse: |input: ~str| -> T) {
81+
run_raw_json_tests(json_data, |input, expected| {
8282
match input {
8383
json::String(input) => {
8484
let result = parse(input.to_owned()).to_json();
8585
assert_json_eq(result, expected, input);
8686
},
8787
_ => fail!("Unexpected JSON")
8888
}
89-
}
89+
});
9090
}
9191
9292
9393
#[test]
9494
fn component_value_list() {
95-
do run_json_tests(include_str!("css-parsing-tests/component_value_list.json")) |input| {
95+
run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| {
9696
tokenize(input).map(|(c, _)| c).to_owned_vec()
97-
}
97+
});
9898
}
9999
100100
101101
#[test]
102102
fn one_component_value() {
103-
do run_json_tests(include_str!("css-parsing-tests/one_component_value.json")) |input| {
103+
run_json_tests(include_str!("css-parsing-tests/one_component_value.json"), |input| {
104104
parse_one_component_value(tokenize(input))
105-
}
105+
});
106106
}
107107
108108
109109
#[test]
110110
fn declaration_list() {
111-
do run_json_tests(include_str!("css-parsing-tests/declaration_list.json")) |input| {
111+
run_json_tests(include_str!("css-parsing-tests/declaration_list.json"), |input| {
112112
parse_declaration_list(tokenize(input)).to_owned_vec()
113-
}
113+
});
114114
}
115115
116116
117117
#[test]
118118
fn one_declaration() {
119-
do run_json_tests(include_str!("css-parsing-tests/one_declaration.json")) |input| {
119+
run_json_tests(include_str!("css-parsing-tests/one_declaration.json"), |input| {
120120
parse_one_declaration(tokenize(input))
121-
}
121+
});
122122
}
123123
124124
125125
#[test]
126126
fn rule_list() {
127-
do run_json_tests(include_str!("css-parsing-tests/rule_list.json")) |input| {
127+
run_json_tests(include_str!("css-parsing-tests/rule_list.json"), |input| {
128128
parse_rule_list(tokenize(input)).to_owned_vec()
129-
}
129+
});
130130
}
131131
132132
133133
#[test]
134134
fn stylesheet() {
135-
do run_json_tests(include_str!("css-parsing-tests/stylesheet.json")) |input| {
135+
run_json_tests(include_str!("css-parsing-tests/stylesheet.json"), |input| {
136136
parse_stylesheet_rules(tokenize(input)).to_owned_vec()
137-
}
137+
});
138138
}
139139
140140
141141
#[test]
142142
fn one_rule() {
143-
do run_json_tests(include_str!("css-parsing-tests/one_rule.json")) |input| {
143+
run_json_tests(include_str!("css-parsing-tests/one_rule.json"), |input| {
144144
parse_one_rule(tokenize(input))
145-
}
145+
});
146146
}
147147
148148
149149
#[test]
150150
fn stylesheet_from_bytes() {
151-
do run_raw_json_tests(include_str!("css-parsing-tests/stylesheet_bytes.json"))
151+
run_raw_json_tests(include_str!("css-parsing-tests/stylesheet_bytes.json"),
152152
|input, expected| {
153153
let map = match input {
154154
json::Object(map) => map,
155155
_ => fail!("Unexpected JSON")
156156
};
157157
158158
let result = {
159-
let css = get_string(map, &~"css_bytes").unwrap().iter().map(|c| {
159+
let css = get_string(map, &~"css_bytes").unwrap().chars().map(|c| {
160160
assert!(c as u32 <= 0xFF);
161161
c as u8
162162
}).to_owned_vec();
@@ -170,7 +170,7 @@ fn stylesheet_from_bytes() {
170170
(rules.to_owned_vec(), used_encoding.name().to_owned()).to_json()
171171
};
172172
assert_json_eq(result, expected, json::Object(map).to_str());
173-
}
173+
});
174174
175175
fn get_string<'a>(map: &'a json::Object, key: &~str) -> Option<&'a str> {
176176
match map.find(key) {
@@ -183,13 +183,13 @@ fn stylesheet_from_bytes() {
183183
}
184184
185185
186-
fn run_color_tests(json_data: &str, to_json: &fn(result: Option<Color>) -> json::Json) {
187-
do run_json_tests(json_data) |input| {
186+
fn run_color_tests(json_data: &str, to_json: |result: Option<Color>| -> json::Json) {
187+
run_json_tests(json_data, |input| {
188188
match parse_one_component_value(tokenize(input)) {
189189
Ok(component_value) => to_json(Color::parse(&component_value)),
190190
Err(_reason) => json::Null,
191191
}
192-
}
192+
});
193193
}
194194
195195
@@ -208,14 +208,14 @@ fn color3_hsl() {
208208
/// color3_keywords.json is different: R, G and B are in 0..255 rather than 0..1
209209
#[test]
210210
fn color3_keywords() {
211-
do run_color_tests(include_str!("css-parsing-tests/color3_keywords.json")) |c| {
211+
run_color_tests(include_str!("css-parsing-tests/color3_keywords.json"), |c| {
212212
match c {
213213
Some(RGBA(RGBA { red: r, green: g, blue: b, alpha: a }))
214214
=> (~[r * 255., g * 255., b * 255., a]).to_json(),
215215
Some(CurrentColor) => json::String(~"currentColor"),
216216
None => json::Null,
217217
}
218-
}
218+
});
219219
}
220220
221221
@@ -242,19 +242,19 @@ fn bench_color_lookup_fail(b: &mut test::BenchHarness) {
242242
243243
#[test]
244244
fn nth() {
245-
do run_json_tests(include_str!("css-parsing-tests/An+B.json")) |input| {
245+
run_json_tests(include_str!("css-parsing-tests/An+B.json"), |input| {
246246
parse_nth(tokenize(input).map(|(c, _)| c).to_owned_vec())
247-
}
247+
});
248248
}
249249
250250
251251
#[test]
252252
fn serializer() {
253-
do run_json_tests(include_str!("css-parsing-tests/component_value_list.json")) |input| {
253+
run_json_tests(include_str!("css-parsing-tests/component_value_list.json"), |input| {
254254
let component_values = tokenize(input).map(|(c, _)| c).to_owned_vec();
255255
let serialized = component_values.iter().to_css();
256256
tokenize(serialized).map(|(c, _)| c).to_owned_vec()
257-
}
257+
});
258258
}
259259
260260
@@ -351,7 +351,7 @@ fn list_to_json(list: &~[(ComponentValue, SourceLocation)]) -> ~[json::Json] {
351351
impl ToJson for AtRule {
352352
fn to_json(&self) -> json::Json {
353353
match *self {
354-
AtRule{name: ref name, prelude: ref prelude, block: ref block, _}
354+
AtRule{name: ref name, prelude: ref prelude, block: ref block, ..}
355355
=> json::List(~[json::String(~"at-rule"), name.to_json(),
356356
prelude.to_json(), block.as_ref().map(list_to_json).to_json()])
357357
}
@@ -362,7 +362,7 @@ impl ToJson for AtRule {
362362
impl ToJson for QualifiedRule {
363363
fn to_json(&self) -> json::Json {
364364
match *self {
365-
QualifiedRule{prelude: ref prelude, block: ref block, _}
365+
QualifiedRule{prelude: ref prelude, block: ref block, ..}
366366
=> json::List(~[json::String(~"qualified rule"),
367367
prelude.to_json(), json::List(list_to_json(block))])
368368
}
@@ -373,7 +373,7 @@ impl ToJson for QualifiedRule {
373373
impl ToJson for Declaration {
374374
fn to_json(&self) -> json::Json {
375375
match *self {
376-
Declaration{name: ref name, value: ref value, important: ref important, _}
376+
Declaration{name: ref name, value: ref value, important: ref important, ..}
377377
=> json::List(~[json::String(~"declaration"), name.to_json(),
378378
value.to_json(), important.to_json()])
379379
}

0 commit comments

Comments
 (0)