Apache DataFusion SQL Query Engine
ARROW-11137: [Rust][DataFusion] Clippy needless_range_loop,needless_lifetimes
Heres, Daniel7e47d04fc241
diff --git a/rust/datafusion/src/lib.rs b/rust/datafusion/src/lib.rsindex d3982ba8ce..3dec1d8ebf 100644--- a/rust/datafusion/src/lib.rs+++ b/rust/datafusion/src/lib.rs@@ -19,8 +19,6 @@#![allow(clippy::float_cmp,clippy::module_inception,- clippy::needless_lifetimes,- clippy::needless_range_loop,clippy::new_without_default,clippy::ptr_arg,clippy::type_complexitydiff --git a/rust/datafusion/src/logical_plan/display.rs b/rust/datafusion/src/logical_plan/display.rsindex 9e2118dacf..76749b547a 100644--- a/rust/datafusion/src/logical_plan/display.rs+++ b/rust/datafusion/src/logical_plan/display.rs@@ -100,7 +100,7 @@ impl<'a, 'b> PlanVisitor for IndentVisitor<'a, 'b> {/// format!("{}", display_schema(&schema))/// );/// ```-pub fn display_schema<'a>(schema: &'a Schema) -> impl fmt::Display + 'a {+pub fn display_schema(schema: &Schema) -> impl fmt::Display + '_ {struct Wrapper<'a>(&'a Schema);impl<'a> fmt::Display for Wrapper<'a> {diff --git a/rust/datafusion/src/logical_plan/plan.rs b/rust/datafusion/src/logical_plan/plan.rsindex bd172b3132..f120548d5e 100644--- a/rust/datafusion/src/logical_plan/plan.rs+++ b/rust/datafusion/src/logical_plan/plan.rs@@ -341,7 +341,7 @@ impl LogicalPlan {/// \n TableScan: foo.csv projection=None",/// display_string);/// ```- pub fn display_indent<'a>(&'a self) -> impl fmt::Display + 'a {+ pub fn display_indent(&self) -> impl fmt::Display + '_ {// Boilerplate structure to wrap LogicalPlan with something// that that can be formattedstruct Wrapper<'a>(&'a LogicalPlan);@@ -382,7 +382,7 @@ impl LogicalPlan {/// \n TableScan: foo.csv projection=None [id:Int32]",/// display_string);/// ```- pub fn display_indent_schema<'a>(&'a self) -> impl fmt::Display + 'a {+ pub fn display_indent_schema(&self) -> impl fmt::Display + '_ {// Boilerplate structure to wrap LogicalPlan with something// that that can be formattedstruct Wrapper<'a>(&'a LogicalPlan);@@ -426,7 +426,7 @@ impl LogicalPlan {/// dot -Tpdf < /tmp/example.dot > /tmp/example.pdf/// ```///- pub fn display_graphviz<'a>(&'a self) -> impl fmt::Display + 'a {+ pub fn display_graphviz(&self) -> impl fmt::Display + '_ {// Boilerplate structure to wrap LogicalPlan with something// that that can be formattedstruct Wrapper<'a>(&'a LogicalPlan);@@ -478,7 +478,7 @@ impl LogicalPlan {////// assert_eq!("TableScan: foo.csv projection=None", display_string);/// ```- pub fn display<'a>(&'a self) -> impl fmt::Display + 'a {+ pub fn display(&self) -> impl fmt::Display + '_ {// Boilerplate structure to wrap LogicalPlan with something// that that can be formattedstruct Wrapper<'a>(&'a LogicalPlan);@@ -507,11 +507,11 @@ impl LogicalPlan {}LogicalPlan::Projection { ref expr, .. } => {write!(f, "Projection: ")?;- for i in 0..expr.len() {+ for (i, expr_item) in expr.iter().enumerate() {if i > 0 {write!(f, ", ")?;}- write!(f, "{:?}", expr[i])?;+ write!(f, "{:?}", expr_item)?;}Ok(())}@@ -530,11 +530,11 @@ impl LogicalPlan {),LogicalPlan::Sort { ref expr, .. } => {write!(f, "Sort: ")?;- for i in 0..expr.len() {+ for (i, expr_item) in expr.iter().enumerate() {if i > 0 {write!(f, ", ")?;}- write!(f, "{:?}", expr[i])?;+ write!(f, "{:?}", expr_item)?;}Ok(())}diff --git a/rust/datafusion/src/physical_plan/expressions.rs b/rust/datafusion/src/physical_plan/expressions.rsindex b0bbd77e31..468e4a2d16 100644--- a/rust/datafusion/src/physical_plan/expressions.rs+++ b/rust/datafusion/src/physical_plan/expressions.rs@@ -2458,8 +2458,8 @@ mod tests {.as_any().downcast_ref::<BooleanArray>().expect("failed to downcast to BooleanArray");- for i in 0..5 {- assert_eq!(result.value(i), expected[i]);+ for (i, &expected_item) in expected.iter().enumerate().take(5) {+ assert_eq!(result.value(i), expected_item);}Ok(())@@ -2492,8 +2492,8 @@ mod tests {.as_any().downcast_ref::<BooleanArray>().expect("failed to downcast to BooleanArray");- for i in 0..5 {- assert_eq!(result.value(i), expected[i]);+ for (i, &expected_item) in expected.iter().enumerate().take(5) {+ assert_eq!(result.value(i), expected_item);}Ok(())diff --git a/rust/datafusion/src/physical_plan/hash_join.rs b/rust/datafusion/src/physical_plan/hash_join.rsindex 50800df909..ac32c27821 100644--- a/rust/datafusion/src/physical_plan/hash_join.rs+++ b/rust/datafusion/src/physical_plan/hash_join.rs@@ -369,8 +369,7 @@ pub(crate) fn create_key(vec: &mut Vec<u8>,) -> Result<()> {vec.clear();- for i in 0..group_by_keys.len() {- let col = &group_by_keys[i];+ for col in group_by_keys {match col.data_type() {DataType::UInt8 => {let array = col.as_any().downcast_ref::<UInt8Array>().unwrap();diff --git a/rust/datafusion/src/physical_plan/repartition.rs b/rust/datafusion/src/physical_plan/repartition.rsindex fb975034a3..1ec1727f2a 100644--- a/rust/datafusion/src/physical_plan/repartition.rs+++ b/rust/datafusion/src/physical_plan/repartition.rs@@ -138,8 +138,8 @@ impl ExecutionPlan for RepartitionExec {}// notify each output partition that this input partition has no more data- for i in 0..num_output_partitions {- let tx = &mut channels[i].0;+ for channel in channels.iter_mut().take(num_output_partitions) {+ let tx = &mut channel.0;tx.send(None).map_err(|e| DataFusionError::Execution(e.to_string()))?;}diff --git a/rust/datafusion/src/sql/planner.rs b/rust/datafusion/src/sql/planner.rsindex 78f3b8fab4..dafff3dcf7 100644--- a/rust/datafusion/src/sql/planner.rs+++ b/rust/datafusion/src/sql/planner.rs@@ -366,8 +366,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {let mut all_join_keys = vec![];let mut left = plans[0].clone();- for i in 1..plans.len() {- let right = &plans[i];+ for right in plans.iter().skip(1) {let left_schema = left.schema();let right_schema = right.schema();let mut join_keys = vec![];@@ -644,9 +643,8 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {SQLExpr::CompoundIdentifier(ids) => {let mut var_names = vec![];- for i in 0..ids.len() {- let id = ids[i].clone();- var_names.push(id.value);+ for id in ids {+ var_names.push(id.value.clone());}if &var_names[0][0..1] == "@" {Ok(Expr::ScalarVariable(var_names))