Fixes Clippy warnings

pull/121/head
Tpt 3 years ago
parent 4c464f1701
commit ec2b307255
  1. 33
      js/src/model.rs
  2. 2
      js/src/store.rs
  3. 4
      lib/src/lib.rs
  4. 4
      lib/src/sparql/eval.rs
  5. 2
      server/src/main.rs
  6. 2
      testsuite/benches/sparql_query.rs
  7. 4
      testsuite/src/manifest.rs
  8. 10
      testsuite/src/sparql_evaluator.rs
  9. 6
      wikibase/src/main.rs

@ -87,7 +87,7 @@ impl JsDataFactory {
graph_name: if graph.is_undefined() || graph.is_null() { graph_name: if graph.is_undefined() || graph.is_null() {
JsTerm::DefaultGraph(JsDefaultGraph {}) JsTerm::DefaultGraph(JsDefaultGraph {})
} else { } else {
self.from_js.to_term(&graph)? self.from_js.to_term(graph)?
}, },
}) })
} }
@ -123,7 +123,7 @@ impl JsNamedNode {
pub fn equals(&self, other: &JsValue) -> bool { pub fn equals(&self, other: &JsValue) -> bool {
if let Ok(Some(JsTerm::NamedNode(other))) = if let Ok(Some(JsTerm::NamedNode(other))) =
FromJsConverter::default().to_optional_term(&other) FromJsConverter::default().to_optional_term(other)
{ {
self == &other self == &other
} else { } else {
@ -182,7 +182,7 @@ impl JsBlankNode {
pub fn equals(&self, other: &JsValue) -> bool { pub fn equals(&self, other: &JsValue) -> bool {
if let Ok(Some(JsTerm::BlankNode(other))) = if let Ok(Some(JsTerm::BlankNode(other))) =
FromJsConverter::default().to_optional_term(&other) FromJsConverter::default().to_optional_term(other)
{ {
self == &other self == &other
} else { } else {
@ -250,8 +250,7 @@ impl JsLiteral {
} }
pub fn equals(&self, other: &JsValue) -> bool { pub fn equals(&self, other: &JsValue) -> bool {
if let Ok(Some(JsTerm::Literal(other))) = if let Ok(Some(JsTerm::Literal(other))) = FromJsConverter::default().to_optional_term(other)
FromJsConverter::default().to_optional_term(&other)
{ {
self == &other self == &other
} else { } else {
@ -296,7 +295,7 @@ impl JsDefaultGraph {
pub fn equals(&self, other: &JsValue) -> bool { pub fn equals(&self, other: &JsValue) -> bool {
if let Ok(Some(JsTerm::DefaultGraph(other))) = if let Ok(Some(JsTerm::DefaultGraph(other))) =
FromJsConverter::default().to_optional_term(&other) FromJsConverter::default().to_optional_term(other)
{ {
self == &other self == &other
} else { } else {
@ -472,7 +471,7 @@ impl JsQuad {
pub fn equals(&self, other: &JsValue) -> bool { pub fn equals(&self, other: &JsValue) -> bool {
FromJsConverter::default() FromJsConverter::default()
.to_quad(&other) .to_quad(other)
.map_or(false, |other| self == &other) .map_or(false, |other| self == &other)
} }
} }
@ -529,18 +528,18 @@ impl Default for FromJsConverter {
impl FromJsConverter { impl FromJsConverter {
pub fn to_term(&self, value: &JsValue) -> Result<JsTerm, JsValue> { pub fn to_term(&self, value: &JsValue) -> Result<JsTerm, JsValue> {
let term_type = Reflect::get(&value, &self.term_type)?; let term_type = Reflect::get(value, &self.term_type)?;
if let Some(term_type) = term_type.as_string() { if let Some(term_type) = term_type.as_string() {
match term_type.as_str() { match term_type.as_str() {
"NamedNode" => Ok(NamedNode::new( "NamedNode" => Ok(NamedNode::new(
Reflect::get(&value, &self.value)? Reflect::get(value, &self.value)?
.as_string() .as_string()
.ok_or_else(|| format_err!("NamedNode should have a string value"))?, .ok_or_else(|| format_err!("NamedNode should have a string value"))?,
) )
.map_err(|v| UriError::new(&v.to_string()))? .map_err(|v| UriError::new(&v.to_string()))?
.into()), .into()),
"BlankNode" => Ok(BlankNode::new( "BlankNode" => Ok(BlankNode::new(
&Reflect::get(&value, &self.value)? &Reflect::get(value, &self.value)?
.as_string() .as_string()
.ok_or_else(|| format_err!("BlankNode should have a string value"))?, .ok_or_else(|| format_err!("BlankNode should have a string value"))?,
) )
@ -548,15 +547,15 @@ impl FromJsConverter {
.into()), .into()),
"Literal" => { "Literal" => {
if let JsTerm::NamedNode(datatype) = if let JsTerm::NamedNode(datatype) =
self.to_term(&Reflect::get(&value, &self.datatype)?)? self.to_term(&Reflect::get(value, &self.datatype)?)?
{ {
let datatype = NamedNode::from(datatype); let datatype = NamedNode::from(datatype);
let literal_value = Reflect::get(&value, &self.value)? let literal_value = Reflect::get(value, &self.value)?
.as_string() .as_string()
.ok_or_else(|| format_err!("Literal should have a string value"))?; .ok_or_else(|| format_err!("Literal should have a string value"))?;
Ok(match datatype.as_str() { Ok(match datatype.as_str() {
"http://www.w3.org/2001/XMLSchema#string" => Literal::new_simple_literal(literal_value), "http://www.w3.org/2001/XMLSchema#string" => Literal::new_simple_literal(literal_value),
"http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" => Literal::new_language_tagged_literal(literal_value, Reflect::get(&value, &self.language)?.as_string().ok_or_else( "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" => Literal::new_language_tagged_literal(literal_value, Reflect::get(value, &self.language)?.as_string().ok_or_else(
|| format_err!("Literal with rdf:langString datatype should have a language"), || format_err!("Literal with rdf:langString datatype should have a language"),
)?).map_err(to_err)?, )?).map_err(to_err)?,
_ => Literal::new_typed_literal(literal_value, datatype) _ => Literal::new_typed_literal(literal_value, datatype)
@ -588,10 +587,10 @@ impl FromJsConverter {
pub fn to_quad(&self, value: &JsValue) -> Result<JsQuad, JsValue> { pub fn to_quad(&self, value: &JsValue) -> Result<JsQuad, JsValue> {
Ok(JsQuad { Ok(JsQuad {
subject: self.to_term(&Reflect::get(&value, &self.subject)?)?, subject: self.to_term(&Reflect::get(value, &self.subject)?)?,
predicate: self.to_term(&Reflect::get(&value, &self.predicate)?)?, predicate: self.to_term(&Reflect::get(value, &self.predicate)?)?,
object: self.to_term(&Reflect::get(&value, &self.object)?)?, object: self.to_term(&Reflect::get(value, &self.object)?)?,
graph_name: self.to_term(&Reflect::get(&value, &self.graph)?)?, graph_name: self.to_term(&Reflect::get(value, &self.graph)?)?,
}) })
} }
} }

@ -149,7 +149,7 @@ impl JsMemoryStore {
None None
} else if base_iri.is_string() { } else if base_iri.is_string() {
base_iri.as_string() base_iri.as_string()
} else if let JsTerm::NamedNode(base_iri) = self.from_js.to_term(&base_iri)? { } else if let JsTerm::NamedNode(base_iri) = self.from_js.to_term(base_iri)? {
Some(base_iri.value()) Some(base_iri.value())
} else { } else {
return Err(format_err!( return Err(format_err!(

@ -101,7 +101,7 @@
// clippy::panic, does not work well with tests // clippy::panic, does not work well with tests
clippy::path_buf_push_overwrite, clippy::path_buf_push_overwrite,
clippy::print_stdout, clippy::print_stdout,
clippy::pub_enum_variant_names, clippy::enum_variant_names,
//TODO clippy::redundant_closure_for_method_calls, //TODO clippy::redundant_closure_for_method_calls,
// clippy::shadow_reuse, // clippy::shadow_reuse,
// clippy::shadow_same, // clippy::shadow_same,
@ -116,7 +116,7 @@
clippy::unseparated_literal_suffix, clippy::unseparated_literal_suffix,
clippy::used_underscore_binding, clippy::used_underscore_binding,
clippy::wildcard_dependencies, clippy::wildcard_dependencies,
clippy::wrong_pub_self_convention, clippy::wrong_self_convention,
)] )]
#![doc(test(attr(deny(warnings))))] #![doc(test(attr(deny(warnings))))]

@ -2562,7 +2562,7 @@ where
type Item = Result<EncodedTuple<S::StrId>, EvaluationError>; type Item = Result<EncodedTuple<S::StrId>, EvaluationError>;
fn next(&mut self) -> Option<Result<EncodedTuple<S::StrId>, EvaluationError>> { fn next(&mut self) -> Option<Result<EncodedTuple<S::StrId>, EvaluationError>> {
while let Some(right_tuple) = self.current_right.next() { for right_tuple in &mut self.current_right {
match right_tuple { match right_tuple {
Ok(right_tuple) => { Ok(right_tuple) => {
if let Some(combined) = combine_tuples( if let Some(combined) = combine_tuples(
@ -2581,7 +2581,7 @@ where
let mut filtered_left = left_tuple.clone(); let mut filtered_left = left_tuple.clone();
unbind_variables(&mut filtered_left, &self.problem_vars); unbind_variables(&mut filtered_left, &self.problem_vars);
self.current_right = self.eval.eval_plan(&self.right_plan, filtered_left); self.current_right = self.eval.eval_plan(&self.right_plan, filtered_left);
while let Some(right_tuple) = self.current_right.next() { for right_tuple in &mut self.current_right {
match right_tuple { match right_tuple {
Ok(right_tuple) => { Ok(right_tuple) => {
if let Some(combined) = if let Some(combined) =

@ -63,7 +63,7 @@ pub async fn main() -> Result<()> {
let store = Store::open(file)?; let store = Store::open(file)?;
println!("Listening for requests at http://{}", &bind); println!("Listening for requests at http://{}", &bind);
http_server(&bind, move |request| handle_request(request, store.clone())).await http_server(bind, move |request| handle_request(request, store.clone())).await
} }
async fn handle_request(request: Request, store: Store) -> Result<Response> { async fn handle_request(request: Request, store: Store) -> Result<Response> {

@ -28,7 +28,7 @@ fn sparql_w3c_syntax_bench(c: &mut Criterion) {
c.bench_function("query parser", |b| { c.bench_function("query parser", |b| {
b.iter(|| { b.iter(|| {
for (query, base) in &queries { for (query, base) in &queries {
Query::parse(query, Some(&base)).unwrap(); Query::parse(query, Some(base)).unwrap();
} }
}) })
}); });

@ -309,9 +309,9 @@ impl<'a> Iterator for RdfListIterator<'a> {
fn next(&mut self) -> Option<Term> { fn next(&mut self) -> Option<Term> {
match self.current_node.clone() { match self.current_node.clone() {
Some(current) => { Some(current) => {
let result = object_for_subject_predicate(&self.graph, &current, rdf::FIRST); let result = object_for_subject_predicate(self.graph, &current, rdf::FIRST);
self.current_node = self.current_node =
match object_for_subject_predicate(&self.graph, &current, rdf::REST) { match object_for_subject_predicate(self.graph, &current, rdf::REST) {
Some(Term::NamedNode(n)) if n == rdf::NIL => None, Some(Term::NamedNode(n)) if n == rdf::NIL => None,
Some(Term::NamedNode(n)) => Some(n.into()), Some(Term::NamedNode(n)) => Some(n.into()),
Some(Term::BlankNode(n)) => Some(n.into()), Some(Term::BlankNode(n)) => Some(n.into()),

@ -38,7 +38,7 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> {
.action .action
.as_deref() .as_deref()
.ok_or_else(|| anyhow!("No action found for test {}", test))?; .ok_or_else(|| anyhow!("No action found for test {}", test))?;
match Query::parse(&read_file_to_string(&query_file)?, Some(&query_file)) { match Query::parse(&read_file_to_string(query_file)?, Some(query_file)) {
Err(error) => Err(anyhow!("Not able to parse {} with error: {}", test, error)), Err(error) => Err(anyhow!("Not able to parse {} with error: {}", test, error)),
Ok(query) => match Query::parse(&query.to_string(), None) { Ok(query) => match Query::parse(&query.to_string(), None) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
@ -160,7 +160,7 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> {
.action .action
.as_deref() .as_deref()
.ok_or_else(|| anyhow!("No action found for test {}", test))?; .ok_or_else(|| anyhow!("No action found for test {}", test))?;
match Update::parse(&read_file_to_string(&update_file)?, Some(&update_file)) { match Update::parse(&read_file_to_string(update_file)?, Some(update_file)) {
Err(error) => Err(anyhow!("Not able to parse {} with error: {}", test, error)), Err(error) => Err(anyhow!("Not able to parse {} with error: {}", test, error)),
Ok(update) => match Update::parse(&update.to_string(), None) { Ok(update) => match Update::parse(&update.to_string(), None) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
@ -277,7 +277,7 @@ impl StaticServiceHandler {
.map(|(name, data)| { .map(|(name, data)| {
let name = NamedNode::new(name)?; let name = NamedNode::new(name)?;
let store = MemoryStore::new(); let store = MemoryStore::new();
load_to_store(&data, &store, &GraphName::DefaultGraph)?; load_to_store(data, &store, &GraphName::DefaultGraph)?;
Ok((name, store)) Ok((name, store))
}) })
.collect::<Result<_>>()?, .collect::<Result<_>>()?,
@ -423,7 +423,7 @@ fn are_query_results_isomorphic(
expected == actual expected == actual
} }
(StaticQueryResults::Graph(expected), StaticQueryResults::Graph(actual)) => { (StaticQueryResults::Graph(expected), StaticQueryResults::Graph(actual)) => {
expected.is_isomorphic(&actual) expected.is_isomorphic(actual)
} }
_ => false, _ => false,
} }
@ -544,7 +544,7 @@ impl StaticQueryResults {
} }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
bindings.sort_by(|(a, _), (b, _)| a.cmp(&b)); bindings.sort_by(|(a, _), (b, _)| a.cmp(b));
let index = let index =
object_for_subject_predicate(&dataset, &solution, rs::INDEX) object_for_subject_predicate(&dataset, &solution, rs::INDEX)
.and_then(|object| { .and_then(|object| {

@ -102,8 +102,8 @@ pub async fn main() -> Result<()> {
let repo = store.clone(); let repo = store.clone();
let mut loader = WikibaseLoader::new( let mut loader = WikibaseLoader::new(
repo, repo,
&mediawiki_api, mediawiki_api,
&mediawiki_base_url, mediawiki_base_url,
&namespaces, &namespaces,
slot.as_deref(), slot.as_deref(),
Duration::new(10, 0), Duration::new(10, 0),
@ -116,7 +116,7 @@ pub async fn main() -> Result<()> {
println!("Listening for requests at http://{}", &bind); println!("Listening for requests at http://{}", &bind);
http_server(&bind, move |request| handle_request(request, store.clone())).await http_server(bind, move |request| handle_request(request, store.clone())).await
} }
async fn handle_request(request: Request, store: RocksDbStore) -> Result<Response> { async fn handle_request(request: Request, store: RocksDbStore) -> Result<Response> {

Loading…
Cancel
Save