Makes Clippy happy

pull/255/head
Tpt 2 years ago committed by Thomas Tanon
parent 73bc18e5bd
commit c1d2cf030d
  1. 10
      lib/oxrdf/src/dataset.rs
  2. 1
      lib/src/io/read.rs
  3. 40
      lib/src/sparql/eval.rs
  4. 2
      lib/src/sparql/model.rs
  5. 41
      lib/src/sparql/plan_builder.rs
  6. 8
      lib/src/xsd/date_time.rs
  7. 13
      lib/src/xsd/decimal.rs
  8. 4
      lib/tests/store.rs

@ -539,14 +539,14 @@ impl Dataset {
}
#[cfg(feature = "rdf-star")]
if let InternedSubject::Triple(triple) = s {
self.triple_blank_nodes(triple, &mut bnodes);
Self::triple_blank_nodes(triple, &mut bnodes);
}
if let InternedTerm::BlankNode(bnode) = o {
bnodes.insert(*bnode);
}
#[cfg(feature = "rdf-star")]
if let InternedTerm::Triple(triple) = o {
self.triple_blank_nodes(triple, &mut bnodes);
Self::triple_blank_nodes(triple, &mut bnodes);
}
if let InternedGraphName::BlankNode(bnode) = g {
bnodes.insert(*bnode);
@ -556,16 +556,16 @@ impl Dataset {
}
#[cfg(feature = "rdf-star")]
fn triple_blank_nodes(&self, triple: &InternedTriple, bnodes: &mut HashSet<InternedBlankNode>) {
fn triple_blank_nodes(triple: &InternedTriple, bnodes: &mut HashSet<InternedBlankNode>) {
if let InternedSubject::BlankNode(bnode) = &triple.subject {
bnodes.insert(*bnode);
} else if let InternedSubject::Triple(t) = &triple.subject {
self.triple_blank_nodes(t, bnodes);
Self::triple_blank_nodes(t, bnodes);
}
if let InternedTerm::BlankNode(bnode) = &triple.object {
bnodes.insert(*bnode);
} else if let InternedTerm::Triple(t) = &triple.object {
self.triple_blank_nodes(t, bnodes);
Self::triple_blank_nodes(t, bnodes);
}
}

@ -109,6 +109,7 @@ pub struct TripleReader<R: BufRead> {
buffer: Vec<Triple>,
}
#[allow(clippy::large_enum_variant)]
enum TripleReaderKind<R: BufRead> {
NTriples(NTriplesParser<R>),
Turtle(TurtleParser<R>),

@ -1484,7 +1484,7 @@ impl SimpleEvaluator {
Rc::new(move |tuple| {
let (arg1, arg2, _) =
to_argument_compatible_strings(&dataset, &arg1(tuple)?, &arg2(tuple)?)?;
Some((&arg1).starts_with(arg2.as_str()).into())
Some(arg1.starts_with(arg2.as_str()).into())
})
}
PlanExpression::EncodeForUri(ltrl) => {
@ -1528,7 +1528,7 @@ impl SimpleEvaluator {
Rc::new(move |tuple| {
let (arg1, arg2, _) =
to_argument_compatible_strings(&dataset, &arg1(tuple)?, &arg2(tuple)?)?;
Some((&arg1).ends_with(arg2.as_str()).into())
Some(arg1.ends_with(arg2.as_str()).into())
})
}
PlanExpression::Contains(arg1, arg2) => {
@ -1538,7 +1538,7 @@ impl SimpleEvaluator {
Rc::new(move |tuple| {
let (arg1, arg2, _) =
to_argument_compatible_strings(&dataset, &arg1(tuple)?, &arg2(tuple)?)?;
Some((&arg1).contains(arg2.as_str()).into())
Some(arg1.contains(arg2.as_str()).into())
})
}
PlanExpression::StrBefore(arg1, arg2) => {
@ -1548,7 +1548,7 @@ impl SimpleEvaluator {
Rc::new(move |tuple| {
let (arg1, arg2, language) =
to_argument_compatible_strings(&dataset, &arg1(tuple)?, &arg2(tuple)?)?;
Some(if let Some(position) = (&arg1).find(arg2.as_str()) {
Some(if let Some(position) = arg1.find(arg2.as_str()) {
build_plain_literal(&dataset, &arg1[..position], language)
} else {
build_string_literal(&dataset, "")
@ -1562,7 +1562,7 @@ impl SimpleEvaluator {
Rc::new(move |tuple| {
let (arg1, arg2, language) =
to_argument_compatible_strings(&dataset, &arg1(tuple)?, &arg2(tuple)?)?;
Some(if let Some(position) = (&arg1).find(arg2.as_str()) {
Some(if let Some(position) = arg1.find(arg2.as_str()) {
build_plain_literal(&dataset, &arg1[position + arg2.len()..], language)
} else {
build_string_literal(&dataset, "")
@ -1858,7 +1858,7 @@ impl SimpleEvaluator {
EncodedTerm::DecimalLiteral(value) => Some(value.to_bool().into()),
EncodedTerm::SmallStringLiteral(value) => parse_boolean_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_boolean_str(&*dataset.get_str(&value_id).ok()??)
parse_boolean_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1876,7 +1876,7 @@ impl SimpleEvaluator {
}
EncodedTerm::SmallStringLiteral(value) => parse_double_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_double_str(&*dataset.get_str(&value_id).ok()??)
parse_double_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1894,7 +1894,7 @@ impl SimpleEvaluator {
}
EncodedTerm::SmallStringLiteral(value) => parse_float_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_float_str(&*dataset.get_str(&value_id).ok()??)
parse_float_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1907,10 +1907,10 @@ impl SimpleEvaluator {
EncodedTerm::DoubleLiteral(value) => Some(value.to_i64().into()),
EncodedTerm::IntegerLiteral(value) => Some(value.into()),
EncodedTerm::DecimalLiteral(value) => Some(i64::try_from(value).ok()?.into()),
EncodedTerm::BooleanLiteral(value) => Some(if value { 1 } else { 0 }.into()),
EncodedTerm::BooleanLiteral(value) => Some(i64::from(value).into()),
EncodedTerm::SmallStringLiteral(value) => parse_integer_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_integer_str(&*dataset.get_str(&value_id).ok()??)
parse_integer_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1923,12 +1923,10 @@ impl SimpleEvaluator {
EncodedTerm::DoubleLiteral(value) => Some(Decimal::from_double(value).into()),
EncodedTerm::IntegerLiteral(value) => Some(Decimal::from(value).into()),
EncodedTerm::DecimalLiteral(value) => Some(value.into()),
EncodedTerm::BooleanLiteral(value) => {
Some(Decimal::from(if value { 1 } else { 0 }).into())
}
EncodedTerm::BooleanLiteral(value) => Some(Decimal::from(value).into()),
EncodedTerm::SmallStringLiteral(value) => parse_decimal_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_decimal_str(&*dataset.get_str(&value_id).ok()??)
parse_decimal_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1941,7 +1939,7 @@ impl SimpleEvaluator {
EncodedTerm::DateTimeLiteral(value) => Some(Date::try_from(value).ok()?.into()),
EncodedTerm::SmallStringLiteral(value) => parse_date_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_date_str(&*dataset.get_str(&value_id).ok()??)
parse_date_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1954,7 +1952,7 @@ impl SimpleEvaluator {
EncodedTerm::DateTimeLiteral(value) => Some(Time::try_from(value).ok()?.into()),
EncodedTerm::SmallStringLiteral(value) => parse_time_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_time_str(&*dataset.get_str(&value_id).ok()??)
parse_time_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1967,7 +1965,7 @@ impl SimpleEvaluator {
EncodedTerm::DateLiteral(value) => Some(DateTime::try_from(value).ok()?.into()),
EncodedTerm::SmallStringLiteral(value) => parse_date_time_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_date_time_str(&*dataset.get_str(&value_id).ok()??)
parse_date_time_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -1985,7 +1983,7 @@ impl SimpleEvaluator {
}
EncodedTerm::SmallStringLiteral(value) => parse_duration_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_duration_str(&*dataset.get_str(&value_id).ok()??)
parse_duration_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -2000,7 +1998,7 @@ impl SimpleEvaluator {
EncodedTerm::YearMonthDurationLiteral(value) => Some(value.into()),
EncodedTerm::SmallStringLiteral(value) => parse_year_month_duration_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_year_month_duration_str(&*dataset.get_str(&value_id).ok()??)
parse_year_month_duration_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -2015,7 +2013,7 @@ impl SimpleEvaluator {
EncodedTerm::DayTimeDurationLiteral(value) => Some(value.into()),
EncodedTerm::SmallStringLiteral(value) => parse_day_time_duration_str(&value),
EncodedTerm::BigStringLiteral { value_id } => {
parse_day_time_duration_str(&*dataset.get_str(&value_id).ok()??)
parse_day_time_duration_str(&dataset.get_str(&value_id).ok()??)
}
_ => None,
})
@ -3292,7 +3290,7 @@ impl Iterator for ConsecutiveDeduplication {
fn size_hint(&self) -> (usize, Option<usize>) {
let (min, max) = self.inner.size_hint();
(if min == 0 { 0 } else { 1 }, max)
((min != 0).into(), max)
}
}

@ -190,7 +190,7 @@ impl QuerySolutionIter {
/// ```
#[inline]
pub fn variables(&self) -> &[Variable] {
&*self.variables
&self.variables
}
}

@ -102,7 +102,7 @@ impl<'a> PlanBuilder<'a> {
let right = self.build_for_graph_pattern(right, variables, graph_name)?;
let mut possible_problem_vars = BTreeSet::new();
self.add_left_join_problematic_variables(&right, &mut possible_problem_vars);
Self::add_left_join_problematic_variables(&right, &mut possible_problem_vars);
//We add the extra filter if needed
let right = if let Some(expr) = expression {
@ -182,7 +182,7 @@ impl<'a> PlanBuilder<'a> {
} => {
let mut inner_variables = by.clone();
let inner_graph_name =
self.convert_pattern_value_id(graph_name, variables, &mut inner_variables);
Self::convert_pattern_value_id(graph_name, variables, &mut inner_variables);
PlanNode::Aggregate {
child: Box::new(self.build_for_graph_pattern(
@ -242,7 +242,7 @@ impl<'a> PlanBuilder<'a> {
} => {
let mut inner_variables = projection.clone();
let inner_graph_name =
self.convert_pattern_value_id(graph_name, variables, &mut inner_variables);
Self::convert_pattern_value_id(graph_name, variables, &mut inner_variables);
PlanNode::Project {
child: Box::new(self.build_for_graph_pattern(
inner,
@ -1034,7 +1034,6 @@ impl<'a> PlanBuilder<'a> {
}
fn convert_pattern_value_id(
&self,
from_value: &PatternValue,
from: &[Variable],
to: &mut Vec<Variable>,
@ -1045,9 +1044,9 @@ impl<'a> PlanBuilder<'a> {
PatternValue::Variable(Self::convert_variable_id(*from_id, from, to))
}
PatternValue::Triple(triple) => PatternValue::Triple(Box::new(TriplePatternValue {
subject: self.convert_pattern_value_id(&triple.subject, from, to),
predicate: self.convert_pattern_value_id(&triple.predicate, from, to),
object: self.convert_pattern_value_id(&triple.object, from, to),
subject: Self::convert_pattern_value_id(&triple.subject, from, to),
predicate: Self::convert_pattern_value_id(&triple.predicate, from, to),
object: Self::convert_pattern_value_id(&triple.object, from, to),
})),
}
}
@ -1067,7 +1066,7 @@ impl<'a> PlanBuilder<'a> {
}
}
fn add_left_join_problematic_variables(&self, node: &PlanNode, set: &mut BTreeSet<usize>) {
fn add_left_join_problematic_variables(node: &PlanNode, set: &mut BTreeSet<usize>) {
match node {
PlanNode::StaticBindings { .. }
| PlanNode::QuadPattern { .. }
@ -1079,22 +1078,22 @@ impl<'a> PlanBuilder<'a> {
set.insert(v);
}
});
self.add_left_join_problematic_variables(child, set);
Self::add_left_join_problematic_variables(child, set);
}
PlanNode::Union { children } => {
for child in children.iter() {
self.add_left_join_problematic_variables(child, set);
Self::add_left_join_problematic_variables(child, set);
}
}
PlanNode::HashJoin { left, right } | PlanNode::ForLoopJoin { left, right } => {
self.add_left_join_problematic_variables(left, set);
self.add_left_join_problematic_variables(right, set);
Self::add_left_join_problematic_variables(left, set);
Self::add_left_join_problematic_variables(right, set);
}
PlanNode::AntiJoin { left, .. } => {
self.add_left_join_problematic_variables(left, set);
Self::add_left_join_problematic_variables(left, set);
}
PlanNode::LeftJoin { left, right, .. } => {
self.add_left_join_problematic_variables(left, set);
Self::add_left_join_problematic_variables(left, set);
right.lookup_used_variables(&mut |v| {
set.insert(v);
});
@ -1108,26 +1107,28 @@ impl<'a> PlanBuilder<'a> {
set.insert(v);
}
});
self.add_left_join_problematic_variables(child, set);
self.add_left_join_problematic_variables(child, set);
Self::add_left_join_problematic_variables(child, set);
Self::add_left_join_problematic_variables(child, set);
}
PlanNode::Sort { child, .. }
| PlanNode::HashDeduplicate { child }
| PlanNode::Reduced { child }
| PlanNode::Skip { child, .. }
| PlanNode::Limit { child, .. } => self.add_left_join_problematic_variables(child, set),
| PlanNode::Limit { child, .. } => {
Self::add_left_join_problematic_variables(child, set)
}
PlanNode::Service { child, silent, .. } => {
if *silent {
child.lookup_used_variables(&mut |v| {
set.insert(v);
});
} else {
self.add_left_join_problematic_variables(child, set)
Self::add_left_join_problematic_variables(child, set)
}
}
PlanNode::Project { mapping, child } => {
let mut child_bound = BTreeSet::new();
self.add_left_join_problematic_variables(child, &mut child_bound);
Self::add_left_join_problematic_variables(child, &mut child_bound);
for (child_i, output_i) in mapping.iter() {
if child_bound.contains(child_i) {
set.insert(*output_i);
@ -1367,7 +1368,7 @@ fn sort_bgp(p: &[TriplePattern]) -> Vec<&TriplePattern> {
let mut new_p: Vec<_> = p.iter().collect();
for i in 0..new_p.len() {
(&mut new_p[i..]).sort_by(|p1, p2| {
new_p[i..].sort_by(|p1, p2| {
estimate_pattern_cost(p1, &assigned_variables, &assigned_blank_nodes).cmp(
&estimate_pattern_cost(p2, &assigned_variables, &assigned_blank_nodes),
)

@ -1234,12 +1234,8 @@ impl Timestamp {
let year =
(400 * year_mul_400 + 100 * year_mul_100 + 4 * year_mul_4 + year_mod_4 + shift) as i64;
let leap_year_offset = if (year_mul_100 == 0 || year_mul_4 != 0) && year_mod_4 == 0 {
1
} else {
0
};
days += leap_year_offset;
let is_leap_year = (year_mul_100 == 0 || year_mul_4 != 0) && year_mod_4 == 0;
days += i128::from(is_leap_year);
let mut month = 0;
for month_i in 1..=12 {

@ -113,9 +113,9 @@ impl Decimal {
let value = self.value / DECIMAL_PART_POW_MINUS_ONE;
Self {
value: if value >= 0 {
(value / 10 + if value % 10 >= 5 { 1 } else { 0 }) * DECIMAL_PART_POW
(value / 10 + i128::from(value % 10 >= 5)) * DECIMAL_PART_POW
} else {
(value / 10 + if -value % 10 > 5 { -1 } else { 0 }) * DECIMAL_PART_POW
(value / 10 - i128::from(-value % 10 > 5)) * DECIMAL_PART_POW
},
}
}
@ -210,6 +210,15 @@ impl Decimal {
}
}
impl From<bool> for Decimal {
#[inline]
fn from(value: bool) -> Self {
Self {
value: i128::from(value) * DECIMAL_PART_POW,
}
}
}
impl From<i8> for Decimal {
#[inline]
fn from(value: i8) -> Self {

@ -356,11 +356,11 @@ fn test_backward_compatibility() -> Result<(), Box<dyn Error>> {
fn reset_dir(dir: &str) -> Result<(), Box<dyn Error>> {
assert!(Command::new("git")
.args(&["clean", "-fX", dir])
.args(["clean", "-fX", dir])
.status()?
.success());
assert!(Command::new("git")
.args(&["checkout", "HEAD", "--", dir])
.args(["checkout", "HEAD", "--", dir])
.status()?
.success());
Ok(())

Loading…
Cancel
Save