Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix clippy error in ci #803

Merged
merged 2 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/parse_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ fn main() {

let ast = Parser::parse_sql(&dialect, sql).unwrap();

println!("AST: {:?}", ast);
println!("AST: {ast:?}");
}
22 changes: 11 additions & 11 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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(", "))
}
Expand Down Expand Up @@ -292,9 +292,9 @@ fn format_type_with_optional_length(
len: &Option<u64>,
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")?;
Expand All @@ -307,9 +307,9 @@ fn format_character_string_type(
sql_type: &str,
size: &Option<CharacterLength>,
) -> fmt::Result {
write!(f, "{}", sql_type)?;
write!(f, "{sql_type}")?;
if let Some(size) = size {
write!(f, "({})", size)?;
write!(f, "({size})")?;
}
Ok(())
}
Expand All @@ -320,7 +320,7 @@ fn format_datetime_precision_and_tz(
len: &Option<u64>,
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 {
Expand Down Expand Up @@ -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(())
}
Expand Down
54 changes: 25 additions & 29 deletions src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -183,29 +183,25 @@ 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,
new_name,
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 {
write!(f, " {}", display_separated(options, " "))
}
}
AlterTableOperation::RenameConstraint { old_name, new_name } => {
write!(f, "RENAME CONSTRAINT {} TO {}", old_name, new_name)
write!(f, "RENAME CONSTRAINT {old_name} TO {new_name}")
}
}
}
Expand All @@ -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}")
}
}
}
Expand Down Expand Up @@ -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}")
}
}
}
Expand Down Expand Up @@ -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(())
}
Expand All @@ -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))?;

Expand All @@ -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))?;
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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" })
}
Expand All @@ -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}"),
}
}
}
Expand All @@ -616,7 +612,7 @@ fn display_constraint_name(name: &'_ Option<Ident>) -> 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(())
}
Expand Down
Loading