From e31e448fda398757a942bfa237a796d20c1acc77 Mon Sep 17 00:00:00 2001 From: Ville Lindholm Date: Sat, 5 Apr 2025 11:42:55 +0300 Subject: [PATCH] lint Signed-off-by: Ville Lindholm --- components/script/dom/node.rs | 3 +- components/script/xpath/eval.rs | 21 ++++------ components/script/xpath/parser.rs | 70 +++++++++++++++---------------- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 1ce511cc4b9..36922d0f11b 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -48,7 +48,7 @@ use style::properties::ComputedValues; use style::selector_parser::{SelectorImpl, SelectorParser}; use style::stylesheets::{Stylesheet, UrlExtraData}; use uuid::Uuid; -use xml5ever::serialize as xml_serialize; +use xml5ever::{local_name, serialize as xml_serialize}; use super::globalscope::GlobalScope; use crate::conversions::Convert; @@ -1415,7 +1415,6 @@ impl Node { // TODO: Check HTTP Content-Language header }) .next() - .unwrap_or(String::new()) } /// diff --git a/components/script/xpath/eval.rs b/components/script/xpath/eval.rs index 7263db4ef4f..4b8e185e954 100644 --- a/components/script/xpath/eval.rs +++ b/components/script/xpath/eval.rs @@ -442,8 +442,8 @@ impl Evaluatable for StepExpr { if axis_step .predicates - .as_ref() - .map_or(true, |plist| plist.predicates.is_empty()) + .predicates + .is_empty() { trace!( "[StepExpr] No predicates, returning nodes {:?}", @@ -461,10 +461,10 @@ impl Evaluatable for StepExpr { } fn is_primitive(&self) -> bool { - match self { - StepExpr::Filter(filter_expr) => filter_expr.is_primitive(), - StepExpr::Axis(_) => false, - } + self.predicates + .predicates + .is_empty() && + self.primary.is_primitive() } } @@ -540,10 +540,7 @@ impl Evaluatable for PredicateExpr { impl Evaluatable for FilterExpr { fn evaluate(&self, context: &EvaluationCtx) -> Result { let primary_result = self.primary.evaluate(context)?; - let have_predicates = self - .predicates - .as_ref() - .map_or(false, |plist| !plist.predicates.is_empty()); + let have_predicates = !self.predicates.predicates.is_empty(); match (have_predicates, &primary_result) { (false, _) => { @@ -571,8 +568,8 @@ impl Evaluatable for FilterExpr { fn is_primitive(&self) -> bool { self.predicates - .as_ref() - .map_or(true, |plist| plist.predicates.is_empty()) && + .predicates + .is_empty() && self.primary.is_primitive() } } diff --git a/components/script/xpath/parser.rs b/components/script/xpath/parser.rs index 616c44ff555..68152c1f4fb 100644 --- a/components/script/xpath/parser.rs +++ b/components/script/xpath/parser.rs @@ -553,7 +553,7 @@ fn relative_path_expr(input: &str) -> IResult<&str, Expr> { all_steps.push(StepExpr::Axis(AxisStep { axis: Axis::DescendantOrSelf, node_test: NodeTest::Kind(KindTest::Node), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })); } all_steps.push(step); @@ -697,16 +697,12 @@ fn filter_expr(input: &str) -> IResult<&str, FilterExpr> { )) } -fn predicate_list(input: &str) -> IResult<&str, Option> { +fn predicate_list(input: &str) -> IResult<&str, PredicateListExpr> { let (input, predicates) = many0(predicate)(input)?; Ok(( input, - if predicates.is_empty() { - None - } else { - Some(PredicateListExpr { predicates }) - }, + PredicateListExpr { predicates }, )) } @@ -1013,7 +1009,7 @@ mod tests { steps: vec![StepExpr::Axis(AxisStep { axis: Axis::Child, node_test: NodeTest::Kind(KindTest::PI(Some("test".to_string()))), - predicates: Some(PredicateListExpr { + predicates: PredicateListExpr { predicates: vec![PredicateExpr { expr: Expr::Path(PathExpr { is_absolute: false, @@ -1022,11 +1018,11 @@ mod tests { primary: PrimaryExpr::Literal(Literal::Numeric( NumericLiteral::Integer(2), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), }], - }), + }, })], }), ), @@ -1044,7 +1040,7 @@ mod tests { primary: PrimaryExpr::Literal(Literal::String( "hello".to_string(), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), Expr::Path(PathExpr { @@ -1052,7 +1048,7 @@ mod tests { is_descendant: false, steps: vec![StepExpr::Filter(FilterExpr { primary: PrimaryExpr::Literal(Literal::String(" ".to_string())), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), Expr::Path(PathExpr { @@ -1062,11 +1058,11 @@ mod tests { primary: PrimaryExpr::Literal(Literal::String( "world".to_string(), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), ])), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), ), @@ -1093,7 +1089,7 @@ mod tests { steps: vec![StepExpr::Axis(AxisStep { axis: Axis::Child, node_test: NodeTest::Wildcard, - predicates: Some(PredicateListExpr { + predicates: PredicateListExpr { predicates: vec![PredicateExpr { expr: Expr::Path(PathExpr { is_absolute: false, @@ -1109,7 +1105,9 @@ mod tests { prefix: None, local_part: "class".to_string(), }), - predicates: None, + predicates: PredicateListExpr { + predicates: vec![] + }, })], })), Box::new(Expr::Path(PathExpr { @@ -1119,15 +1117,15 @@ mod tests { primary: PrimaryExpr::Literal(Literal::String( "test".to_string(), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), }], - }), + }, })], }), ), @@ -1143,7 +1141,7 @@ mod tests { prefix: None, local_part: "div".to_string(), }), - predicates: Some(PredicateListExpr { + predicates: PredicateListExpr { predicates: vec![PredicateExpr { expr: Expr::Relational( Box::new(Expr::Path(PathExpr { @@ -1153,7 +1151,7 @@ mod tests { primary: PrimaryExpr::Function( CoreFunction::Position, ), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), RelationalOp::Gt, @@ -1164,28 +1162,28 @@ mod tests { primary: PrimaryExpr::Literal(Literal::Numeric( NumericLiteral::Integer(1), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), ), }], - }), + }, }), StepExpr::Axis(AxisStep { axis: Axis::Child, node_test: NodeTest::Wildcard, - predicates: Some(PredicateListExpr { + predicates: PredicateListExpr { predicates: vec![PredicateExpr { expr: Expr::Path(PathExpr { is_absolute: false, is_descendant: false, steps: vec![StepExpr::Filter(FilterExpr { primary: PrimaryExpr::Function(CoreFunction::Last), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), }], - }), + }, }), ], }), @@ -1202,7 +1200,7 @@ mod tests { prefix: None, local_part: "mu".to_string(), }), - predicates: Some(PredicateListExpr { + predicates: PredicateListExpr { predicates: vec![PredicateExpr { expr: Expr::Equality( Box::new(Expr::Path(PathExpr { @@ -1214,7 +1212,7 @@ mod tests { prefix: Some("xml".to_string()), local_part: "id".to_string(), }), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), EqualityOp::Eq, @@ -1225,17 +1223,17 @@ mod tests { primary: PrimaryExpr::Literal(Literal::String( "id1".to_string(), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), ), }], - }), + }, }), StepExpr::Axis(AxisStep { axis: Axis::DescendantOrSelf, // Represents the second '//' node_test: NodeTest::Kind(KindTest::Node), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, }), StepExpr::Axis(AxisStep { axis: Axis::Child, @@ -1243,7 +1241,7 @@ mod tests { prefix: None, local_part: "rho".to_string(), }), - predicates: Some(PredicateListExpr { + predicates: PredicateListExpr { predicates: vec![ PredicateExpr { expr: Expr::Path(PathExpr { @@ -1255,7 +1253,7 @@ mod tests { prefix: None, local_part: "title".to_string(), }), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], }), }, @@ -1270,7 +1268,7 @@ mod tests { prefix: Some("xml".to_string()), local_part: "lang".to_string(), }), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), EqualityOp::Eq, @@ -1281,13 +1279,13 @@ mod tests { primary: PrimaryExpr::Literal(Literal::String( "en-GB".to_string(), )), - predicates: None, + predicates: PredicateListExpr { predicates: vec![] }, })], })), ), }, ], - }), + }, }), ], }),