From 460eb9dc0d332d8891f3c5252ba1e3b68bdd1188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 27 Apr 2023 13:46:01 +0200 Subject: [PATCH 1/3] rules_and_declarations: Minor clean-ups. --- src/rules_and_declarations.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/rules_and_declarations.rs b/src/rules_and_declarations.rs index 3224bb96..064621b6 100644 --- a/src/rules_and_declarations.rs +++ b/src/rules_and_declarations.rs @@ -140,14 +140,14 @@ pub trait AtRuleParser<'i> { /// A trait to provide various parsing of qualified rules. /// -/// For example, there could be different implementations -/// for top-level qualified rules (i.e. style rules with Selectors as prelude) -/// and for qualified rules inside `@keyframes` (keyframe rules with keyframe selectors as prelude). +/// For example, there could be different implementations for top-level qualified rules (i.e. style +/// rules with Selectors as prelude) and for qualified rules inside `@keyframes` (keyframe rules +/// with keyframe selectors as prelude). /// -/// Default implementations that reject all qualified rules are provided, -/// so that `impl QualifiedRuleParser<(), ()> for ... {}` can be used -/// for example for using `RuleListParser` to parse a rule list with only at-rules -/// (such as inside `@font-feature-values`). +/// Default implementations that reject all qualified rules are provided, so that +/// `impl QualifiedRuleParser<(), ()> for ... {}` can be used for example for using +/// `RuleListParser` to parse a rule list with only at-rules (such as inside +/// `@font-feature-values`). pub trait QualifiedRuleParser<'i> { /// The intermediate representation of a qualified rule prelude. type Prelude; @@ -223,10 +223,7 @@ where /// since `::next` can return either. /// It could be a custom enum. pub fn new(input: &'a mut Parser<'i, 't>, parser: P) -> Self { - DeclarationListParser { - input: input, - parser: parser, - } + DeclarationListParser { input, parser } } } @@ -304,8 +301,8 @@ where /// It could be a custom enum. pub fn new_for_stylesheet(input: &'a mut Parser<'i, 't>, parser: P) -> Self { RuleListParser { - input: input, - parser: parser, + input, + parser, is_stylesheet: true, any_rule_so_far: false, } @@ -319,8 +316,8 @@ where /// (This is to deal with legacy workarounds for `` HTML element parsing.) pub fn new_for_nested_rule(input: &'a mut Parser<'i, 't>, parser: P) -> Self { RuleListParser { - input: input, - parser: parser, + input, + parser, is_stylesheet: false, any_rule_so_far: false, } From 48b8f0f89c7c89eeb7e1fd224baaa943e9d3c3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 27 Apr 2023 13:50:56 +0200 Subject: [PATCH 2/3] rules_and_declarations: Clean-up lambdas. --- src/rules_and_declarations.rs | 38 +++++++++++++---------------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/rules_and_declarations.rs b/src/rules_and_declarations.rs index 064621b6..bb4dc97f 100644 --- a/src/rules_and_declarations.rs +++ b/src/rules_and_declarations.rs @@ -246,12 +246,10 @@ where let name = name.clone(); let result = { let parser = &mut self.parser; - // FIXME: https://github.com/servo/rust-cssparser/issues/254 - let callback = |input: &mut Parser<'i, '_>| { + parse_until_after(self.input, Delimiter::Semicolon, |input| { input.expect_colon()?; parser.parse_value(name, input) - }; - parse_until_after(self.input, Delimiter::Semicolon, callback) + }) }; return Some(result.map_err(|e| (e, self.input.slice_from(start.position())))); } @@ -436,26 +434,20 @@ where P: AtRuleParser<'i, Error = E>, { let delimiters = Delimiter::Semicolon | Delimiter::CurlyBracketBlock; - // FIXME: https://github.com/servo/rust-cssparser/issues/254 - let callback = |input: &mut Parser<'i, '_>| parser.parse_prelude(name, input); - let result = parse_until_before(input, delimiters, callback); + let result = parse_until_before(input, delimiters, |input| parser.parse_prelude(name, input)); match result { Ok(prelude) => { let result = match input.next() { - Ok(&Token::Semicolon) | Err(_) => { - parser.rule_without_block(prelude, start) - .map_err(|()| input.new_unexpected_token_error(Token::Semicolon)) - }, + Ok(&Token::Semicolon) | Err(_) => parser + .rule_without_block(prelude, start) + .map_err(|()| input.new_unexpected_token_error(Token::Semicolon)), Ok(&Token::CurlyBracketBlock) => { - // FIXME: https://github.com/servo/rust-cssparser/issues/254 - let callback = - |input: &mut Parser<'i, '_>| parser.parse_block(prelude, start, input); - parse_nested_block(input, callback) - }, + parse_nested_block(input, |input| parser.parse_block(prelude, start, input)) + } Ok(_) => unreachable!(), }; result.map_err(|e| (e, input.slice_from(start.position()))) - }, + } Err(error) => { let end_position = input.position(); match input.next() { @@ -463,7 +455,7 @@ where _ => unreachable!(), }; Err((error, input.slice(start.position()..end_position))) - }, + } } } @@ -475,16 +467,14 @@ where P: QualifiedRuleParser<'i, Error = E>, { let start = input.state(); - // FIXME: https://github.com/servo/rust-cssparser/issues/254 - let callback = |input: &mut Parser<'i, '_>| parser.parse_prelude(input); - let prelude = parse_until_before(input, Delimiter::CurlyBracketBlock, callback); + let prelude = parse_until_before(input, Delimiter::CurlyBracketBlock, |input| { + parser.parse_prelude(input) + }); match *input.next()? { Token::CurlyBracketBlock => { // Do this here so that we consume the `{` even if the prelude is `Err`. let prelude = prelude?; - // FIXME: https://github.com/servo/rust-cssparser/issues/254 - let callback = |input: &mut Parser<'i, '_>| parser.parse_block(prelude, &start, input); - parse_nested_block(input, callback) + parse_nested_block(input, |input| parser.parse_block(prelude, &start, input)) } _ => unreachable!(), } From bd27360a33b07cf464dab72d3a512c70574e680d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 27 Apr 2023 14:01:32 +0200 Subject: [PATCH 3/3] Bump MSRV to 1.63 --- .github/workflows/main.yml | 6 +----- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c2264163..6b8f1460 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,7 +16,7 @@ jobs: - nightly - beta - stable - - 1.56.0 + - 1.63.0 features: - - --features dummy_match_byte @@ -35,10 +35,6 @@ jobs: toolchain: ${{ matrix.toolchain }} override: true - - name: Downgrade phf to a version compatible with the MSRV - run: cargo update --package phf --precise 0.10.1 - if: matrix.toolchain == '1.40.0' - - name: Cargo build run: cargo build ${{ matrix.features }} diff --git a/Cargo.toml b/Cargo.toml index 23695b79..ec4aa47c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["css", "syntax", "parser"] license = "MPL-2.0" build = "build.rs" edition = "2018" -rust-version = "1.56" +rust-version = "1.63" exclude = ["src/css-parsing-tests/**", "src/big-data-url.css"]