diff --git a/examples/cli.rs b/examples/cli.rs index fcaf1b144..53ef1abb1 100644 --- a/examples/cli.rs +++ b/examples/cli.rs @@ -46,7 +46,7 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname] "--hive" => Box::new(HiveDialect {}), "--redshift" => Box::new(RedshiftSqlDialect {}), "--generic" | "" => Box::new(GenericDialect {}), - s => panic!("Unexpected parameter: {}", s), + s => panic!("Unexpected parameter: {s}"), }; println!("Parsing from file '{}' using {:?}", &filename, dialect); @@ -75,16 +75,16 @@ $ cargo run --feature json_example --example cli FILENAME.sql [--dialectname] #[cfg(feature = "json_example")] { let serialized = serde_json::to_string_pretty(&statements).unwrap(); - println!("Serialized as JSON:\n{}", serialized); + println!("Serialized as JSON:\n{serialized}"); } } else { - println!("Parse results:\n{:#?}", statements); + println!("Parse results:\n{statements:#?}"); } std::process::exit(0); } Err(e) => { - println!("Error during parsing: {:?}", e); + println!("Error during parsing: {e:?}"); std::process::exit(1); } } diff --git a/examples/parse_select.rs b/examples/parse_select.rs index e7aa16307..71fe1fa1e 100644 --- a/examples/parse_select.rs +++ b/examples/parse_select.rs @@ -25,5 +25,5 @@ fn main() { let ast = Parser::parse_sql(&dialect, sql).unwrap(); - println!("AST: {:?}", ast); + println!("AST: {ast:?}"); } diff --git a/src/ast/data_type.rs b/src/ast/data_type.rs index ba90659ab..ec5f256f2 100644 --- a/src/ast/data_type.rs +++ b/src/ast/data_type.rs @@ -186,13 +186,13 @@ impl fmt::Display for DataType { } DataType::Blob(size) => format_type_with_optional_length(f, "BLOB", size, false), DataType::Numeric(info) => { - write!(f, "NUMERIC{}", info) + write!(f, "NUMERIC{info}") } DataType::Decimal(info) => { - write!(f, "DECIMAL{}", info) + write!(f, "DECIMAL{info}") } DataType::Dec(info) => { - write!(f, "DEC{}", info) + write!(f, "DEC{info}") } DataType::Float(size) => format_type_with_optional_length(f, "FLOAT", size, false), DataType::TinyInt(zerofill) => { @@ -250,14 +250,14 @@ impl fmt::Display for DataType { DataType::Bytea => write!(f, "BYTEA"), DataType::Array(ty) => { if let Some(t) = &ty { - write!(f, "{}[]", t) + write!(f, "{t}[]") } else { write!(f, "ARRAY") } } DataType::Custom(ty, modifiers) => { if modifiers.is_empty() { - write!(f, "{}", ty) + write!(f, "{ty}") } else { write!(f, "{}({})", ty, modifiers.join(", ")) } @@ -292,9 +292,9 @@ fn format_type_with_optional_length( len: &Option, unsigned: bool, ) -> fmt::Result { - write!(f, "{}", sql_type)?; + write!(f, "{sql_type}")?; if let Some(len) = len { - write!(f, "({})", len)?; + write!(f, "({len})")?; } if unsigned { write!(f, " UNSIGNED")?; @@ -307,9 +307,9 @@ fn format_character_string_type( sql_type: &str, size: &Option, ) -> fmt::Result { - write!(f, "{}", sql_type)?; + write!(f, "{sql_type}")?; if let Some(size) = size { - write!(f, "({})", size)?; + write!(f, "({size})")?; } Ok(()) } @@ -320,7 +320,7 @@ fn format_datetime_precision_and_tz( len: &Option, time_zone: &TimezoneInfo, ) -> fmt::Result { - write!(f, "{}", sql_type)?; + write!(f, "{sql_type}")?; let len_fmt = len.as_ref().map(|l| format!("({l})")).unwrap_or_default(); match time_zone { @@ -432,7 +432,7 @@ impl fmt::Display for CharacterLength { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.length)?; if let Some(unit) = &self.unit { - write!(f, " {}", unit)?; + write!(f, " {unit}")?; } Ok(()) } diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 8576d7277..31e944b6b 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -117,7 +117,7 @@ impl fmt::Display for AlterTableOperation { display_comma_separated(new_partitions), ine = if *if_not_exists { " IF NOT EXISTS" } else { "" } ), - AlterTableOperation::AddConstraint(c) => write!(f, "ADD {}", c), + AlterTableOperation::AddConstraint(c) => write!(f, "ADD {c}"), AlterTableOperation::AddColumn { column_keyword, if_not_exists, @@ -135,7 +135,7 @@ impl fmt::Display for AlterTableOperation { Ok(()) } AlterTableOperation::AlterColumn { column_name, op } => { - write!(f, "ALTER COLUMN {} {}", column_name, op) + write!(f, "ALTER COLUMN {column_name} {op}") } AlterTableOperation::DropPartitions { partitions, @@ -183,13 +183,9 @@ impl fmt::Display for AlterTableOperation { AlterTableOperation::RenameColumn { old_column_name, new_column_name, - } => write!( - f, - "RENAME COLUMN {} TO {}", - old_column_name, new_column_name - ), + } => write!(f, "RENAME COLUMN {old_column_name} TO {new_column_name}"), AlterTableOperation::RenameTable { table_name } => { - write!(f, "RENAME TO {}", table_name) + write!(f, "RENAME TO {table_name}") } AlterTableOperation::ChangeColumn { old_name, @@ -197,7 +193,7 @@ impl fmt::Display for AlterTableOperation { data_type, options, } => { - write!(f, "CHANGE COLUMN {} {} {}", old_name, new_name, data_type)?; + write!(f, "CHANGE COLUMN {old_name} {new_name} {data_type}")?; if options.is_empty() { Ok(()) } else { @@ -205,7 +201,7 @@ impl fmt::Display for AlterTableOperation { } } AlterTableOperation::RenameConstraint { old_name, new_name } => { - write!(f, "RENAME CONSTRAINT {} TO {}", old_name, new_name) + write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}") } } } @@ -215,7 +211,7 @@ impl fmt::Display for AlterIndexOperation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { AlterIndexOperation::RenameIndex { index_name } => { - write!(f, "RENAME TO {}", index_name) + write!(f, "RENAME TO {index_name}") } } } @@ -248,16 +244,16 @@ impl fmt::Display for AlterColumnOperation { AlterColumnOperation::SetNotNull => write!(f, "SET NOT NULL",), AlterColumnOperation::DropNotNull => write!(f, "DROP NOT NULL",), AlterColumnOperation::SetDefault { value } => { - write!(f, "SET DEFAULT {}", value) + write!(f, "SET DEFAULT {value}") } AlterColumnOperation::DropDefault {} => { write!(f, "DROP DEFAULT") } AlterColumnOperation::SetDataType { data_type, using } => { if let Some(expr) = using { - write!(f, "SET DATA TYPE {} USING {}", data_type, expr) + write!(f, "SET DATA TYPE {data_type} USING {expr}") } else { - write!(f, "SET DATA TYPE {}", data_type) + write!(f, "SET DATA TYPE {data_type}") } } } @@ -369,10 +365,10 @@ impl fmt::Display for TableConstraint { display_comma_separated(referred_columns), )?; if let Some(action) = on_delete { - write!(f, " ON DELETE {}", action)?; + write!(f, " ON DELETE {action}")?; } if let Some(action) = on_update { - write!(f, " ON UPDATE {}", action)?; + write!(f, " ON UPDATE {action}")?; } Ok(()) } @@ -387,10 +383,10 @@ impl fmt::Display for TableConstraint { } => { write!(f, "{}", if *display_as_key { "KEY" } else { "INDEX" })?; if let Some(name) = name { - write!(f, " {}", name)?; + write!(f, " {name}")?; } if let Some(index_type) = index_type { - write!(f, " USING {}", index_type)?; + write!(f, " USING {index_type}")?; } write!(f, " ({})", display_comma_separated(columns))?; @@ -409,11 +405,11 @@ impl fmt::Display for TableConstraint { } if !matches!(index_type_display, KeyOrIndexDisplay::None) { - write!(f, " {}", index_type_display)?; + write!(f, " {index_type_display}")?; } if let Some(name) = opt_index_name { - write!(f, " {}", name)?; + write!(f, " {name}")?; } write!(f, " ({})", display_comma_separated(columns))?; @@ -500,7 +496,7 @@ impl fmt::Display for ColumnDef { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{} {}", self.name, self.data_type)?; for option in &self.options { - write!(f, " {}", option)?; + write!(f, " {option}")?; } Ok(()) } @@ -580,7 +576,7 @@ impl fmt::Display for ColumnOption { match self { Null => write!(f, "NULL"), NotNull => write!(f, "NOT NULL"), - Default(expr) => write!(f, "DEFAULT {}", expr), + Default(expr) => write!(f, "DEFAULT {expr}"), Unique { is_primary } => { write!(f, "{}", if *is_primary { "PRIMARY KEY" } else { "UNIQUE" }) } @@ -590,23 +586,23 @@ impl fmt::Display for ColumnOption { on_delete, on_update, } => { - write!(f, "REFERENCES {}", foreign_table)?; + write!(f, "REFERENCES {foreign_table}")?; if !referred_columns.is_empty() { write!(f, " ({})", display_comma_separated(referred_columns))?; } if let Some(action) = on_delete { - write!(f, " ON DELETE {}", action)?; + write!(f, " ON DELETE {action}")?; } if let Some(action) = on_update { - write!(f, " ON UPDATE {}", action)?; + write!(f, " ON UPDATE {action}")?; } Ok(()) } - Check(expr) => write!(f, "CHECK ({})", expr), + Check(expr) => write!(f, "CHECK ({expr})"), DialectSpecific(val) => write!(f, "{}", display_separated(val, " ")), - CharacterSet(n) => write!(f, "CHARACTER SET {}", n), + CharacterSet(n) => write!(f, "CHARACTER SET {n}"), Comment(v) => write!(f, "COMMENT '{}'", escape_single_quote_string(v)), - OnUpdate(expr) => write!(f, "ON UPDATE {}", expr), + OnUpdate(expr) => write!(f, "ON UPDATE {expr}"), } } } @@ -616,7 +612,7 @@ fn display_constraint_name(name: &'_ Option) -> impl fmt::Display + '_ { impl<'a> fmt::Display for ConstraintName<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.0 { - write!(f, "CONSTRAINT {} ", name)?; + write!(f, "CONSTRAINT {name} ")?; } Ok(()) } diff --git a/src/ast/mod.rs b/src/ast/mod.rs index b8d5cf042..a8c934396 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -71,9 +71,9 @@ where fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let mut delim = ""; for t in self.slice { - write!(f, "{}", delim)?; + write!(f, "{delim}")?; delim = self.sep; - write!(f, "{}", t)?; + write!(f, "{t}")?; } Ok(()) } @@ -145,7 +145,7 @@ impl fmt::Display for Ident { match self.quote_style { Some(q) if q == '"' || q == '\'' || q == '`' => { let escaped = value::escape_quoted_string(&self.value, q); - write!(f, "{}{}{}", q, escaped, q) + write!(f, "{q}{escaped}{q}") } Some(q) if q == '[' => write!(f, "[{}]", self.value), None => f.write_str(&self.value), @@ -529,27 +529,27 @@ pub enum Expr { impl fmt::Display for Expr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Expr::Identifier(s) => write!(f, "{}", s), + Expr::Identifier(s) => write!(f, "{s}"), Expr::MapAccess { column, keys } => { - write!(f, "{}", column)?; + write!(f, "{column}")?; for k in keys { match k { - k @ Expr::Value(Value::Number(_, _)) => write!(f, "[{}]", k)?, - Expr::Value(Value::SingleQuotedString(s)) => write!(f, "[\"{}\"]", s)?, - _ => write!(f, "[{}]", k)?, + k @ Expr::Value(Value::Number(_, _)) => write!(f, "[{k}]")?, + Expr::Value(Value::SingleQuotedString(s)) => write!(f, "[\"{s}\"]")?, + _ => write!(f, "[{k}]")?, } } Ok(()) } Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")), - Expr::IsTrue(ast) => write!(f, "{} IS TRUE", ast), - Expr::IsNotTrue(ast) => write!(f, "{} IS NOT TRUE", ast), - Expr::IsFalse(ast) => write!(f, "{} IS FALSE", ast), - Expr::IsNotFalse(ast) => write!(f, "{} IS NOT FALSE", ast), - Expr::IsNull(ast) => write!(f, "{} IS NULL", ast), - Expr::IsNotNull(ast) => write!(f, "{} IS NOT NULL", ast), - Expr::IsUnknown(ast) => write!(f, "{} IS UNKNOWN", ast), - Expr::IsNotUnknown(ast) => write!(f, "{} IS NOT UNKNOWN", ast), + Expr::IsTrue(ast) => write!(f, "{ast} IS TRUE"), + Expr::IsNotTrue(ast) => write!(f, "{ast} IS NOT TRUE"), + Expr::IsFalse(ast) => write!(f, "{ast} IS FALSE"), + Expr::IsNotFalse(ast) => write!(f, "{ast} IS NOT FALSE"), + Expr::IsNull(ast) => write!(f, "{ast} IS NULL"), + Expr::IsNotNull(ast) => write!(f, "{ast} IS NOT NULL"), + Expr::IsUnknown(ast) => write!(f, "{ast} IS UNKNOWN"), + Expr::IsNotUnknown(ast) => write!(f, "{ast} IS NOT UNKNOWN"), Expr::InList { expr, list, @@ -596,7 +596,7 @@ impl fmt::Display for Expr { low, high ), - Expr::BinaryOp { left, op, right } => write!(f, "{} {} {}", left, op, right), + Expr::BinaryOp { left, op, right } => write!(f, "{left} {op} {right}"), Expr::Like { negated, expr, @@ -663,46 +663,46 @@ impl fmt::Display for Expr { pattern ), }, - Expr::AnyOp(expr) => write!(f, "ANY({})", expr), - Expr::AllOp(expr) => write!(f, "ALL({})", expr), + Expr::AnyOp(expr) => write!(f, "ANY({expr})"), + Expr::AllOp(expr) => write!(f, "ALL({expr})"), Expr::UnaryOp { op, expr } => { if op == &UnaryOperator::PGPostfixFactorial { - write!(f, "{}{}", expr, op) + write!(f, "{expr}{op}") } else if op == &UnaryOperator::Not { - write!(f, "{} {}", op, expr) + write!(f, "{op} {expr}") } else { - write!(f, "{}{}", op, expr) + write!(f, "{op}{expr}") } } - Expr::Cast { expr, data_type } => write!(f, "CAST({} AS {})", expr, data_type), - Expr::TryCast { expr, data_type } => write!(f, "TRY_CAST({} AS {})", expr, data_type), - Expr::SafeCast { expr, data_type } => write!(f, "SAFE_CAST({} AS {})", expr, data_type), - Expr::Extract { field, expr } => write!(f, "EXTRACT({} FROM {})", field, expr), + Expr::Cast { expr, data_type } => write!(f, "CAST({expr} AS {data_type})"), + Expr::TryCast { expr, data_type } => write!(f, "TRY_CAST({expr} AS {data_type})"), + Expr::SafeCast { expr, data_type } => write!(f, "SAFE_CAST({expr} AS {data_type})"), + Expr::Extract { field, expr } => write!(f, "EXTRACT({field} FROM {expr})"), Expr::Ceil { expr, field } => { if field == &DateTimeField::NoDateTime { - write!(f, "CEIL({})", expr) + write!(f, "CEIL({expr})") } else { - write!(f, "CEIL({} TO {})", expr, field) + write!(f, "CEIL({expr} TO {field})") } } Expr::Floor { expr, field } => { if field == &DateTimeField::NoDateTime { - write!(f, "FLOOR({})", expr) + write!(f, "FLOOR({expr})") } else { - write!(f, "FLOOR({} TO {})", expr, field) + write!(f, "FLOOR({expr} TO {field})") } } - Expr::Position { expr, r#in } => write!(f, "POSITION({} IN {})", expr, r#in), - Expr::Collate { expr, collation } => write!(f, "{} COLLATE {}", expr, collation), - Expr::Nested(ast) => write!(f, "({})", ast), - Expr::Value(v) => write!(f, "{}", v), + Expr::Position { expr, r#in } => write!(f, "POSITION({expr} IN {in})"), + Expr::Collate { expr, collation } => write!(f, "{expr} COLLATE {collation}"), + Expr::Nested(ast) => write!(f, "({ast})"), + Expr::Value(v) => write!(f, "{v}"), Expr::TypedString { data_type, value } => { - write!(f, "{}", data_type)?; + write!(f, "{data_type}")?; write!(f, " '{}'", &value::escape_single_quote_string(value)) } - Expr::Function(fun) => write!(f, "{}", fun), + Expr::Function(fun) => write!(f, "{fun}"), Expr::AggregateExpressionWithFilter { expr, filter } => { - write!(f, "{} FILTER (WHERE {})", expr, filter) + write!(f, "{expr} FILTER (WHERE {filter})") } Expr::Case { operand, @@ -712,14 +712,14 @@ impl fmt::Display for Expr { } => { write!(f, "CASE")?; if let Some(operand) = operand { - write!(f, " {}", operand)?; + write!(f, " {operand}")?; } for (c, r) in conditions.iter().zip(results) { - write!(f, " WHEN {} THEN {}", c, r)?; + write!(f, " WHEN {c} THEN {r}")?; } if let Some(else_result) = else_result { - write!(f, " ELSE {}", else_result)?; + write!(f, " ELSE {else_result}")?; } write!(f, " END") } @@ -729,15 +729,15 @@ impl fmt::Display for Expr { if *negated { "NOT " } else { "" }, subquery ), - Expr::Subquery(s) => write!(f, "({})", s), - Expr::ArraySubquery(s) => write!(f, "ARRAY({})", s), - Expr::ListAgg(listagg) => write!(f, "{}", listagg), - Expr::ArrayAgg(arrayagg) => write!(f, "{}", arrayagg), + Expr::Subquery(s) => write!(f, "({s})"), + Expr::ArraySubquery(s) => write!(f, "ARRAY({s})"), + Expr::ListAgg(listagg) => write!(f, "{listagg}"), + Expr::ArrayAgg(arrayagg) => write!(f, "{arrayagg}"), Expr::GroupingSets(sets) => { write!(f, "GROUPING SETS (")?; let mut sep = ""; for set in sets { - write!(f, "{}", sep)?; + write!(f, "{sep}")?; sep = ", "; write!(f, "({})", display_comma_separated(set))?; } @@ -747,7 +747,7 @@ impl fmt::Display for Expr { write!(f, "CUBE (")?; let mut sep = ""; for set in sets { - write!(f, "{}", sep)?; + write!(f, "{sep}")?; sep = ", "; if set.len() == 1 { write!(f, "{}", set[0])?; @@ -761,7 +761,7 @@ impl fmt::Display for Expr { write!(f, "ROLLUP (")?; let mut sep = ""; for set in sets { - write!(f, "{}", sep)?; + write!(f, "{sep}")?; sep = ", "; if set.len() == 1 { write!(f, "{}", set[0])?; @@ -776,12 +776,12 @@ impl fmt::Display for Expr { substring_from, substring_for, } => { - write!(f, "SUBSTRING({}", expr)?; + write!(f, "SUBSTRING({expr}")?; if let Some(from_part) = substring_from { - write!(f, " FROM {}", from_part)?; + write!(f, " FROM {from_part}")?; } if let Some(for_part) = substring_for { - write!(f, " FOR {}", for_part)?; + write!(f, " FOR {for_part}")?; } write!(f, ")") @@ -794,17 +794,16 @@ impl fmt::Display for Expr { } => { write!( f, - "OVERLAY({} PLACING {} FROM {}", - expr, overlay_what, overlay_from + "OVERLAY({expr} PLACING {overlay_what} FROM {overlay_from}" )?; if let Some(for_part) = overlay_for { - write!(f, " FOR {}", for_part)?; + write!(f, " FOR {for_part}")?; } write!(f, ")") } - Expr::IsDistinctFrom(a, b) => write!(f, "{} IS DISTINCT FROM {}", a, b), - Expr::IsNotDistinctFrom(a, b) => write!(f, "{} IS NOT DISTINCT FROM {}", a, b), + Expr::IsDistinctFrom(a, b) => write!(f, "{a} IS DISTINCT FROM {b}"), + Expr::IsNotDistinctFrom(a, b) => write!(f, "{a} IS NOT DISTINCT FROM {b}"), Expr::Trim { expr, trim_where, @@ -812,12 +811,12 @@ impl fmt::Display for Expr { } => { write!(f, "TRIM(")?; if let Some(ident) = trim_where { - write!(f, "{} ", ident)?; + write!(f, "{ident} ")?; } if let Some(trim_char) = trim_what { - write!(f, "{} FROM {}", trim_char, expr)?; + write!(f, "{trim_char} FROM {expr}")?; } else { - write!(f, "{}", expr)?; + write!(f, "{expr}")?; } write!(f, ")") @@ -826,14 +825,14 @@ impl fmt::Display for Expr { write!(f, "({})", display_comma_separated(exprs)) } Expr::ArrayIndex { obj, indexes } => { - write!(f, "{}", obj)?; + write!(f, "{obj}")?; for i in indexes { - write!(f, "[{}]", i)?; + write!(f, "[{i}]")?; } Ok(()) } Expr::Array(set) => { - write!(f, "{}", set) + write!(f, "{set}") } Expr::JsonAccess { left, @@ -841,19 +840,19 @@ impl fmt::Display for Expr { right, } => { if operator == &JsonOperator::Colon { - write!(f, "{}{}{}", left, operator, right) + write!(f, "{left}{operator}{right}") } else { - write!(f, "{} {} {}", left, operator, right) + write!(f, "{left} {operator} {right}") } } Expr::CompositeAccess { expr, key } => { - write!(f, "{}.{}", expr, key) + write!(f, "{expr}.{key}") } Expr::AtTimeZone { timestamp, time_zone, } => { - write!(f, "{} AT TIME ZONE '{}'", timestamp, time_zone) + write!(f, "{timestamp} AT TIME ZONE '{time_zone}'") } Expr::Interval { value, @@ -867,8 +866,7 @@ impl fmt::Display for Expr { assert!(last_field.is_none()); write!( f, - "INTERVAL {} SECOND ({}, {})", - value, leading_precision, fractional_seconds_precision + "INTERVAL {value} SECOND ({leading_precision}, {fractional_seconds_precision})" ) } Expr::Interval { @@ -878,18 +876,18 @@ impl fmt::Display for Expr { last_field, fractional_seconds_precision, } => { - write!(f, "INTERVAL {}", value)?; + write!(f, "INTERVAL {value}")?; if let Some(leading_field) = leading_field { - write!(f, " {}", leading_field)?; + write!(f, " {leading_field}")?; } if let Some(leading_precision) = leading_precision { - write!(f, " ({})", leading_precision)?; + write!(f, " ({leading_precision})")?; } if let Some(last_field) = last_field { - write!(f, " TO {}", last_field)?; + write!(f, " TO {last_field}")?; } if let Some(fractional_seconds_precision) = fractional_seconds_precision { - write!(f, " ({})", fractional_seconds_precision)?; + write!(f, " ({fractional_seconds_precision})")?; } Ok(()) } @@ -1023,8 +1021,8 @@ impl fmt::Display for WindowFrameBound { WindowFrameBound::CurrentRow => f.write_str("CURRENT ROW"), WindowFrameBound::Preceding(None) => f.write_str("UNBOUNDED PRECEDING"), WindowFrameBound::Following(None) => f.write_str("UNBOUNDED FOLLOWING"), - WindowFrameBound::Preceding(Some(n)) => write!(f, "{} PRECEDING", n), - WindowFrameBound::Following(Some(n)) => write!(f, "{} FOLLOWING", n), + WindowFrameBound::Preceding(Some(n)) => write!(f, "{n} PRECEDING"), + WindowFrameBound::Following(Some(n)) => write!(f, "{n} FOLLOWING"), } } } @@ -1644,10 +1642,10 @@ impl fmt::Display for Statement { write!(f, "KILL ")?; if let Some(m) = modifier { - write!(f, "{} ", m)?; + write!(f, "{m} ")?; } - write!(f, "{}", id) + write!(f, "{id}") } Statement::ExplainTable { describe_alias, @@ -1659,7 +1657,7 @@ impl fmt::Display for Statement { write!(f, "EXPLAIN ")?; } - write!(f, "{}", table_name) + write!(f, "{table_name}") } Statement::Explain { describe_alias, @@ -1683,12 +1681,12 @@ impl fmt::Display for Statement { } if let Some(format) = format { - write!(f, "FORMAT {} ", format)?; + write!(f, "FORMAT {format} ")?; } - write!(f, "{}", statement) + write!(f, "{statement}") } - Statement::Query(s) => write!(f, "{}", s), + Statement::Query(s) => write!(f, "{s}"), Statement::Declare { name, binary, @@ -1697,7 +1695,7 @@ impl fmt::Display for Statement { hold, query, } => { - write!(f, "DECLARE {} ", name)?; + write!(f, "DECLARE {name} ")?; if *binary { write!(f, "BINARY ")?; @@ -1729,19 +1727,19 @@ impl fmt::Display for Statement { } } - write!(f, "FOR {}", query) + write!(f, "FOR {query}") } Statement::Fetch { name, direction, into, } => { - write!(f, "FETCH {} ", direction)?; + write!(f, "FETCH {direction} ")?; - write!(f, "IN {}", name)?; + write!(f, "IN {name}")?; if let Some(into) = into { - write!(f, " INTO {}", into)?; + write!(f, " INTO {into}")?; } Ok(()) @@ -1761,9 +1759,9 @@ impl fmt::Display for Statement { path = path )?; if let Some(ref ff) = file_format { - write!(f, " STORED AS {}", ff)? + write!(f, " STORED AS {ff}")? } - write!(f, " {}", source) + write!(f, " {source}") } Statement::Msck { table_name, @@ -1777,7 +1775,7 @@ impl fmt::Display for Statement { table = table_name )?; if let Some(pa) = partition_action { - write!(f, " {}", pa)?; + write!(f, " {pa}")?; } Ok(()) } @@ -1785,7 +1783,7 @@ impl fmt::Display for Statement { table_name, partitions, } => { - write!(f, "TRUNCATE TABLE {}", table_name)?; + write!(f, "TRUNCATE TABLE {table_name}")?; if let Some(ref parts) = partitions { if !parts.is_empty() { write!(f, " PARTITION ({})", display_comma_separated(parts))?; @@ -1802,7 +1800,7 @@ impl fmt::Display for Statement { noscan, compute_statistics, } => { - write!(f, "ANALYZE TABLE {}", table_name)?; + write!(f, "ANALYZE TABLE {table_name}")?; if let Some(ref parts) = partitions { if !parts.is_empty() { write!(f, " PARTITION ({})", display_comma_separated(parts))?; @@ -1840,7 +1838,7 @@ impl fmt::Display for Statement { returning, } => { if let Some(action) = or { - write!(f, "INSERT OR {} INTO {} ", action, table_name)?; + write!(f, "INSERT OR {action} INTO {table_name} ")?; } else { write!( f, @@ -1862,10 +1860,10 @@ impl fmt::Display for Statement { if !after_columns.is_empty() { write!(f, "({}) ", display_comma_separated(after_columns))?; } - write!(f, "{}", source)?; + write!(f, "{source}")?; if let Some(on) = on { - write!(f, "{}", on)?; + write!(f, "{on}")?; } if let Some(returning) = returning { @@ -1884,7 +1882,7 @@ impl fmt::Display for Statement { legacy_options, values, } => { - write!(f, "COPY {}", table_name)?; + write!(f, "COPY {table_name}")?; if !columns.is_empty() { write!(f, " ({})", display_comma_separated(columns))?; } @@ -1899,10 +1897,10 @@ impl fmt::Display for Statement { writeln!(f, ";")?; let mut delim = ""; for v in values { - write!(f, "{}", delim)?; + write!(f, "{delim}")?; delim = "\t"; if let Some(v) = v { - write!(f, "{}", v)?; + write!(f, "{v}")?; } else { write!(f, "\\N")?; } @@ -1918,15 +1916,15 @@ impl fmt::Display for Statement { selection, returning, } => { - write!(f, "UPDATE {}", table)?; + write!(f, "UPDATE {table}")?; if !assignments.is_empty() { write!(f, " SET {}", display_comma_separated(assignments))?; } if let Some(from) = from { - write!(f, " FROM {}", from)?; + write!(f, " FROM {from}")?; } if let Some(selection) = selection { - write!(f, " WHERE {}", selection)?; + write!(f, " WHERE {selection}")?; } if let Some(returning) = returning { write!(f, " RETURNING {}", display_comma_separated(returning))?; @@ -1939,12 +1937,12 @@ impl fmt::Display for Statement { selection, returning, } => { - write!(f, "DELETE FROM {}", table_name)?; + write!(f, "DELETE FROM {table_name}")?; if let Some(using) = using { - write!(f, " USING {}", using)?; + write!(f, " USING {using}")?; } if let Some(selection) = selection { - write!(f, " WHERE {}", selection)?; + write!(f, " WHERE {selection}")?; } if let Some(returning) = returning { write!(f, " RETURNING {}", display_comma_separated(returning))?; @@ -1952,7 +1950,7 @@ impl fmt::Display for Statement { Ok(()) } Statement::Close { cursor } => { - write!(f, "CLOSE {}", cursor)?; + write!(f, "CLOSE {cursor}")?; Ok(()) } @@ -1966,12 +1964,12 @@ impl fmt::Display for Statement { if *if_not_exists { write!(f, " IF NOT EXISTS")?; } - write!(f, " {}", db_name)?; + write!(f, " {db_name}")?; if let Some(l) = location { - write!(f, " LOCATION '{}'", l)?; + write!(f, " LOCATION '{l}'")?; } if let Some(ml) = managed_location { - write!(f, " MANAGEDLOCATION '{}'", ml)?; + write!(f, " MANAGEDLOCATION '{ml}'")?; } Ok(()) } @@ -1993,7 +1991,7 @@ impl fmt::Display for Statement { write!(f, "({})", display_comma_separated(args))?; } if let Some(return_type) = return_type { - write!(f, " RETURNS {}", return_type)?; + write!(f, " RETURNS {return_type}")?; } write!(f, "{params}")?; Ok(()) @@ -2023,7 +2021,7 @@ impl fmt::Display for Statement { if !cluster_by.is_empty() { write!(f, " CLUSTER BY ({})", display_comma_separated(cluster_by))?; } - write!(f, " AS {}", query) + write!(f, " AS {query}") } Statement::CreateTable { name, @@ -2099,11 +2097,11 @@ impl fmt::Display for Statement { // Only for Hive if let Some(l) = like { - write!(f, " LIKE {}", l)?; + write!(f, " LIKE {l}")?; } if let Some(c) = clone { - write!(f, " CLONE {}", c)?; + write!(f, " CLONE {c}")?; } match hive_distribution { @@ -2120,7 +2118,7 @@ impl fmt::Display for Statement { write!(f, " SORTED BY ({})", display_comma_separated(sorted_by))?; } if *num_buckets > 0 { - write!(f, " INTO {} BUCKETS", num_buckets)?; + write!(f, " INTO {num_buckets} BUCKETS")?; } } HiveDistributionStyle::SKEWED { @@ -2149,7 +2147,7 @@ impl fmt::Display for Statement { { match row_format { Some(HiveRowFormat::SERDE { class }) => { - write!(f, " ROW FORMAT SERDE '{}'", class)? + write!(f, " ROW FORMAT SERDE '{class}'")? } Some(HiveRowFormat::DELIMITED) => write!(f, " ROW FORMAT DELIMITED")?, None => (), @@ -2160,17 +2158,16 @@ impl fmt::Display for Statement { output_format, }) => write!( f, - " STORED AS INPUTFORMAT {} OUTPUTFORMAT {}", - input_format, output_format + " STORED AS INPUTFORMAT {input_format} OUTPUTFORMAT {output_format}" )?, Some(HiveIOFormat::FileFormat { format }) if !*external => { - write!(f, " STORED AS {}", format)? + write!(f, " STORED AS {format}")? } _ => (), } if !*external { if let Some(loc) = location { - write!(f, " LOCATION '{}'", loc)?; + write!(f, " LOCATION '{loc}'")?; } } } @@ -2193,16 +2190,16 @@ impl fmt::Display for Statement { write!(f, " WITH ({})", display_comma_separated(with_options))?; } if let Some(query) = query { - write!(f, " AS {}", query)?; + write!(f, " AS {query}")?; } if let Some(engine) = engine { - write!(f, " ENGINE={}", engine)?; + write!(f, " ENGINE={engine}")?; } if let Some(default_charset) = default_charset { - write!(f, " DEFAULT CHARSET={}", default_charset)?; + write!(f, " DEFAULT CHARSET={default_charset}")?; } if let Some(collation) = collation { - write!(f, " COLLATE={}", collation)?; + write!(f, " COLLATE={collation}")?; } if on_commit.is_some() { @@ -2212,7 +2209,7 @@ impl fmt::Display for Statement { Some(OnCommit::Drop) => "ON COMMIT DROP", None => "", }; - write!(f, " {}", on_commit)?; + write!(f, " {on_commit}")?; } Ok(()) @@ -2252,7 +2249,7 @@ impl fmt::Display for Statement { table_name = table_name )?; if let Some(value) = using { - write!(f, " USING {} ", value)?; + write!(f, " USING {value} ")?; } write!(f, "({})", display_separated(columns, ",")) } @@ -2318,15 +2315,15 @@ impl fmt::Display for Statement { } )?; if let Some(limit) = connection_limit { - write!(f, " CONNECTION LIMIT {}", limit)?; + write!(f, " CONNECTION LIMIT {limit}")?; } match password { - Some(Password::Password(pass)) => write!(f, " PASSWORD {}", pass), + Some(Password::Password(pass)) => write!(f, " PASSWORD {pass}"), Some(Password::NullPassword) => write!(f, " PASSWORD NULL"), None => Ok(()), }?; if let Some(until) = valid_until { - write!(f, " VALID UNTIL {}", until)?; + write!(f, " VALID UNTIL {until}")?; } if !in_role.is_empty() { write!(f, " IN ROLE {}", display_comma_separated(in_role))?; @@ -2344,15 +2341,15 @@ impl fmt::Display for Statement { write!(f, " ADMIN {}", display_comma_separated(admin))?; } if let Some(owner) = authorization_owner { - write!(f, " AUTHORIZATION {}", owner)?; + write!(f, " AUTHORIZATION {owner}")?; } Ok(()) } Statement::AlterTable { name, operation } => { - write!(f, "ALTER TABLE {} {}", name, operation) + write!(f, "ALTER TABLE {name} {operation}") } Statement::AlterIndex { name, operation } => { - write!(f, "ALTER INDEX {} {}", name, operation) + write!(f, "ALTER INDEX {name} {operation}") } Statement::Drop { object_type, @@ -2383,12 +2380,12 @@ impl fmt::Display for Statement { display_comma_separated(func_desc), )?; if let Some(op) = option { - write!(f, " {}", op)?; + write!(f, " {op}")?; } Ok(()) } Statement::Discard { object_type } => { - write!(f, "DISCARD {object_type}", object_type = object_type)?; + write!(f, "DISCARD {object_type}")?; Ok(()) } Self::SetRole { @@ -2457,12 +2454,7 @@ impl fmt::Display for Statement { Ok(()) } Statement::ShowCreate { obj_type, obj_name } => { - write!( - f, - "SHOW CREATE {obj_type} {obj_name}", - obj_type = obj_type, - obj_name = obj_name, - )?; + write!(f, "SHOW CREATE {obj_type} {obj_name}",)?; Ok(()) } Statement::ShowColumns { @@ -2479,7 +2471,7 @@ impl fmt::Display for Statement { table_name = table_name, )?; if let Some(filter) = filter { - write!(f, " {}", filter)?; + write!(f, " {filter}")?; } Ok(()) } @@ -2496,28 +2488,28 @@ impl fmt::Display for Statement { full = if *full { "FULL " } else { "" }, )?; if let Some(db_name) = db_name { - write!(f, " FROM {}", db_name)?; + write!(f, " FROM {db_name}")?; } if let Some(filter) = filter { - write!(f, " {}", filter)?; + write!(f, " {filter}")?; } Ok(()) } Statement::ShowFunctions { filter } => { write!(f, "SHOW FUNCTIONS")?; if let Some(filter) = filter { - write!(f, " {}", filter)?; + write!(f, " {filter}")?; } Ok(()) } Statement::Use { db_name } => { - write!(f, "USE {}", db_name)?; + write!(f, "USE {db_name}")?; Ok(()) } Statement::ShowCollation { filter } => { write!(f, "SHOW COLLATION")?; if let Some(filter) = filter { - write!(f, " {}", filter)?; + write!(f, " {filter}")?; } Ok(()) } @@ -2542,7 +2534,7 @@ impl fmt::Display for Statement { write!(f, " {}", display_comma_separated(modes))?; } if let Some(snapshot_id) = snapshot { - write!(f, " SNAPSHOT {}", snapshot_id)?; + write!(f, " SNAPSHOT {snapshot_id}")?; } Ok(()) } @@ -2562,9 +2554,9 @@ impl fmt::Display for Statement { name = schema_name ), Statement::Assert { condition, message } => { - write!(f, "ASSERT {}", condition)?; + write!(f, "ASSERT {condition}")?; if let Some(m) = message { - write!(f, " AS {}", m)?; + write!(f, " AS {m}")?; } Ok(()) } @@ -2575,14 +2567,14 @@ impl fmt::Display for Statement { with_grant_option, granted_by, } => { - write!(f, "GRANT {} ", privileges)?; - write!(f, "ON {} ", objects)?; + write!(f, "GRANT {privileges} ")?; + write!(f, "ON {objects} ")?; write!(f, "TO {}", display_comma_separated(grantees))?; if *with_grant_option { write!(f, " WITH GRANT OPTION")?; } if let Some(grantor) = granted_by { - write!(f, " GRANTED BY {}", grantor)?; + write!(f, " GRANTED BY {grantor}")?; } Ok(()) } @@ -2593,11 +2585,11 @@ impl fmt::Display for Statement { granted_by, cascade, } => { - write!(f, "REVOKE {} ", privileges)?; - write!(f, "ON {} ", objects)?; + write!(f, "REVOKE {privileges} ")?; + write!(f, "ON {objects} ")?; write!(f, "FROM {}", display_comma_separated(grantees))?; if let Some(grantor) = granted_by { - write!(f, " GRANTED BY {}", grantor)?; + write!(f, " GRANTED BY {grantor}")?; } write!(f, " {}", if *cascade { "CASCADE" } else { "RESTRICT" })?; Ok(()) @@ -2609,7 +2601,7 @@ impl fmt::Display for Statement { name = name, ), Statement::Execute { name, parameters } => { - write!(f, "EXECUTE {}", name)?; + write!(f, "EXECUTE {name}")?; if !parameters.is_empty() { write!(f, "({})", display_comma_separated(parameters))?; } @@ -2620,27 +2612,27 @@ impl fmt::Display for Statement { data_types, statement, } => { - write!(f, "PREPARE {} ", name)?; + write!(f, "PREPARE {name} ")?; if !data_types.is_empty() { write!(f, "({}) ", display_comma_separated(data_types))?; } - write!(f, "AS {}", statement) + write!(f, "AS {statement}") } Statement::Comment { object_type, object_name, comment, } => { - write!(f, "COMMENT ON {} {} IS ", object_type, object_name)?; + write!(f, "COMMENT ON {object_type} {object_name} IS ")?; if let Some(c) = comment { - write!(f, "'{}'", c) + write!(f, "'{c}'") } else { write!(f, "NULL") } } Statement::Savepoint { name } => { write!(f, "SAVEPOINT ")?; - write!(f, "{}", name) + write!(f, "{name}") } Statement::Merge { into, @@ -2654,7 +2646,7 @@ impl fmt::Display for Statement { "MERGE{int} {table} USING {source} ", int = if *into { " INTO" } else { "" } )?; - write!(f, "ON {} ", on)?; + write!(f, "ON {on} ")?; write!(f, "{}", display_separated(clauses, " ")) } Statement::Cache { @@ -2672,7 +2664,7 @@ impl fmt::Display for Statement { table_name = table_name, )?; } else { - write!(f, "CACHE TABLE {table_name}", table_name = table_name,)?; + write!(f, "CACHE TABLE {table_name}",)?; } if !options.is_empty() { @@ -2695,13 +2687,9 @@ impl fmt::Display for Statement { if_exists, } => { if *if_exists { - write!( - f, - "UNCACHE TABLE IF EXISTS {table_name}", - table_name = table_name - ) + write!(f, "UNCACHE TABLE IF EXISTS {table_name}") } else { - write!(f, "UNCACHE TABLE {table_name}", table_name = table_name) + write!(f, "UNCACHE TABLE {table_name}") } } Statement::CreateSequence { @@ -2728,10 +2716,10 @@ impl fmt::Display for Statement { as_type = as_type )?; for sequence_option in sequence_options { - write!(f, "{}", sequence_option)?; + write!(f, "{sequence_option}")?; } if let Some(ob) = owned_by.as_ref() { - write!(f, " OWNED BY {}", ob)?; + write!(f, " OWNED BY {ob}")?; } write!(f, "") } @@ -2776,7 +2764,7 @@ impl fmt::Display for SequenceOptions { write!(f, " NO MINVALUE") } MinMaxValue::Some(minvalue) => { - write!(f, " MINVALUE {minvalue}", minvalue = minvalue) + write!(f, " MINVALUE {minvalue}") } }, SequenceOptions::MaxValue(value) => match value { @@ -2787,7 +2775,7 @@ impl fmt::Display for SequenceOptions { write!(f, " NO MAXVALUE") } MinMaxValue::Some(maxvalue) => { - write!(f, " MAXVALUE {maxvalue}", maxvalue = maxvalue) + write!(f, " MAXVALUE {maxvalue}") } }, SequenceOptions::StartWith(start, with) => { @@ -2881,7 +2869,7 @@ impl fmt::Display for OnConflict { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, " ON CONFLICT")?; if let Some(target) = &self.conflict_target { - write!(f, "{}", target)?; + write!(f, "{target}")?; } write!(f, " {}", self.action) } @@ -2890,7 +2878,7 @@ impl fmt::Display for ConflictTarget { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { ConflictTarget::Columns(cols) => write!(f, "({})", display_comma_separated(cols)), - ConflictTarget::OnConstraint(name) => write!(f, " ON CONSTRAINT {}", name), + ConflictTarget::OnConstraint(name) => write!(f, " ON CONSTRAINT {name}"), } } } @@ -2908,7 +2896,7 @@ impl fmt::Display for OnConflictAction { )?; } if let Some(selection) = &do_update.selection { - write!(f, " WHERE {}", selection)?; + write!(f, " WHERE {selection}")?; } Ok(()) } @@ -3143,8 +3131,8 @@ pub enum FunctionArgExpr { impl fmt::Display for FunctionArgExpr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - FunctionArgExpr::Expr(expr) => write!(f, "{}", expr), - FunctionArgExpr::QualifiedWildcard(prefix) => write!(f, "{}.*", prefix), + FunctionArgExpr::Expr(expr) => write!(f, "{expr}"), + FunctionArgExpr::QualifiedWildcard(prefix) => write!(f, "{prefix}.*"), FunctionArgExpr::Wildcard => f.write_str("*"), } } @@ -3161,8 +3149,8 @@ pub enum FunctionArg { impl fmt::Display for FunctionArg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - FunctionArg::Named { name, arg } => write!(f, "{} => {}", name, arg), - FunctionArg::Unnamed(unnamed_arg) => write!(f, "{}", unnamed_arg), + FunctionArg::Named { name, arg } => write!(f, "{name} => {arg}"), + FunctionArg::Unnamed(unnamed_arg) => write!(f, "{unnamed_arg}"), } } } @@ -3179,7 +3167,7 @@ impl fmt::Display for CloseCursor { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { CloseCursor::All => write!(f, "ALL"), - CloseCursor::Specific { name } => write!(f, "{}", name), + CloseCursor::Specific { name } => write!(f, "{name}"), } } } @@ -3232,7 +3220,7 @@ impl fmt::Display for Function { )?; if let Some(o) = &self.over { - write!(f, " OVER ({})", o)?; + write!(f, " OVER ({o})")?; } } @@ -3291,10 +3279,10 @@ impl fmt::Display for ListAgg { self.expr )?; if let Some(separator) = &self.separator { - write!(f, ", {}", separator)?; + write!(f, ", {separator}")?; } if let Some(on_overflow) = &self.on_overflow { - write!(f, "{}", on_overflow)?; + write!(f, "{on_overflow}")?; } write!(f, ")")?; if !self.within_group.is_empty() { @@ -3331,7 +3319,7 @@ impl fmt::Display for ListAggOnOverflow { ListAggOnOverflow::Truncate { filler, with_count } => { write!(f, " TRUNCATE")?; if let Some(filler) = filler { - write!(f, " {}", filler)?; + write!(f, " {filler}")?; } if *with_count { write!(f, " WITH")?; @@ -3368,16 +3356,16 @@ impl fmt::Display for ArrayAgg { )?; if !self.within_group { if let Some(order_by) = &self.order_by { - write!(f, " ORDER BY {}", order_by)?; + write!(f, " ORDER BY {order_by}")?; } if let Some(limit) = &self.limit { - write!(f, " LIMIT {}", limit)?; + write!(f, " LIMIT {limit}")?; } } write!(f, ")")?; if self.within_group { if let Some(order_by) = &self.order_by { - write!(f, " WITHIN GROUP (ORDER BY {})", order_by)?; + write!(f, " WITHIN GROUP (ORDER BY {order_by})")?; } } Ok(()) @@ -3507,8 +3495,8 @@ impl fmt::Display for TransactionMode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use TransactionMode::*; match self { - AccessMode(access_mode) => write!(f, "{}", access_mode), - IsolationLevel(iso_level) => write!(f, "ISOLATION LEVEL {}", iso_level), + AccessMode(access_mode) => write!(f, "{access_mode}"), + IsolationLevel(iso_level) => write!(f, "ISOLATION LEVEL {iso_level}"), } } } @@ -3568,7 +3556,7 @@ impl fmt::Display for ShowStatementFilter { match self { Like(pattern) => write!(f, "LIKE '{}'", value::escape_single_quote_string(pattern)), ILike(pattern) => write!(f, "ILIKE {}", value::escape_single_quote_string(pattern)), - Where(expr) => write!(f, "WHERE {}", expr), + Where(expr) => write!(f, "WHERE {expr}"), } } } @@ -3677,15 +3665,15 @@ impl fmt::Display for CopyOption { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use CopyOption::*; match self { - Format(name) => write!(f, "FORMAT {}", name), + Format(name) => write!(f, "FORMAT {name}"), Freeze(true) => write!(f, "FREEZE"), Freeze(false) => write!(f, "FREEZE FALSE"), - Delimiter(char) => write!(f, "DELIMITER '{}'", char), + Delimiter(char) => write!(f, "DELIMITER '{char}'"), Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)), Header(true) => write!(f, "HEADER"), Header(false) => write!(f, "HEADER FALSE"), - Quote(char) => write!(f, "QUOTE '{}'", char), - Escape(char) => write!(f, "ESCAPE '{}'", char), + Quote(char) => write!(f, "QUOTE '{char}'"), + Escape(char) => write!(f, "ESCAPE '{char}'"), ForceQuote(columns) => write!(f, "FORCE_QUOTE ({})", display_comma_separated(columns)), ForceNotNull(columns) => { write!(f, "FORCE_NOT_NULL ({})", display_comma_separated(columns)) @@ -3718,7 +3706,7 @@ impl fmt::Display for CopyLegacyOption { use CopyLegacyOption::*; match self { Binary => write!(f, "BINARY"), - Delimiter(char) => write!(f, "DELIMITER '{}'", char), + Delimiter(char) => write!(f, "DELIMITER '{char}'"), Null(string) => write!(f, "NULL '{}'", value::escape_single_quote_string(string)), Csv(opts) => write!(f, "CSV {}", display_separated(opts, " ")), } @@ -3749,8 +3737,8 @@ impl fmt::Display for CopyLegacyCsvOption { use CopyLegacyCsvOption::*; match self { Header => write!(f, "HEADER"), - Quote(char) => write!(f, "QUOTE '{}'", char), - Escape(char) => write!(f, "ESCAPE '{}'", char), + Quote(char) => write!(f, "QUOTE '{char}'"), + Escape(char) => write!(f, "ESCAPE '{char}'"), ForceQuote(columns) => write!(f, "FORCE QUOTE {}", display_comma_separated(columns)), ForceNotNull(columns) => { write!(f, "FORCE NOT NULL {}", display_comma_separated(columns)) @@ -3787,7 +3775,7 @@ impl fmt::Display for MergeClause { } => { write!(f, " MATCHED")?; if let Some(pred) = predicate { - write!(f, " AND {}", pred)?; + write!(f, " AND {pred}")?; } write!( f, @@ -3798,7 +3786,7 @@ impl fmt::Display for MergeClause { MatchedDelete(predicate) => { write!(f, " MATCHED")?; if let Some(pred) = predicate { - write!(f, " AND {}", pred)?; + write!(f, " AND {pred}")?; } write!(f, " THEN DELETE") } @@ -3809,7 +3797,7 @@ impl fmt::Display for MergeClause { } => { write!(f, " NOT MATCHED")?; if let Some(pred) = predicate { - write!(f, " AND {}", pred)?; + write!(f, " AND {pred}")?; } write!( f, @@ -3944,14 +3932,14 @@ impl OperateFunctionArg { impl fmt::Display for OperateFunctionArg { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(mode) = &self.mode { - write!(f, "{} ", mode)?; + write!(f, "{mode} ")?; } if let Some(name) = &self.name { - write!(f, "{} ", name)?; + write!(f, "{name} ")?; } write!(f, "{}", self.data_type)?; if let Some(default_expr) = &self.default_expr { - write!(f, " = {}", default_expr)?; + write!(f, " = {default_expr}")?; } Ok(()) } @@ -4164,14 +4152,14 @@ mod tests { vec![Expr::Identifier(Ident::new("a"))], vec![Expr::Identifier(Ident::new("b"))], ]); - assert_eq!("GROUPING SETS ((a), (b))", format!("{}", grouping_sets)); + assert_eq!("GROUPING SETS ((a), (b))", format!("{grouping_sets}")); // a and b in the same group let grouping_sets = Expr::GroupingSets(vec![vec![ Expr::Identifier(Ident::new("a")), Expr::Identifier(Ident::new("b")), ]]); - assert_eq!("GROUPING SETS ((a, b))", format!("{}", grouping_sets)); + assert_eq!("GROUPING SETS ((a, b))", format!("{grouping_sets}")); // (a, b) and (c, d) in different group let grouping_sets = Expr::GroupingSets(vec![ @@ -4184,28 +4172,25 @@ mod tests { Expr::Identifier(Ident::new("d")), ], ]); - assert_eq!( - "GROUPING SETS ((a, b), (c, d))", - format!("{}", grouping_sets) - ); + assert_eq!("GROUPING SETS ((a, b), (c, d))", format!("{grouping_sets}")); } #[test] fn test_rollup_display() { let rollup = Expr::Rollup(vec![vec![Expr::Identifier(Ident::new("a"))]]); - assert_eq!("ROLLUP (a)", format!("{}", rollup)); + assert_eq!("ROLLUP (a)", format!("{rollup}")); let rollup = Expr::Rollup(vec![vec![ Expr::Identifier(Ident::new("a")), Expr::Identifier(Ident::new("b")), ]]); - assert_eq!("ROLLUP ((a, b))", format!("{}", rollup)); + assert_eq!("ROLLUP ((a, b))", format!("{rollup}")); let rollup = Expr::Rollup(vec![ vec![Expr::Identifier(Ident::new("a"))], vec![Expr::Identifier(Ident::new("b"))], ]); - assert_eq!("ROLLUP (a, b)", format!("{}", rollup)); + assert_eq!("ROLLUP (a, b)", format!("{rollup}")); let rollup = Expr::Rollup(vec![ vec![Expr::Identifier(Ident::new("a"))], @@ -4215,25 +4200,25 @@ mod tests { ], vec![Expr::Identifier(Ident::new("d"))], ]); - assert_eq!("ROLLUP (a, (b, c), d)", format!("{}", rollup)); + assert_eq!("ROLLUP (a, (b, c), d)", format!("{rollup}")); } #[test] fn test_cube_display() { let cube = Expr::Cube(vec![vec![Expr::Identifier(Ident::new("a"))]]); - assert_eq!("CUBE (a)", format!("{}", cube)); + assert_eq!("CUBE (a)", format!("{cube}")); let cube = Expr::Cube(vec![vec![ Expr::Identifier(Ident::new("a")), Expr::Identifier(Ident::new("b")), ]]); - assert_eq!("CUBE ((a, b))", format!("{}", cube)); + assert_eq!("CUBE ((a, b))", format!("{cube}")); let cube = Expr::Cube(vec![ vec![Expr::Identifier(Ident::new("a"))], vec![Expr::Identifier(Ident::new("b"))], ]); - assert_eq!("CUBE (a, b)", format!("{}", cube)); + assert_eq!("CUBE (a, b)", format!("{cube}")); let cube = Expr::Cube(vec![ vec![Expr::Identifier(Ident::new("a"))], @@ -4243,6 +4228,6 @@ mod tests { ], vec![Expr::Identifier(Ident::new("d"))], ]); - assert_eq!("CUBE (a, (b, c), d)", format!("{}", cube)); + assert_eq!("CUBE (a, (b, c), d)", format!("{cube}")); } } diff --git a/src/ast/query.rs b/src/ast/query.rs index f63234b09..d64babadf 100644 --- a/src/ast/query.rs +++ b/src/ast/query.rs @@ -46,20 +46,20 @@ pub struct Query { impl fmt::Display for Query { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(ref with) = self.with { - write!(f, "{} ", with)?; + write!(f, "{with} ")?; } write!(f, "{}", self.body)?; if !self.order_by.is_empty() { write!(f, " ORDER BY {}", display_comma_separated(&self.order_by))?; } if let Some(ref limit) = self.limit { - write!(f, " LIMIT {}", limit)?; + write!(f, " LIMIT {limit}")?; } if let Some(ref offset) = self.offset { - write!(f, " {}", offset)?; + write!(f, " {offset}")?; } if let Some(ref fetch) = self.fetch { - write!(f, " {}", fetch)?; + write!(f, " {fetch}")?; } if !self.locks.is_empty() { write!(f, " {}", display_separated(&self.locks, " "))?; @@ -95,25 +95,23 @@ pub enum SetExpr { impl fmt::Display for SetExpr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - SetExpr::Select(s) => write!(f, "{}", s), - SetExpr::Query(q) => write!(f, "({})", q), - SetExpr::Values(v) => write!(f, "{}", v), - SetExpr::Insert(v) => write!(f, "{}", v), - SetExpr::Table(t) => write!(f, "{}", t), + SetExpr::Select(s) => write!(f, "{s}"), + SetExpr::Query(q) => write!(f, "({q})"), + SetExpr::Values(v) => write!(f, "{v}"), + SetExpr::Insert(v) => write!(f, "{v}"), + SetExpr::Table(t) => write!(f, "{t}"), SetExpr::SetOperation { left, right, op, set_quantifier, } => { - write!(f, "{} {}", left, op)?; + write!(f, "{left} {op}")?; match set_quantifier { - SetQuantifier::All | SetQuantifier::Distinct => { - write!(f, " {}", set_quantifier)? - } - SetQuantifier::None => write!(f, "{}", set_quantifier)?, + SetQuantifier::All | SetQuantifier::Distinct => write!(f, " {set_quantifier}")?, + SetQuantifier::None => write!(f, "{set_quantifier}")?, } - write!(f, " {}", right)?; + write!(f, " {right}")?; Ok(()) } } @@ -224,12 +222,12 @@ impl fmt::Display for Select { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "SELECT{}", if self.distinct { " DISTINCT" } else { "" })?; if let Some(ref top) = self.top { - write!(f, " {}", top)?; + write!(f, " {top}")?; } write!(f, " {}", display_comma_separated(&self.projection))?; if let Some(ref into) = self.into { - write!(f, " {}", into)?; + write!(f, " {into}")?; } if !self.from.is_empty() { @@ -237,11 +235,11 @@ impl fmt::Display for Select { } if !self.lateral_views.is_empty() { for lv in &self.lateral_views { - write!(f, "{}", lv)?; + write!(f, "{lv}")?; } } if let Some(ref selection) = self.selection { - write!(f, " WHERE {}", selection)?; + write!(f, " WHERE {selection}")?; } if !self.group_by.is_empty() { write!(f, " GROUP BY {}", display_comma_separated(&self.group_by))?; @@ -264,10 +262,10 @@ impl fmt::Display for Select { write!(f, " SORT BY {}", display_comma_separated(&self.sort_by))?; } if let Some(ref having) = self.having { - write!(f, " HAVING {}", having)?; + write!(f, " HAVING {having}")?; } if let Some(ref qualify) = self.qualify { - write!(f, " QUALIFY {}", qualify)?; + write!(f, " QUALIFY {qualify}")?; } Ok(()) } @@ -344,7 +342,7 @@ impl fmt::Display for Cte { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{} AS ({})", self.alias, self.query)?; if let Some(ref fr) = self.from { - write!(f, " FROM {}", fr)?; + write!(f, " FROM {fr}")?; } Ok(()) } @@ -531,10 +529,10 @@ impl fmt::Display for ExceptSelectItem { impl fmt::Display for SelectItem { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match &self { - SelectItem::UnnamedExpr(expr) => write!(f, "{}", expr), - SelectItem::ExprWithAlias { expr, alias } => write!(f, "{} AS {}", expr, alias), + SelectItem::UnnamedExpr(expr) => write!(f, "{expr}"), + SelectItem::ExprWithAlias { expr, alias } => write!(f, "{expr} AS {alias}"), SelectItem::QualifiedWildcard(prefix, additional_options) => { - write!(f, "{}.*", prefix)?; + write!(f, "{prefix}.*")?; write!(f, "{additional_options}")?; Ok(()) } @@ -559,7 +557,7 @@ impl fmt::Display for TableWithJoins { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.relation)?; for join in &self.joins { - write!(f, "{}", join)?; + write!(f, "{join}")?; } Ok(()) } @@ -632,12 +630,12 @@ impl fmt::Display for TableFactor { args, with_hints, } => { - write!(f, "{}", name)?; + write!(f, "{name}")?; if let Some(args) = args { write!(f, "({})", display_comma_separated(args))?; } if let Some(alias) = alias { - write!(f, " AS {}", alias)?; + write!(f, " AS {alias}")?; } if !with_hints.is_empty() { write!(f, " WITH ({})", display_comma_separated(with_hints))?; @@ -652,16 +650,16 @@ impl fmt::Display for TableFactor { if *lateral { write!(f, "LATERAL ")?; } - write!(f, "({})", subquery)?; + write!(f, "({subquery})")?; if let Some(alias) = alias { - write!(f, " AS {}", alias)?; + write!(f, " AS {alias}")?; } Ok(()) } TableFactor::TableFunction { expr, alias } => { - write!(f, "TABLE({})", expr)?; + write!(f, "TABLE({expr})")?; if let Some(alias) = alias { - write!(f, " AS {}", alias)?; + write!(f, " AS {alias}")?; } Ok(()) } @@ -671,15 +669,15 @@ impl fmt::Display for TableFactor { with_offset, with_offset_alias, } => { - write!(f, "UNNEST({})", array_expr)?; + write!(f, "UNNEST({array_expr})")?; if let Some(alias) = alias { - write!(f, " AS {}", alias)?; + write!(f, " AS {alias}")?; } if *with_offset { write!(f, " WITH OFFSET")?; } if let Some(alias) = with_offset_alias { - write!(f, " AS {}", alias)?; + write!(f, " AS {alias}")?; } Ok(()) } @@ -687,9 +685,9 @@ impl fmt::Display for TableFactor { table_with_joins, alias, } => { - write!(f, "({})", table_with_joins)?; + write!(f, "({table_with_joins})")?; if let Some(alias) = alias { - write!(f, " AS {}", alias)?; + write!(f, " AS {alias}")?; } Ok(()) } @@ -736,7 +734,7 @@ impl fmt::Display for Join { impl<'a> fmt::Display for Suffix<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.0 { - JoinConstraint::On(expr) => write!(f, " ON {}", expr), + JoinConstraint::On(expr) => write!(f, " ON {expr}"), JoinConstraint::Using(attrs) => { write!(f, " USING({})", display_comma_separated(attrs)) } @@ -921,9 +919,9 @@ impl fmt::Display for Fetch { let extension = if self.with_ties { "WITH TIES" } else { "ONLY" }; if let Some(ref quantity) = self.quantity { let percent = if self.percent { " PERCENT" } else { "" }; - write!(f, "FETCH FIRST {}{} ROWS {}", quantity, percent, extension) + write!(f, "FETCH FIRST {quantity}{percent} ROWS {extension}") } else { - write!(f, "FETCH FIRST ROWS {}", extension) + write!(f, "FETCH FIRST ROWS {extension}") } } } @@ -941,10 +939,10 @@ impl fmt::Display for LockClause { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "FOR {}", &self.lock_type)?; if let Some(ref of) = self.of { - write!(f, " OF {}", of)?; + write!(f, " OF {of}")?; } if let Some(ref nb) = self.nonblock { - write!(f, " {}", nb)?; + write!(f, " {nb}")?; } Ok(()) } @@ -964,7 +962,7 @@ impl fmt::Display for LockType { LockType::Share => "SHARE", LockType::Update => "UPDATE", }; - write!(f, "{}", select_lock) + write!(f, "{select_lock}") } } @@ -982,7 +980,7 @@ impl fmt::Display for NonBlock { NonBlock::Nowait => "NOWAIT", NonBlock::SkipLocked => "SKIP LOCKED", }; - write!(f, "{}", nonblock) + write!(f, "{nonblock}") } } @@ -1001,9 +999,9 @@ impl fmt::Display for Top { let extension = if self.with_ties { " WITH TIES" } else { "" }; if let Some(ref quantity) = self.quantity { let percent = if self.percent { " PERCENT" } else { "" }; - write!(f, "TOP ({}){}{}", quantity, percent, extension) + write!(f, "TOP ({quantity}){percent}{extension}") } else { - write!(f, "TOP{}", extension) + write!(f, "TOP{extension}") } } } @@ -1024,7 +1022,7 @@ impl fmt::Display for Values { let prefix = if self.explicit_row { "ROW" } else { "" }; let mut delim = ""; for row in &self.rows { - write!(f, "{}", delim)?; + write!(f, "{delim}")?; delim = ", "; write!(f, "{prefix}({})", display_comma_separated(row))?; } diff --git a/src/ast/value.rs b/src/ast/value.rs index 4072c0a4c..0adb2d5dc 100644 --- a/src/ast/value.rs +++ b/src/ast/value.rs @@ -61,16 +61,16 @@ impl fmt::Display for Value { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Value::Number(v, l) => write!(f, "{}{long}", v, long = if *l { "L" } else { "" }), - Value::DoubleQuotedString(v) => write!(f, "\"{}\"", v), + Value::DoubleQuotedString(v) => write!(f, "\"{v}\""), Value::SingleQuotedString(v) => write!(f, "'{}'", escape_single_quote_string(v)), - Value::DollarQuotedString(v) => write!(f, "{}", v), + Value::DollarQuotedString(v) => write!(f, "{v}"), Value::EscapedStringLiteral(v) => write!(f, "E'{}'", escape_escaped_string(v)), - Value::NationalStringLiteral(v) => write!(f, "N'{}'", v), - Value::HexStringLiteral(v) => write!(f, "X'{}'", v), - Value::Boolean(v) => write!(f, "{}", v), + Value::NationalStringLiteral(v) => write!(f, "N'{v}'"), + Value::HexStringLiteral(v) => write!(f, "X'{v}'"), + Value::Boolean(v) => write!(f, "{v}"), Value::Null => write!(f, "NULL"), - Value::Placeholder(v) => write!(f, "{}", v), - Value::UnQuotedString(v) => write!(f, "{}", v), + Value::Placeholder(v) => write!(f, "{v}"), + Value::UnQuotedString(v) => write!(f, "{v}"), } } } @@ -178,7 +178,7 @@ impl<'a> fmt::Display for EscapeQuotedString<'a> { if c == self.quote { write!(f, "{q}{q}", q = self.quote)?; } else { - write!(f, "{}", c)?; + write!(f, "{c}")?; } } Ok(()) @@ -215,7 +215,7 @@ impl<'a> fmt::Display for EscapeEscapedStringLiteral<'a> { write!(f, r#"\r"#)?; } _ => { - write!(f, "{}", c)?; + write!(f, "{c}")?; } } } diff --git a/src/ast/visitor.rs b/src/ast/visitor.rs index 1a9eeaa24..6787bfd68 100644 --- a/src/ast/visitor.rs +++ b/src/ast/visitor.rs @@ -600,32 +600,32 @@ mod tests { type Break = (); fn pre_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow { - self.visited.push(format!("PRE: RELATION: {}", relation)); + self.visited.push(format!("PRE: RELATION: {relation}")); ControlFlow::Continue(()) } fn post_visit_relation(&mut self, relation: &ObjectName) -> ControlFlow { - self.visited.push(format!("POST: RELATION: {}", relation)); + self.visited.push(format!("POST: RELATION: {relation}")); ControlFlow::Continue(()) } fn pre_visit_expr(&mut self, expr: &Expr) -> ControlFlow { - self.visited.push(format!("PRE: EXPR: {}", expr)); + self.visited.push(format!("PRE: EXPR: {expr}")); ControlFlow::Continue(()) } fn post_visit_expr(&mut self, expr: &Expr) -> ControlFlow { - self.visited.push(format!("POST: EXPR: {}", expr)); + self.visited.push(format!("POST: EXPR: {expr}")); ControlFlow::Continue(()) } fn pre_visit_statement(&mut self, statement: &Statement) -> ControlFlow { - self.visited.push(format!("PRE: STATEMENT: {}", statement)); + self.visited.push(format!("PRE: STATEMENT: {statement}")); ControlFlow::Continue(()) } fn post_visit_statement(&mut self, statement: &Statement) -> ControlFlow { - self.visited.push(format!("POST: STATEMENT: {}", statement)); + self.visited.push(format!("POST: STATEMENT: {statement}")); ControlFlow::Continue(()) } } diff --git a/src/parser.rs b/src/parser.rs index 3883a333d..58252d3fe 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -805,7 +805,7 @@ impl<'a> Parser<'a> { let tok = self.next_token(); let key = match tok.token { Token::Word(word) => word.to_ident(), - _ => return parser_err!(format!("Expected identifier, found: {}", tok)), + _ => return parser_err!(format!("Expected identifier, found: {tok}")), }; Ok(Expr::CompositeAccess { expr: Box::new(expr), @@ -2083,7 +2083,7 @@ impl<'a> Parser<'a> { /// Report unexpected token pub fn expected(&self, expected: &str, found: TokenWithLocation) -> Result { - parser_err!(format!("Expected {}, found: {}", expected, found)) + parser_err!(format!("Expected {expected}, found: {found}")) } /// Look for an expected keyword and consume it if it exists @@ -2135,7 +2135,7 @@ impl<'a> Parser<'a> { if let Some(keyword) = self.parse_one_of_keywords(keywords) { Ok(keyword) } else { - let keywords: Vec = keywords.iter().map(|x| format!("{:?}", x)).collect(); + let keywords: Vec = keywords.iter().map(|x| format!("{x:?}")).collect(); self.expected( &format!("one of {}", keywords.join(" or ")), self.peek_token(), @@ -2495,7 +2495,7 @@ impl<'a> Parser<'a> { Keyword::ARCHIVE => Ok(Some(CreateFunctionUsing::Archive(uri))), _ => self.expected( "JAR, FILE or ARCHIVE, got {:?}", - TokenWithLocation::wrap(Token::make_keyword(format!("{:?}", keyword).as_str())), + TokenWithLocation::wrap(Token::make_keyword(format!("{keyword:?}").as_str())), ), } } @@ -4028,7 +4028,7 @@ impl<'a> Parser<'a> { fn parse_literal_char(&mut self) -> Result { let s = self.parse_literal_string()?; if s.len() != 1 { - return parser_err!(format!("Expect a char, found {:?}", s)); + return parser_err!(format!("Expect a char, found {s:?}")); } Ok(s.chars().next().unwrap()) } @@ -4107,7 +4107,7 @@ impl<'a> Parser<'a> { // (i.e., it returns the input string). Token::Number(ref n, l) => match n.parse() { Ok(n) => Ok(Value::Number(n, l)), - Err(e) => parser_err!(format!("Could not parse '{}' as number: {}", n, e)), + Err(e) => parser_err!(format!("Could not parse '{n}' as number: {e}")), }, Token::SingleQuotedString(ref s) => Ok(Value::SingleQuotedString(s.to_string())), Token::DoubleQuotedString(ref s) => Ok(Value::DoubleQuotedString(s.to_string())), @@ -4147,7 +4147,7 @@ impl<'a> Parser<'a> { let next_token = self.next_token(); match next_token.token { Token::Number(s, _) => s.parse::().map_err(|e| { - ParserError::ParserError(format!("Could not parse '{}' as u64: {}", s, e)) + ParserError::ParserError(format!("Could not parse '{s}' as u64: {e}")) }), _ => self.expected("literal int", next_token), } @@ -5267,8 +5267,7 @@ impl<'a> Parser<'a> { Keyword::EVENT => Ok(ShowCreateObject::Event), Keyword::VIEW => Ok(ShowCreateObject::View), keyword => Err(ParserError::ParserError(format!( - "Unable to map keyword to ShowCreateObject: {:?}", - keyword + "Unable to map keyword to ShowCreateObject: {keyword:?}" ))), }?; @@ -5437,8 +5436,7 @@ impl<'a> Parser<'a> { } _ => { return Err(ParserError::ParserError(format!( - "expected OUTER, SEMI, ANTI or JOIN after {:?}", - kw + "expected OUTER, SEMI, ANTI or JOIN after {kw:?}" ))) } } @@ -5561,8 +5559,7 @@ impl<'a> Parser<'a> { // but not `FROM (mytable AS alias1) AS alias2`. if let Some(inner_alias) = alias { return Err(ParserError::ParserError(format!( - "duplicate alias {}", - inner_alias + "duplicate alias {inner_alias}" ))); } // Act as if the alias was specified normally next @@ -5731,8 +5728,7 @@ impl<'a> Parser<'a> { if !err.is_empty() { let errors: Vec = err.into_iter().filter_map(|x| x.err()).collect(); return Err(ParserError::ParserError(format!( - "INTERNAL ERROR: GRANT/REVOKE unexpected keyword(s) - {:?}", - errors + "INTERNAL ERROR: GRANT/REVOKE unexpected keyword(s) - {errors:?}" ))); } let act = actions.into_iter().filter_map(|x| x.ok()).collect(); diff --git a/src/test_utils.rs b/src/test_utils.rs index 79c24e292..d5bafd90f 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -49,8 +49,7 @@ impl TestedDialects { if let Some((prev_dialect, prev_parsed)) = s { assert_eq!( prev_parsed, parsed, - "Parse results with {:?} are different from {:?}", - prev_dialect, dialect + "Parse results with {prev_dialect:?} are different from {dialect:?}" ); } Some((dialect, parsed)) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index dcf128542..eef4cb7b4 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -180,17 +180,17 @@ impl fmt::Display for Token { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Token::EOF => f.write_str("EOF"), - Token::Word(ref w) => write!(f, "{}", w), + Token::Word(ref w) => write!(f, "{w}"), Token::Number(ref n, l) => write!(f, "{}{long}", n, long = if *l { "L" } else { "" }), - Token::Char(ref c) => write!(f, "{}", c), - Token::SingleQuotedString(ref s) => write!(f, "'{}'", s), - Token::DoubleQuotedString(ref s) => write!(f, "\"{}\"", s), - Token::DollarQuotedString(ref s) => write!(f, "{}", s), - Token::NationalStringLiteral(ref s) => write!(f, "N'{}'", s), - Token::EscapedStringLiteral(ref s) => write!(f, "E'{}'", s), - Token::HexStringLiteral(ref s) => write!(f, "X'{}'", s), + Token::Char(ref c) => write!(f, "{c}"), + Token::SingleQuotedString(ref s) => write!(f, "'{s}'"), + Token::DoubleQuotedString(ref s) => write!(f, "\"{s}\""), + Token::DollarQuotedString(ref s) => write!(f, "{s}"), + Token::NationalStringLiteral(ref s) => write!(f, "N'{s}'"), + Token::EscapedStringLiteral(ref s) => write!(f, "E'{s}'"), + Token::HexStringLiteral(ref s) => write!(f, "X'{s}'"), Token::Comma => f.write_str(","), - Token::Whitespace(ws) => write!(f, "{}", ws), + Token::Whitespace(ws) => write!(f, "{ws}"), Token::DoubleEq => f.write_str("=="), Token::Spaceship => f.write_str("<=>"), Token::Eq => f.write_str("="), @@ -232,7 +232,7 @@ impl fmt::Display for Token { Token::ShiftRight => f.write_str(">>"), Token::PGSquareRoot => f.write_str("|/"), Token::PGCubeRoot => f.write_str("||/"), - Token::Placeholder(ref s) => write!(f, "{}", s), + Token::Placeholder(ref s) => write!(f, "{s}"), Token::Arrow => write!(f, "->"), Token::LongArrow => write!(f, "->>"), Token::HashArrow => write!(f, "#>"), @@ -323,8 +323,8 @@ impl fmt::Display for Whitespace { Whitespace::Space => f.write_str(" "), Whitespace::Newline => f.write_str("\n"), Whitespace::Tab => f.write_str("\t"), - Whitespace::SingleLineComment { prefix, comment } => write!(f, "{}{}", prefix, comment), - Whitespace::MultiLineComment(s) => write!(f, "/*{}*/", s), + Whitespace::SingleLineComment { prefix, comment } => write!(f, "{prefix}{comment}"), + Whitespace::MultiLineComment(s) => write!(f, "/*{s}*/"), } } } @@ -595,13 +595,13 @@ impl<'a> Tokenizer<'a> { } else { self.tokenizer_error( error_loc, - format!("Expected close delimiter '{}' before EOF.", quote_end), + format!("Expected close delimiter '{quote_end}' before EOF."), ) } } // numbers and period '0'..='9' | '.' => { - let mut s = peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + let mut s = peeking_take_while(chars, |ch| ch.is_ascii_digit()); // match binary literal that starts with 0x if s == "0" && chars.peek() == Some(&'x') { @@ -618,7 +618,7 @@ impl<'a> Tokenizer<'a> { s.push('.'); chars.next(); } - s += &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + s += &peeking_take_while(chars, |ch| ch.is_ascii_digit()); // No number -> Token::Period if s == "." { @@ -642,12 +642,12 @@ impl<'a> Tokenizer<'a> { match char_clone.peek() { // Definitely an exponent, get original iterator up to speed and use it - Some(&c) if matches!(c, '0'..='9') => { + Some(&c) if c.is_ascii_digit() => { for _ in 0..exponent_part.len() { chars.next(); } exponent_part += - &peeking_take_while(chars, |ch| matches!(ch, '0'..='9')); + &peeking_take_while(chars, |ch| ch.is_ascii_digit()); s += exponent_part.as_str(); } // Not an exponent, discard the work done @@ -907,8 +907,7 @@ impl<'a> Tokenizer<'a> { return self.tokenizer_error( chars.location(), format!( - "Unterminated dollar-quoted string at or near \"{}\"", - value + "Unterminated dollar-quoted string at or near \"{value}\"" ), ); } diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs index 3fe5cd92b..24d3fdcc5 100644 --- a/tests/sqlparser_bigquery.rs +++ b/tests/sqlparser_bigquery.rs @@ -35,7 +35,7 @@ fn parse_literal_string() { #[test] fn parse_table_identifiers() { fn test_table_ident(ident: &str, expected: Vec) { - let sql = format!("SELECT 1 FROM {}", ident); + let sql = format!("SELECT 1 FROM {ident}"); let select = bigquery().verified_only_select(&sql); assert_eq!( select.from, @@ -51,7 +51,7 @@ fn parse_table_identifiers() { ); } fn test_table_ident_err(ident: &str) { - let sql = format!("SELECT 1 FROM {}", ident); + let sql = format!("SELECT 1 FROM {ident}"); assert!(bigquery().parse_sql_statements(&sql).is_err()); } diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index c880eee7c..ae693e34a 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -2435,7 +2435,7 @@ fn parse_create_or_replace_table() { #[test] fn parse_create_table_with_on_delete_on_update_2in_any_order() -> Result<(), ParserError> { let sql = |options: &str| -> String { - format!("create table X (y_id int references Y (id) {})", options) + format!("create table X (y_id int references Y (id) {options})") }; parse_sql_statements(&sql("on update cascade on delete no action"))?; @@ -2777,7 +2777,7 @@ fn parse_alter_table_constraints() { check_one("CHECK (end_date > start_date OR end_date IS NULL)"); fn check_one(constraint_text: &str) { - match verified_stmt(&format!("ALTER TABLE tab ADD {}", constraint_text)) { + match verified_stmt(&format!("ALTER TABLE tab ADD {constraint_text}")) { Statement::AlterTable { name, operation: AlterTableOperation::AddConstraint(constraint), @@ -2787,7 +2787,7 @@ fn parse_alter_table_constraints() { } _ => unreachable!(), } - verified_stmt(&format!("CREATE TABLE foo (id INT, {})", constraint_text)); + verified_stmt(&format!("CREATE TABLE foo (id INT, {constraint_text})")); } } @@ -2804,7 +2804,7 @@ fn parse_alter_table_drop_column() { ); fn check_one(constraint_text: &str) { - match verified_stmt(&format!("ALTER TABLE tab {}", constraint_text)) { + match verified_stmt(&format!("ALTER TABLE tab {constraint_text}")) { Statement::AlterTable { name, operation: @@ -2827,10 +2827,7 @@ fn parse_alter_table_drop_column() { #[test] fn parse_alter_table_alter_column() { let alter_stmt = "ALTER TABLE tab"; - match verified_stmt(&format!( - "{} ALTER COLUMN is_active SET NOT NULL", - alter_stmt - )) { + match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active SET NOT NULL")) { Statement::AlterTable { name, operation: AlterTableOperation::AlterColumn { column_name, op }, @@ -2848,8 +2845,7 @@ fn parse_alter_table_alter_column() { ); match verified_stmt(&format!( - "{} ALTER COLUMN is_active SET DEFAULT false", - alter_stmt + "{alter_stmt} ALTER COLUMN is_active SET DEFAULT false" )) { Statement::AlterTable { name, @@ -2867,10 +2863,7 @@ fn parse_alter_table_alter_column() { _ => unreachable!(), } - match verified_stmt(&format!( - "{} ALTER COLUMN is_active DROP DEFAULT", - alter_stmt - )) { + match verified_stmt(&format!("{alter_stmt} ALTER COLUMN is_active DROP DEFAULT")) { Statement::AlterTable { name, operation: AlterTableOperation::AlterColumn { column_name, op }, @@ -2906,7 +2899,7 @@ fn parse_alter_table_alter_column_type() { let res = Parser::parse_sql( &GenericDialect {}, - &format!("{} ALTER COLUMN is_active TYPE TEXT", alter_stmt), + &format!("{alter_stmt} ALTER COLUMN is_active TYPE TEXT"), ); assert_eq!( ParserError::ParserError("Expected SET/DROP NOT NULL, SET DEFAULT, SET DATA TYPE after ALTER COLUMN, found: TYPE".to_string()), @@ -2915,10 +2908,7 @@ fn parse_alter_table_alter_column_type() { let res = Parser::parse_sql( &GenericDialect {}, - &format!( - "{} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'", - alter_stmt - ), + &format!("{alter_stmt} ALTER COLUMN is_active SET DATA TYPE TEXT USING 'text'"), ); assert_eq!( ParserError::ParserError("Expected end of statement, found: USING".to_string()), @@ -2966,7 +2956,7 @@ fn parse_alter_table_drop_constraint() { let res = Parser::parse_sql( &GenericDialect {}, - &format!("{} DROP CONSTRAINT is_active TEXT", alter_stmt), + &format!("{alter_stmt} DROP CONSTRAINT is_active TEXT"), ); assert_eq!( ParserError::ParserError("Expected end of statement, found: TEXT".to_string()), @@ -2997,7 +2987,7 @@ fn parse_scalar_function_in_projection() { for function_name in names { // like SELECT sqrt(id) FROM foo - let sql = dbg!(format!("SELECT {}(id) FROM foo", function_name)); + let sql = dbg!(format!("SELECT {function_name}(id) FROM foo")); let select = verified_only_select(&sql); assert_eq!( &Expr::Function(Function { @@ -4221,7 +4211,7 @@ fn parse_ctes() { // Top-level CTE assert_ctes_in_select(&cte_sqls, &verified_query(with)); // CTE in a subquery - let sql = &format!("SELECT ({})", with); + let sql = &format!("SELECT ({with})"); let select = verified_only_select(sql); match expr_from_projection(only(&select.projection)) { Expr::Subquery(ref subquery) => { @@ -4230,7 +4220,7 @@ fn parse_ctes() { _ => panic!("Expected subquery"), } // CTE in a derived table - let sql = &format!("SELECT * FROM ({})", with); + let sql = &format!("SELECT * FROM ({with})"); let select = verified_only_select(sql); match only(select.from).relation { TableFactor::Derived { subquery, .. } => { @@ -4239,13 +4229,13 @@ fn parse_ctes() { _ => panic!("Expected derived table"), } // CTE in a view - let sql = &format!("CREATE VIEW v AS {}", with); + let sql = &format!("CREATE VIEW v AS {with}"); match verified_stmt(sql) { Statement::CreateView { query, .. } => assert_ctes_in_select(&cte_sqls, &query), _ => panic!("Expected CREATE VIEW"), } // CTE in a CTE... - let sql = &format!("WITH outer_cte AS ({}) SELECT * FROM outer_cte", with); + let sql = &format!("WITH outer_cte AS ({with}) SELECT * FROM outer_cte"); let select = verified_query(sql); assert_ctes_in_select(&cte_sqls, &only(&select.with.unwrap().cte_tables).query); } @@ -4270,10 +4260,7 @@ fn parse_cte_renamed_columns() { #[test] fn parse_recursive_cte() { let cte_query = "SELECT 1 UNION ALL SELECT val + 1 FROM nums WHERE val < 10".to_owned(); - let sql = &format!( - "WITH RECURSIVE nums (val) AS ({}) SELECT * FROM nums", - cte_query - ); + let sql = &format!("WITH RECURSIVE nums (val) AS ({cte_query}) SELECT * FROM nums"); let cte_query = verified_query(&cte_query); let query = verified_query(sql); @@ -5029,9 +5016,8 @@ fn lateral_derived() { fn chk(lateral_in: bool) { let lateral_str = if lateral_in { "LATERAL " } else { "" }; let sql = format!( - "SELECT * FROM customer LEFT JOIN {}\ - (SELECT * FROM order WHERE order.customer = customer.id LIMIT 3) AS order ON true", - lateral_str + "SELECT * FROM customer LEFT JOIN {lateral_str}\ + (SELECT * FROM order WHERE order.customer = customer.id LIMIT 3) AS order ON true" ); let select = verified_only_select(&sql); let from = only(select.from); @@ -6286,9 +6272,7 @@ fn parse_cache_table() { let query = all_dialects().verified_query(sql); assert_eq!( - verified_stmt( - format!("CACHE TABLE '{table_name}'", table_name = cache_table_name).as_str() - ), + verified_stmt(format!("CACHE TABLE '{cache_table_name}'").as_str()), Statement::Cache { table_flag: None, table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]), @@ -6299,14 +6283,7 @@ fn parse_cache_table() { ); assert_eq!( - verified_stmt( - format!( - "CACHE {flag} TABLE '{table_name}'", - flag = table_flag, - table_name = cache_table_name - ) - .as_str() - ), + verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}'").as_str()), Statement::Cache { table_flag: Some(ObjectName(vec![Ident::new(table_flag)])), table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]), @@ -6319,9 +6296,7 @@ fn parse_cache_table() { assert_eq!( verified_stmt( format!( - "CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88)", - flag = table_flag, - table_name = cache_table_name, + "CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88)", ) .as_str() ), @@ -6346,10 +6321,7 @@ fn parse_cache_table() { assert_eq!( verified_stmt( format!( - "CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) {sql}", - flag = table_flag, - table_name = cache_table_name, - sql = sql, + "CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) {sql}", ) .as_str() ), @@ -6374,10 +6346,7 @@ fn parse_cache_table() { assert_eq!( verified_stmt( format!( - "CACHE {flag} TABLE '{table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) AS {sql}", - flag = table_flag, - table_name = cache_table_name, - sql = sql, + "CACHE {table_flag} TABLE '{cache_table_name}' OPTIONS('K1' = 'V1', 'K2' = 0.88) AS {sql}", ) .as_str() ), @@ -6400,15 +6369,7 @@ fn parse_cache_table() { ); assert_eq!( - verified_stmt( - format!( - "CACHE {flag} TABLE '{table_name}' {sql}", - flag = table_flag, - table_name = cache_table_name, - sql = sql - ) - .as_str() - ), + verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}' {sql}").as_str()), Statement::Cache { table_flag: Some(ObjectName(vec![Ident::new(table_flag)])), table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]), @@ -6419,14 +6380,7 @@ fn parse_cache_table() { ); assert_eq!( - verified_stmt( - format!( - "CACHE {flag} TABLE '{table_name}' AS {sql}", - flag = table_flag, - table_name = cache_table_name - ) - .as_str() - ), + verified_stmt(format!("CACHE {table_flag} TABLE '{cache_table_name}' AS {sql}").as_str()), Statement::Cache { table_flag: Some(ObjectName(vec![Ident::new(table_flag)])), table_name: ObjectName(vec![Ident::with_quote('\'', cache_table_name)]), @@ -6574,7 +6528,7 @@ fn parse_with_recursion_limit() { .expect("tokenize to work") .parse_statements(); - assert!(matches!(res, Ok(_)), "{:?}", res); + assert!(matches!(res, Ok(_)), "{res:?}"); // limit recursion to something smaller, expect parsing to fail let res = Parser::new(&dialect) @@ -6592,7 +6546,7 @@ fn parse_with_recursion_limit() { .with_recursion_limit(50) .parse_statements(); - assert!(matches!(res, Ok(_)), "{:?}", res); + assert!(matches!(res, Ok(_)), "{res:?}"); } /// Makes a predicate that looks like ((user_id = $id) OR user_id = $2...) @@ -6604,7 +6558,7 @@ fn make_where_clause(num: usize) -> String { if i > 0 { write!(&mut output, " OR ").unwrap(); } - write!(&mut output, "user_id = {}", i).unwrap(); + write!(&mut output, "user_id = {i}").unwrap(); if i < num - 1 { write!(&mut output, ")").unwrap(); } diff --git a/tests/sqlparser_custom_dialect.rs b/tests/sqlparser_custom_dialect.rs index a700dda11..465ce8720 100644 --- a/tests/sqlparser_custom_dialect.rs +++ b/tests/sqlparser_custom_dialect.rs @@ -47,7 +47,7 @@ fn custom_prefix_parser() -> Result<(), ParserError> { let sql = "SELECT 1 + 2"; let ast = Parser::parse_sql(&dialect, sql)?; let query = &ast[0]; - assert_eq!("SELECT NULL + 2", &format!("{}", query)); + assert_eq!("SELECT NULL + 2", &format!("{query}")); Ok(()) } @@ -87,7 +87,7 @@ fn custom_infix_parser() -> Result<(), ParserError> { let sql = "SELECT 1 + 2"; let ast = Parser::parse_sql(&dialect, sql)?; let query = &ast[0]; - assert_eq!("SELECT 1 * 2", &format!("{}", query)); + assert_eq!("SELECT 1 * 2", &format!("{query}")); Ok(()) } @@ -121,7 +121,7 @@ fn custom_statement_parser() -> Result<(), ParserError> { let sql = "SELECT 1 + 2"; let ast = Parser::parse_sql(&dialect, sql)?; let query = &ast[0]; - assert_eq!("COMMIT", &format!("{}", query)); + assert_eq!("COMMIT", &format!("{query}")); Ok(()) } diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs index 508ae8461..3bf74255f 100644 --- a/tests/sqlparser_mysql.rs +++ b/tests/sqlparser_mysql.rs @@ -209,7 +209,7 @@ fn parse_show_create() { ShowCreateObject::View, ] { assert_eq!( - mysql_and_generic().verified_stmt(format!("SHOW CREATE {} myident", obj_type).as_str()), + mysql_and_generic().verified_stmt(format!("SHOW CREATE {obj_type} myident").as_str()), Statement::ShowCreate { obj_type: *obj_type, obj_name: obj_name.clone(), diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index 496a61843..08cb0b343 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs @@ -485,7 +485,7 @@ PHP ₱ USD $ \N Some other value \\."#; let ast = pg_and_generic().one_statement_parses_to(sql, ""); - println!("{:#?}", ast); + println!("{ast:#?}"); //assert_eq!(sql, ast.to_string()); } @@ -2069,7 +2069,7 @@ fn parse_create_role() { assert_eq!(*login, Some(true)); assert_eq!(*password, Some(Password::NullPassword)); } - err => panic!("Failed to parse CREATE ROLE test case: {:?}", err), + err => panic!("Failed to parse CREATE ROLE test case: {err:?}"), } let sql = "CREATE ROLE abc WITH LOGIN PASSWORD NULL"; @@ -2086,7 +2086,7 @@ fn parse_create_role() { assert_eq!(*login, Some(true)); assert_eq!(*password, Some(Password::NullPassword)); } - err => panic!("Failed to parse CREATE ROLE test case: {:?}", err), + err => panic!("Failed to parse CREATE ROLE test case: {err:?}"), } let sql = "CREATE ROLE magician WITH SUPERUSER CREATEROLE NOCREATEDB BYPASSRLS INHERIT PASSWORD 'abcdef' LOGIN VALID UNTIL '2025-01-01' IN ROLE role1, role2 ROLE role3 ADMIN role4, role5 REPLICATION"; @@ -2141,7 +2141,7 @@ fn parse_create_role() { assert_eq_vec(&["role4", "role5"], admin); assert_eq!(*authorization_owner, None); } - err => panic!("Failed to parse CREATE ROLE test case: {:?}", err), + err => panic!("Failed to parse CREATE ROLE test case: {err:?}"), } let sql = "CREATE ROLE abc WITH USER foo, bar ROLE baz "; @@ -2155,7 +2155,7 @@ fn parse_create_role() { assert_eq_vec(&["foo", "bar"], user); assert_eq_vec(&["baz"], role); } - err => panic!("Failed to parse CREATE ROLE test case: {:?}", err), + err => panic!("Failed to parse CREATE ROLE test case: {err:?}"), } let negatables = vec![ @@ -2169,9 +2169,9 @@ fn parse_create_role() { ]; for negatable_kw in negatables.iter() { - let sql = format!("CREATE ROLE abc {kw} NO{kw}", kw = negatable_kw); + let sql = format!("CREATE ROLE abc {negatable_kw} NO{negatable_kw}"); if pg().parse_sql_statements(&sql).is_ok() { - panic!("Should not be able to parse CREATE ROLE containing both negated and non-negated versions of the same keyword: {}", negatable_kw) + panic!("Should not be able to parse CREATE ROLE containing both negated and non-negated versions of the same keyword: {negatable_kw}") } } }