From ec2b3072555a2449d0bc9951580344f3693be005 Mon Sep 17 00:00:00 2001 From: Tpt Date: Thu, 29 Jul 2021 21:20:11 +0200 Subject: [PATCH] Fixes Clippy warnings --- js/src/model.rs | 33 +++++++++++++++---------------- js/src/store.rs | 2 +- lib/src/lib.rs | 4 ++-- lib/src/sparql/eval.rs | 4 ++-- server/src/main.rs | 2 +- testsuite/benches/sparql_query.rs | 2 +- testsuite/src/manifest.rs | 4 ++-- testsuite/src/sparql_evaluator.rs | 10 +++++----- wikibase/src/main.rs | 6 +++--- 9 files changed, 33 insertions(+), 34 deletions(-) diff --git a/js/src/model.rs b/js/src/model.rs index 7c690550..ebefe7cc 100644 --- a/js/src/model.rs +++ b/js/src/model.rs @@ -87,7 +87,7 @@ impl JsDataFactory { graph_name: if graph.is_undefined() || graph.is_null() { JsTerm::DefaultGraph(JsDefaultGraph {}) } 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 { if let Ok(Some(JsTerm::NamedNode(other))) = - FromJsConverter::default().to_optional_term(&other) + FromJsConverter::default().to_optional_term(other) { self == &other } else { @@ -182,7 +182,7 @@ impl JsBlankNode { pub fn equals(&self, other: &JsValue) -> bool { if let Ok(Some(JsTerm::BlankNode(other))) = - FromJsConverter::default().to_optional_term(&other) + FromJsConverter::default().to_optional_term(other) { self == &other } else { @@ -250,8 +250,7 @@ impl JsLiteral { } pub fn equals(&self, other: &JsValue) -> bool { - if let Ok(Some(JsTerm::Literal(other))) = - FromJsConverter::default().to_optional_term(&other) + if let Ok(Some(JsTerm::Literal(other))) = FromJsConverter::default().to_optional_term(other) { self == &other } else { @@ -296,7 +295,7 @@ impl JsDefaultGraph { pub fn equals(&self, other: &JsValue) -> bool { if let Ok(Some(JsTerm::DefaultGraph(other))) = - FromJsConverter::default().to_optional_term(&other) + FromJsConverter::default().to_optional_term(other) { self == &other } else { @@ -472,7 +471,7 @@ impl JsQuad { pub fn equals(&self, other: &JsValue) -> bool { FromJsConverter::default() - .to_quad(&other) + .to_quad(other) .map_or(false, |other| self == &other) } } @@ -529,18 +528,18 @@ impl Default for FromJsConverter { impl FromJsConverter { pub fn to_term(&self, value: &JsValue) -> Result { - 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() { match term_type.as_str() { "NamedNode" => Ok(NamedNode::new( - Reflect::get(&value, &self.value)? + Reflect::get(value, &self.value)? .as_string() .ok_or_else(|| format_err!("NamedNode should have a string value"))?, ) .map_err(|v| UriError::new(&v.to_string()))? .into()), "BlankNode" => Ok(BlankNode::new( - &Reflect::get(&value, &self.value)? + &Reflect::get(value, &self.value)? .as_string() .ok_or_else(|| format_err!("BlankNode should have a string value"))?, ) @@ -548,15 +547,15 @@ impl FromJsConverter { .into()), "Literal" => { 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 literal_value = Reflect::get(&value, &self.value)? + let literal_value = Reflect::get(value, &self.value)? .as_string() .ok_or_else(|| format_err!("Literal should have a string value"))?; Ok(match datatype.as_str() { "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"), )?).map_err(to_err)?, _ => Literal::new_typed_literal(literal_value, datatype) @@ -588,10 +587,10 @@ impl FromJsConverter { pub fn to_quad(&self, value: &JsValue) -> Result { Ok(JsQuad { - subject: self.to_term(&Reflect::get(&value, &self.subject)?)?, - predicate: self.to_term(&Reflect::get(&value, &self.predicate)?)?, - object: self.to_term(&Reflect::get(&value, &self.object)?)?, - graph_name: self.to_term(&Reflect::get(&value, &self.graph)?)?, + subject: self.to_term(&Reflect::get(value, &self.subject)?)?, + predicate: self.to_term(&Reflect::get(value, &self.predicate)?)?, + object: self.to_term(&Reflect::get(value, &self.object)?)?, + graph_name: self.to_term(&Reflect::get(value, &self.graph)?)?, }) } } diff --git a/js/src/store.rs b/js/src/store.rs index 952aa423..dca00776 100644 --- a/js/src/store.rs +++ b/js/src/store.rs @@ -149,7 +149,7 @@ impl JsMemoryStore { None } else if base_iri.is_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()) } else { return Err(format_err!( diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 2c5af743..f7eecebb 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -101,7 +101,7 @@ // clippy::panic, does not work well with tests clippy::path_buf_push_overwrite, clippy::print_stdout, - clippy::pub_enum_variant_names, + clippy::enum_variant_names, //TODO clippy::redundant_closure_for_method_calls, // clippy::shadow_reuse, // clippy::shadow_same, @@ -116,7 +116,7 @@ clippy::unseparated_literal_suffix, clippy::used_underscore_binding, clippy::wildcard_dependencies, - clippy::wrong_pub_self_convention, + clippy::wrong_self_convention, )] #![doc(test(attr(deny(warnings))))] diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 139bef72..3283a9b5 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -2562,7 +2562,7 @@ where type Item = Result, EvaluationError>; fn next(&mut self) -> Option, EvaluationError>> { - while let Some(right_tuple) = self.current_right.next() { + for right_tuple in &mut self.current_right { match right_tuple { Ok(right_tuple) => { if let Some(combined) = combine_tuples( @@ -2581,7 +2581,7 @@ where let mut filtered_left = left_tuple.clone(); unbind_variables(&mut filtered_left, &self.problem_vars); 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 { Ok(right_tuple) => { if let Some(combined) = diff --git a/server/src/main.rs b/server/src/main.rs index fa5ea18a..0a8d654a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -63,7 +63,7 @@ pub async fn main() -> Result<()> { let store = Store::open(file)?; 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 { diff --git a/testsuite/benches/sparql_query.rs b/testsuite/benches/sparql_query.rs index f0961308..a19c4392 100644 --- a/testsuite/benches/sparql_query.rs +++ b/testsuite/benches/sparql_query.rs @@ -28,7 +28,7 @@ fn sparql_w3c_syntax_bench(c: &mut Criterion) { c.bench_function("query parser", |b| { b.iter(|| { for (query, base) in &queries { - Query::parse(query, Some(&base)).unwrap(); + Query::parse(query, Some(base)).unwrap(); } }) }); diff --git a/testsuite/src/manifest.rs b/testsuite/src/manifest.rs index 9dbcb222..1f431de4 100644 --- a/testsuite/src/manifest.rs +++ b/testsuite/src/manifest.rs @@ -309,9 +309,9 @@ impl<'a> Iterator for RdfListIterator<'a> { fn next(&mut self) -> Option { match self.current_node.clone() { Some(current) => { - let result = object_for_subject_predicate(&self.graph, ¤t, rdf::FIRST); + let result = object_for_subject_predicate(self.graph, ¤t, rdf::FIRST); self.current_node = - match object_for_subject_predicate(&self.graph, ¤t, rdf::REST) { + match object_for_subject_predicate(self.graph, ¤t, rdf::REST) { Some(Term::NamedNode(n)) if n == rdf::NIL => None, Some(Term::NamedNode(n)) => Some(n.into()), Some(Term::BlankNode(n)) => Some(n.into()), diff --git a/testsuite/src/sparql_evaluator.rs b/testsuite/src/sparql_evaluator.rs index 767617ae..7003720b 100644 --- a/testsuite/src/sparql_evaluator.rs +++ b/testsuite/src/sparql_evaluator.rs @@ -38,7 +38,7 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { .action .as_deref() .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)), Ok(query) => match Query::parse(&query.to_string(), None) { Ok(_) => Ok(()), @@ -160,7 +160,7 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> { .action .as_deref() .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)), Ok(update) => match Update::parse(&update.to_string(), None) { Ok(_) => Ok(()), @@ -277,7 +277,7 @@ impl StaticServiceHandler { .map(|(name, data)| { let name = NamedNode::new(name)?; let store = MemoryStore::new(); - load_to_store(&data, &store, &GraphName::DefaultGraph)?; + load_to_store(data, &store, &GraphName::DefaultGraph)?; Ok((name, store)) }) .collect::>()?, @@ -423,7 +423,7 @@ fn are_query_results_isomorphic( expected == actual } (StaticQueryResults::Graph(expected), StaticQueryResults::Graph(actual)) => { - expected.is_isomorphic(&actual) + expected.is_isomorphic(actual) } _ => false, } @@ -544,7 +544,7 @@ impl StaticQueryResults { } }) .collect::>(); - bindings.sort_by(|(a, _), (b, _)| a.cmp(&b)); + bindings.sort_by(|(a, _), (b, _)| a.cmp(b)); let index = object_for_subject_predicate(&dataset, &solution, rs::INDEX) .and_then(|object| { diff --git a/wikibase/src/main.rs b/wikibase/src/main.rs index e688f14a..0ce52097 100644 --- a/wikibase/src/main.rs +++ b/wikibase/src/main.rs @@ -102,8 +102,8 @@ pub async fn main() -> Result<()> { let repo = store.clone(); let mut loader = WikibaseLoader::new( repo, - &mediawiki_api, - &mediawiki_base_url, + mediawiki_api, + mediawiki_base_url, &namespaces, slot.as_deref(), Duration::new(10, 0), @@ -116,7 +116,7 @@ pub async fn main() -> Result<()> { 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 {