Skip to content

Commit e31b38d

Browse files
committed
Use the 2018 edition
1 parent 47c25ec commit e31b38d

13 files changed

+64
-93
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ readme = "README.md"
1010
keywords = ["css", "syntax", "parser"]
1111
license = "MPL-2.0"
1212
build = "build.rs"
13+
edition = "2018"
1314

1415
exclude = ["src/css-parsing-tests/**", "src/big-data-url.css"]
1516

build.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
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-
#[macro_use]
6-
extern crate quote;
7-
#[macro_use]
8-
extern crate syn;
9-
extern crate proc_macro2;
10-
115
#[cfg(feature = "dummy_match_byte")]
126
mod codegen {
137
pub fn main() {}
@@ -19,7 +13,6 @@ mod match_byte;
1913

2014
#[cfg(not(feature = "dummy_match_byte"))]
2115
mod codegen {
22-
use match_byte;
2316
use std::env;
2417
use std::path::Path;
2518
use std::thread::Builder;
@@ -35,7 +28,7 @@ mod codegen {
3528
let handle = Builder::new()
3629
.stack_size(128 * 1024 * 1024)
3730
.spawn(move || {
38-
match_byte::expand(&input, &output);
31+
crate::match_byte::expand(&input, &output);
3932
})
4033
.unwrap();
4134

build/match_byte.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
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-
use quote::ToTokens;
5+
use quote::{quote, ToTokens};
66
use std::fs::File;
77
use std::io::{Read, Write};
88
use std::path::Path;
99
use syn;
1010
use syn::fold::Fold;
1111
use syn::parse::{Parse, ParseStream, Result};
12+
use syn::{parse_quote, Token};
1213

1314
use proc_macro2::{Span, TokenStream};
1415

src/lib.rs

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -67,56 +67,27 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
6767

6868
#![recursion_limit = "200"] // For color::parse_color_keyword
6969

70-
extern crate dtoa_short;
71-
extern crate itoa;
72-
#[macro_use]
73-
extern crate cssparser_macros;
74-
#[macro_use]
75-
extern crate matches;
76-
#[cfg(test)]
77-
extern crate difference;
78-
#[cfg(test)]
79-
extern crate encoding_rs;
80-
#[doc(hidden)]
81-
pub extern crate phf as _internal__phf;
82-
#[cfg(feature = "serde")]
83-
extern crate serde;
84-
#[cfg(test)]
85-
extern crate serde_json;
86-
#[cfg(feature = "heapsize")]
87-
#[macro_use]
88-
extern crate heapsize;
89-
extern crate smallvec;
90-
91-
pub use cssparser_macros::*;
92-
93-
pub use color::{
70+
pub use crate::color::{
9471
parse_color_keyword, AngleOrNumber, Color, ColorComponentParser, NumberOrPercentage, RGBA,
9572
};
96-
pub use cow_rc_str::CowRcStr;
97-
pub use from_bytes::{stylesheet_encoding, EncodingSupport};
98-
pub use nth::parse_nth;
99-
pub use parser::{BasicParseError, BasicParseErrorKind, ParseError, ParseErrorKind};
100-
pub use parser::{Delimiter, Delimiters, Parser, ParserInput, ParserState};
101-
pub use rules_and_declarations::parse_important;
102-
pub use rules_and_declarations::{parse_one_declaration, DeclarationListParser, DeclarationParser};
103-
pub use rules_and_declarations::{parse_one_rule, RuleListParser};
104-
pub use rules_and_declarations::{AtRuleParser, AtRuleType, QualifiedRuleParser};
105-
pub use serializer::{
106-
serialize_identifier, serialize_name, serialize_string, CssStringWriter, ToCss,
107-
TokenSerializationType,
108-
};
109-
pub use tokenizer::{SourceLocation, SourcePosition, Token};
110-
pub use unicode_range::UnicodeRange;
111-
112-
// For macros
73+
pub use crate::cow_rc_str::CowRcStr;
74+
pub use crate::from_bytes::{stylesheet_encoding, EncodingSupport};
11375
#[doc(hidden)]
114-
pub use macros::_internal__to_lowercase;
115-
116-
// For macros when used in this crate. Unsure how $crate works with procedural-masquerade.
117-
mod cssparser {
118-
pub use _internal__phf;
119-
}
76+
pub use crate::macros::_internal__to_lowercase;
77+
pub use crate::nth::parse_nth;
78+
pub use crate::parser::{BasicParseError, BasicParseErrorKind, ParseError, ParseErrorKind};
79+
pub use crate::parser::{Delimiter, Delimiters, Parser, ParserInput, ParserState};
80+
pub use crate::rules_and_declarations::{parse_important, parse_one_declaration};
81+
pub use crate::rules_and_declarations::{parse_one_rule, RuleListParser};
82+
pub use crate::rules_and_declarations::{AtRuleParser, AtRuleType, QualifiedRuleParser};
83+
pub use crate::rules_and_declarations::{DeclarationListParser, DeclarationParser};
84+
pub use crate::serializer::{serialize_identifier, serialize_name, serialize_string};
85+
pub use crate::serializer::{CssStringWriter, ToCss, TokenSerializationType};
86+
pub use crate::tokenizer::{SourceLocation, SourcePosition, Token};
87+
pub use crate::unicode_range::UnicodeRange;
88+
pub use cssparser_macros::*;
89+
#[doc(hidden)]
90+
pub use phf as _internal__phf;
12091

12192
#[macro_use]
12293
mod macros;

src/macros.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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+
use matches::matches;
56
use std::mem::MaybeUninit;
67

78
/// Expands to a `match` expression with string patterns,
@@ -40,7 +41,7 @@ macro_rules! match_ignore_ascii_case {
4041
// rather than expression/statement context,
4142
// even though the macro only expands to items.
4243
mod cssparser_internal {
43-
cssparser_internal__assert_ascii_lowercase__max_len! {
44+
$crate::cssparser_internal__assert_ascii_lowercase__max_len! {
4445
match x { $( $match_body )* }
4546
}
4647
}
@@ -90,8 +91,8 @@ macro_rules! ascii_case_insensitive_phf_map {
9091
mod cssparser_internal {
9192
use $crate::_internal__phf::{Map, phf_map};
9293
#[allow(unused)] use super::*;
93-
cssparser_internal__max_len!( $( $key )+ );
94-
cssparser_internal__phf_map!( $ValueType $( $key $value )+ );
94+
$crate::cssparser_internal__max_len!( $( $key )+ );
95+
$crate::cssparser_internal__phf_map!( $ValueType $( $key $value )+ );
9596
}
9697
cssparser_internal__to_lowercase!(input, cssparser_internal::MAX_LENGTH => lowercase);
9798
lowercase.and_then(|s| cssparser_internal::MAP.get(s))

src/nth.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use super::{BasicParseError, Parser, ParserInput, Token};
6+
use matches::matches;
67

78
/// Parse the *An+B* notation, as found in the `:nth-child()` selector.
89
/// The input is typically the arguments of a function,

src/parser.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
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-
use cow_rc_str::CowRcStr;
5+
use crate::cow_rc_str::CowRcStr;
6+
use crate::tokenizer::{SourceLocation, SourcePosition, Token, Tokenizer};
67
use smallvec::SmallVec;
78
use std::ops::BitOr;
89
use std::ops::Range;
9-
use tokenizer::{SourceLocation, SourcePosition, Token, Tokenizer};
1010

1111
/// A capture of the internal state of a `Parser` (including the position within the input),
1212
/// obtained from the `Parser::position` method.
@@ -125,7 +125,7 @@ impl<'i, T> ParseErrorKind<'i, T> {
125125

126126
/// Extensible parse errors that can be encountered by client parsing implementations.
127127
#[derive(Clone, Debug, PartialEq)]
128-
pub struct ParseError<'i, E: 'i> {
128+
pub struct ParseError<'i, E> {
129129
/// Details of this error
130130
pub kind: ParseErrorKind<'i, E>,
131131
/// Location where this error occurred
@@ -195,7 +195,7 @@ impl<'i> ParserInput<'i> {
195195
/// A CSS parser that borrows its `&str` input,
196196
/// yields `Token`s,
197197
/// and keeps track of nested blocks and functions.
198-
pub struct Parser<'i: 't, 't> {
198+
pub struct Parser<'i, 't> {
199199
input: &'t mut ParserInput<'i>,
200200
/// If `Some(_)`, .parse_nested_block() can be called.
201201
at_start_of: Option<BlockType>,
@@ -504,7 +504,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
504504

505505
/// The old name of `try_parse`, which requires raw identifiers in the Rust 2018 edition.
506506
#[inline]
507-
pub fn try<F, T, E>(&mut self, thing: F) -> Result<T, E>
507+
pub fn r#try<F, T, E>(&mut self, thing: F) -> Result<T, E>
508508
where
509509
F: FnOnce(&mut Parser<'i, 't>) -> Result<T, E>,
510510
{

src/rules_and_declarations.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use super::{BasicParseError, BasicParseErrorKind, Delimiter};
88
use super::{ParseError, Parser, SourceLocation, Token};
9-
use cow_rc_str::CowRcStr;
10-
use parser::{parse_nested_block, parse_until_after, parse_until_before, ParserState};
9+
use crate::cow_rc_str::CowRcStr;
10+
use crate::parser::{parse_nested_block, parse_until_after, parse_until_before, ParserState};
1111

1212
/// Parse `!important`.
1313
///
@@ -221,15 +221,15 @@ pub trait QualifiedRuleParser<'i> {
221221
}
222222

223223
/// Provides an iterator for declaration list parsing.
224-
pub struct DeclarationListParser<'i: 't, 't: 'a, 'a, P> {
224+
pub struct DeclarationListParser<'i, 't, 'a, P> {
225225
/// The input given to `DeclarationListParser::new`
226226
pub input: &'a mut Parser<'i, 't>,
227227

228228
/// The parser given to `DeclarationListParser::new`
229229
pub parser: P,
230230
}
231231

232-
impl<'i: 't, 't: 'a, 'a, I, P, E: 'i> DeclarationListParser<'i, 't, 'a, P>
232+
impl<'i, 't, 'a, I, P, E: 'i> DeclarationListParser<'i, 't, 'a, P>
233233
where
234234
P: DeclarationParser<'i, Declaration = I, Error = E> + AtRuleParser<'i, AtRule = I, Error = E>,
235235
{
@@ -257,7 +257,7 @@ where
257257

258258
/// `DeclarationListParser` is an iterator that yields `Ok(_)` for a valid declaration or at-rule
259259
/// or `Err(())` for an invalid one.
260-
impl<'i: 't, 't: 'a, 'a, I, P, E: 'i> Iterator for DeclarationListParser<'i, 't, 'a, P>
260+
impl<'i, 't, 'a, I, P, E: 'i> Iterator for DeclarationListParser<'i, 't, 'a, P>
261261
where
262262
P: DeclarationParser<'i, Declaration = I, Error = E> + AtRuleParser<'i, AtRule = I, Error = E>,
263263
{
@@ -306,7 +306,7 @@ where
306306
}
307307

308308
/// Provides an iterator for rule list parsing.
309-
pub struct RuleListParser<'i: 't, 't: 'a, 'a, P> {
309+
pub struct RuleListParser<'i, 't, 'a, P> {
310310
/// The input given to `RuleListParser::new`
311311
pub input: &'a mut Parser<'i, 't>,
312312

@@ -317,7 +317,7 @@ pub struct RuleListParser<'i: 't, 't: 'a, 'a, P> {
317317
any_rule_so_far: bool,
318318
}
319319

320-
impl<'i: 't, 't: 'a, 'a, R, P, E: 'i> RuleListParser<'i, 't, 'a, P>
320+
impl<'i, 't, 'a, R, P, E: 'i> RuleListParser<'i, 't, 'a, P>
321321
where
322322
P: QualifiedRuleParser<'i, QualifiedRule = R, Error = E>
323323
+ AtRuleParser<'i, AtRule = R, Error = E>,
@@ -358,7 +358,7 @@ where
358358
}
359359

360360
/// `RuleListParser` is an iterator that yields `Ok(_)` for a rule or `Err(())` for an invalid one.
361-
impl<'i: 't, 't: 'a, 'a, R, P, E: 'i> Iterator for RuleListParser<'i, 't, 'a, P>
361+
impl<'i, 't, 'a, R, P, E: 'i> Iterator for RuleListParser<'i, 't, 'a, P>
362362
where
363363
P: QualifiedRuleParser<'i, QualifiedRule = R, Error = E>
364364
+ AtRuleParser<'i, AtRule = R, Error = E>,
@@ -467,7 +467,7 @@ where
467467
})
468468
}
469469

470-
fn parse_at_rule<'i: 't, 't, P, E>(
470+
fn parse_at_rule<'i, 't, P, E>(
471471
start: &ParserState,
472472
name: CowRcStr<'i>,
473473
input: &mut Parser<'i, 't>,

src/serializer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use dtoa_short::{self, Notation};
66
use itoa;
7+
use matches::matches;
78
use std::fmt::{self, Write};
89
use std::io;
910
use std::str;
@@ -293,7 +294,7 @@ where
293294
/// Ok(())
294295
/// }
295296
/// ```
296-
pub struct CssStringWriter<'a, W: 'a> {
297+
pub struct CssStringWriter<'a, W> {
297298
inner: &'a mut W,
298299
}
299300

src/size_of_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
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-
use cow_rc_str::CowRcStr;
5+
use crate::cow_rc_str::CowRcStr;
6+
use crate::tokenizer::Token;
67
use std::borrow::Cow;
7-
use tokenizer::Token;
88

99
macro_rules! size_of_test {
1010
($testname: ident, $t: ty, $expected_size: expr) => {
@@ -41,19 +41,19 @@ size_of_test!(token, Token, 32);
4141
size_of_test!(std_cow_str, Cow<'static, str>, 32);
4242
size_of_test!(cow_rc_str, CowRcStr, 16);
4343

44-
size_of_test!(tokenizer, ::tokenizer::Tokenizer, 72);
44+
size_of_test!(tokenizer, crate::tokenizer::Tokenizer, 72);
4545
size_of_test!(
4646
parser_input,
47-
::parser::ParserInput,
47+
crate::parser::ParserInput,
4848
if cfg!(rustc_has_pr45225) { 136 } else { 144 }
4949
);
50-
size_of_test!(parser, ::parser::Parser, 16);
51-
size_of_test!(source_position, ::SourcePosition, 8);
52-
size_of_test!(parser_state, ::ParserState, 24);
50+
size_of_test!(parser, crate::parser::Parser, 16);
51+
size_of_test!(source_position, crate::SourcePosition, 8);
52+
size_of_test!(parser_state, crate::ParserState, 24);
5353

54-
size_of_test!(basic_parse_error, ::BasicParseError, 48);
54+
size_of_test!(basic_parse_error, crate::BasicParseError, 48);
5555
size_of_test!(
5656
parse_error_lower_bound,
57-
::ParseError<()>,
57+
crate::ParseError<()>,
5858
if cfg!(rustc_has_pr45225) { 48 } else { 56 }
5959
);

src/tests.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
extern crate test;
77

88
use encoding_rs;
9+
use matches::matches;
910
use serde_json::{self, json, Map, Value};
1011

1112
#[cfg(feature = "bench")]
@@ -468,10 +469,11 @@ fn serializer(preserve_comments: bool) {
468469
_ => None,
469470
};
470471
if let Some(closing_token) = closing_token {
471-
let result: Result<_, ParseError<()>> = input.parse_nested_block(|input| {
472-
write_to(previous_token, input, string, preserve_comments);
473-
Ok(())
474-
});
472+
let result: Result<_, ParseError<()>> =
473+
input.parse_nested_block(|input| {
474+
write_to(previous_token, input, string, preserve_comments);
475+
Ok(())
476+
});
475477
result.unwrap();
476478
closing_token.to_css(string).unwrap();
477479
}

src/tokenizer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
// https://drafts.csswg.org/css-syntax/#tokenization
66

7+
use self::Token::*;
8+
use crate::cow_rc_str::CowRcStr;
9+
use crate::parser::ParserState;
10+
use matches::matches;
711
use std::char;
812
use std::i32;
913
use std::ops::Range;
1014

11-
use self::Token::*;
12-
use cow_rc_str::CowRcStr;
13-
use parser::ParserState;
14-
1515
/// One of the pieces the CSS input is broken into.
1616
///
1717
/// Some components use `Cow` in order to borrow from the original input string

src/unicode_range.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
//! https://drafts.csswg.org/css-syntax/#urange
66
7+
use crate::tokenizer::Token;
8+
use crate::{BasicParseError, Parser, ToCss};
79
use std::char;
810
use std::fmt;
9-
use tokenizer::Token;
10-
use {BasicParseError, Parser, ToCss};
1111

1212
/// One contiguous range of code points.
1313
///

0 commit comments

Comments
 (0)