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

style: simplify some statements for readability #1962

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
15 changes: 7 additions & 8 deletions cargo-pgrx/src/command/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ fn first_build(
command.arg(arg);
}

let command_str = format!("{:?}", command);
let command_str = format!("{command:?}");
eprintln!(
"{} for SQL generation with features `{}`",
" Building".bold().green(),
Expand All @@ -367,7 +367,7 @@ fn first_build(

tracing::debug!(command = %command_str, "Running");
let cargo_output =
command.output().wrap_err_with(|| format!("failed to spawn cargo: {}", command_str))?;
command.output().wrap_err_with(|| format!("failed to spawn cargo: {command_str}"))?;
tracing::trace!(status_code = %cargo_output.status, command = %command_str, "Finished");

if !cargo_output.status.success() {
Expand Down Expand Up @@ -522,7 +522,7 @@ fn second_build(

command.env("PGRX_EMBED", embed_path.as_ref());

let command_str = format!("{:?}", command);
let command_str = format!("{command:?}");
eprintln!(
"{} {}, in debug mode, for SQL generation with features {}",
" Rebuilding".bold().green(),
Expand All @@ -532,7 +532,7 @@ fn second_build(

tracing::debug!(command = %command_str, "Running");
let cargo_output =
command.output().wrap_err_with(|| format!("failed to spawn cargo: {}", command_str))?;
command.output().wrap_err_with(|| format!("failed to spawn cargo: {command_str}"))?;
tracing::trace!(status_code = %cargo_output.status, command = %command_str, "Finished");

if !cargo_output.status.success() {
Expand All @@ -559,11 +559,10 @@ fn compute_sql(package_name: &str, manifest: &Manifest) -> eyre::Result<()> {
});
command.env("CARGO_PKG_VERSION", cargo_pkg_version);

let command_str = format!("{:?}", command);
let command_str = format!("{command:?}");
tracing::debug!(command = %command_str, "Running");
let embed_output = command
.output()
.wrap_err_with(|| format!("failed to spawn pgrx_embed: {}", command_str))?;
let embed_output =
command.output().wrap_err_with(|| format!("failed to spawn pgrx_embed: {command_str}"))?;
tracing::trace!(status_code = %embed_output.status, command = %command_str, "Finished");

if !embed_output.status.success() {
Expand Down
24 changes: 12 additions & 12 deletions pgrx-sql-entity-graph/src/aggregate/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl ToSql for PgAggregateEntity {

if let Some(value) = self.finalfunc {
optional_attributes.push((
format!("\tFINALFUNC = {}\"{}\"", schema, value),
format!("\tFINALFUNC = {schema}\"{value}\""),
format!("/* {}::final */", self.full_path),
));
}
Expand All @@ -190,43 +190,43 @@ impl ToSql for PgAggregateEntity {
}
if let Some(value) = self.combinefunc {
optional_attributes.push((
format!("\tCOMBINEFUNC = {}\"{}\"", schema, value),
format!("\tCOMBINEFUNC = {schema}\"{value}\""),
format!("/* {}::combine */", self.full_path),
));
}
if let Some(value) = self.serialfunc {
optional_attributes.push((
format!("\tSERIALFUNC = {}\"{}\"", schema, value),
format!("\tSERIALFUNC = {schema}\"{value}\""),
format!("/* {}::serial */", self.full_path),
));
}
if let Some(value) = self.deserialfunc {
optional_attributes.push((
format!("\tDESERIALFUNC ={} \"{}\"", schema, value),
format!("\tDESERIALFUNC ={schema} \"{value}\""),
format!("/* {}::deserial */", self.full_path),
));
}
if let Some(value) = self.initcond {
optional_attributes.push((
format!("\tINITCOND = '{}'", value),
format!("\tINITCOND = '{value}'"),
format!("/* {}::INITIAL_CONDITION */", self.full_path),
));
}
if let Some(value) = self.msfunc {
optional_attributes.push((
format!("\tMSFUNC = {}\"{}\"", schema, value),
format!("\tMSFUNC = {schema}\"{value}\""),
format!("/* {}::moving_state */", self.full_path),
));
}
if let Some(value) = self.minvfunc {
optional_attributes.push((
format!("\tMINVFUNC = {}\"{}\"", schema, value),
format!("\tMINVFUNC = {schema}\"{value}\""),
format!("/* {}::moving_state_inverse */", self.full_path),
));
}
if let Some(value) = self.mfinalfunc {
optional_attributes.push((
format!("\tMFINALFUNC = {}\"{}\"", schema, value),
format!("\tMFINALFUNC = {schema}\"{value}\""),
format!("/* {}::moving_state_finalize */", self.full_path),
));
}
Expand All @@ -238,13 +238,13 @@ impl ToSql for PgAggregateEntity {
}
if let Some(value) = self.minitcond {
optional_attributes.push((
format!("\tMINITCOND = '{}'", value),
format!("\tMINITCOND = '{value}'"),
format!("/* {}::MOVING_INITIAL_CONDITION */", self.full_path),
));
}
if let Some(value) = self.sortop {
optional_attributes.push((
format!("\tSORTOP = \"{}\"", value),
format!("\tSORTOP = \"{value}\""),
format!("/* {}::SORT_OPERATOR */", self.full_path),
));
}
Expand Down Expand Up @@ -290,7 +290,7 @@ impl ToSql for PgAggregateEntity {
if let Some(value) = &self.mstype {
let mstype_sql = map_ty(value).wrap_err("Mapping moving state type")?;
optional_attributes.push((
format!("\tMSTYPE = {}", mstype_sql),
format!("\tMSTYPE = {mstype_sql}"),
format!("/* {}::MovingState = {} */", self.full_path, value.full_path),
));
}
Expand Down Expand Up @@ -348,7 +348,7 @@ impl ToSql for PgAggregateEntity {
maybe_comma = if needs_comma { ", " } else { " " },
full_path = arg.used_ty.full_path,
name = if let Some(name) = arg.name {
format!(r#""{}" "#, name)
format!(r#""{name}" "#)
} else { "".to_string() },
);
args.push(buf);
Expand Down
21 changes: 10 additions & 11 deletions pgrx-sql-entity-graph/src/extension_sql/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ impl ToSql for ExtensionSqlEntity {
fn to_sql(&self, _context: &PgrxSql) -> eyre::Result<String> {
let ExtensionSqlEntity { file, line, sql, creates, requires, .. } = self;
let creates = if !creates.is_empty() {
let joined =
creates.iter().map(|i| format!("-- {}", i)).collect::<Vec<_>>().join("\n");
let joined = creates.iter().map(|i| format!("-- {i}")).collect::<Vec<_>>().join("\n");
format!(
"\
-- creates:\n\
Expand All @@ -84,7 +83,7 @@ impl ToSql for ExtensionSqlEntity {
};
let requires = if !requires.is_empty() {
let joined =
requires.iter().map(|i| format!("-- {}", i)).collect::<Vec<_>>().join("\n");
requires.iter().map(|i| format!("-- {i}")).collect::<Vec<_>>().join("\n");
format!(
"\
-- requires:\n\
Expand Down Expand Up @@ -156,14 +155,14 @@ impl SqlDeclaredEntity {
.ok_or_else(|| eyre::eyre!("Did not get SQL for `{}`", name))?
.to_string(),
name: name.to_string(),
option: format!("Option<{}>", name),
vec: format!("Vec<{}>", name),
vec_option: format!("Vec<Option<{}>>", name),
option_vec: format!("Option<Vec<{}>>", name),
option_vec_option: format!("Option<Vec<Option<{}>>", name),
array: format!("Array<{}>", name),
option_array: format!("Option<{}>", name),
varlena: format!("Varlena<{}>", name),
option: format!("Option<{name}>"),
vec: format!("Vec<{name}>"),
vec_option: format!("Vec<Option<{name}>>"),
option_vec: format!("Option<Vec<{name}>>"),
option_vec_option: format!("Option<Vec<Option<{name}>>"),
array: format!("Array<{name}>"),
option_array: format!("Option<{name}>"),
varlena: format!("Varlena<{name}>"),
pg_box: vec![
format!("pgrx::pgbox::PgBox<{}>", name),
format!("pgrx::pgbox::PgBox<{}, pgrx::pgbox::AllocatedByRust>", name),
Expand Down
2 changes: 1 addition & 1 deletion pgrx-sql-entity-graph/src/extension_sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl Parse for ExtensionSqlAttribute {
other => {
return Err(syn::Error::new(
ident.span(),
format!("Unknown extension_sql attribute: {}", other),
format!("Unknown extension_sql attribute: {other}"),
))
}
};
Expand Down
2 changes: 1 addition & 1 deletion pgrx-sql-entity-graph/src/extern_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl core::fmt::Display for ExternArgs {
ExternArgs::NoGuard => Ok(()),
ExternArgs::Schema(_) => Ok(()),
ExternArgs::Name(_) => Ok(()),
ExternArgs::Cost(cost) => write!(f, "COST {}", cost),
ExternArgs::Cost(cost) => write!(f, "COST {cost}"),
ExternArgs::Requires(_) => Ok(()),
}
}
Expand Down
20 changes: 10 additions & 10 deletions pgrx-sql-entity-graph/src/pg_extern/entity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl ToSql for PgExternEntity {
let module_pathname = &context.get_module_pathname();
let schema = self
.schema
.map(|schema| format!("{}.", schema))
.map(|schema| format!("{schema}."))
.unwrap_or_else(|| context.schema_prefix_for(&self_index));
let arguments = if !self.fn_args.is_empty() {
let mut args = Vec::new();
Expand All @@ -130,7 +130,7 @@ impl ToSql for PgExternEntity {
schema_prefix = context.schema_prefix_for(&graph_index),
// First try to match on [`TypeId`] since it's most reliable.
sql_type = argument_sql,
default = if let Some(def) = arg.used_ty.default { format!(" DEFAULT {}", def) } else { String::from("") },
default = if let Some(def) = arg.used_ty.default { format!(" DEFAULT {def}") } else { String::from("") },
variadic = if metadata_argument.variadic { "VARIADIC " } else { "" },
maybe_comma = if needs_comma { ", " } else { " " },
type_name = metadata_argument.type_name,
Expand All @@ -154,7 +154,7 @@ impl ToSql for PgExternEntity {
schema_prefix = context.schema_prefix_for(&graph_index),
// First try to match on [`TypeId`] since it's most reliable.
sql_type = sql,
default = if let Some(def) = arg.used_ty.default { format!(" DEFAULT {}", def) } else { String::from("") },
default = if let Some(def) = arg.used_ty.default { format!(" DEFAULT {def}") } else { String::from("") },
variadic = if metadata_argument.variadic { "VARIADIC " } else { "" },
maybe_comma = if needs_comma { ", " } else { " " },
type_name = metadata_argument.type_name,
Expand Down Expand Up @@ -255,7 +255,7 @@ impl ToSql for PgExternEntity {
);
items.push_str(&item);
}
format!("RETURNS TABLE ({}\n)", items)
format!("RETURNS TABLE ({items}\n)")
}
PgExternReturnEntity::Trigger => String::from("RETURNS trigger"),
};
Expand Down Expand Up @@ -307,7 +307,7 @@ impl ToSql for PgExternEntity {
"-- requires:\n{}\n",
requires_attrs
.iter()
.map(|i| format!("-- {}", i))
.map(|i| format!("-- {i}"))
.collect::<Vec<_>>()
.join("\n")
)
Expand All @@ -327,16 +327,16 @@ impl ToSql for PgExternEntity {
if let Some(op) = &self.operator {
let mut optionals = vec![];
if let Some(it) = op.commutator {
optionals.push(format!("\tCOMMUTATOR = {}", it));
optionals.push(format!("\tCOMMUTATOR = {it}"));
};
if let Some(it) = op.negator {
optionals.push(format!("\tNEGATOR = {}", it));
optionals.push(format!("\tNEGATOR = {it}"));
};
if let Some(it) = op.restrict {
optionals.push(format!("\tRESTRICT = {}", it));
optionals.push(format!("\tRESTRICT = {it}"));
};
if let Some(it) = op.join {
optionals.push(format!("\tJOIN = {}", it));
optionals.push(format!("\tJOIN = {it}"));
};
if op.hashes {
optionals.push(String::from("\tHASHES"));
Expand Down Expand Up @@ -423,7 +423,7 @@ impl ToSql for PgExternEntity {

let schema = self
.schema
.map(|schema| format!("{}.", schema))
.map(|schema| format!("{schema}."))
.unwrap_or_else(|| context.schema_prefix_for(&self_index));

let operator_sql = format!("\n\n\
Expand Down
8 changes: 4 additions & 4 deletions pgrx-sql-entity-graph/src/pgrx_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl PgrxSql {
create_dir_all(parent)?;
}
let mut out = File::create(path)?;
write!(out, "{}", generated)?;
write!(out, "{generated}")?;
Ok(())
}

Expand All @@ -281,7 +281,7 @@ impl PgrxSql {

#[cfg(not(feature = "syntax-highlighting"))]
{
write!(*out, "{}", generated)?;
write!(*out, "{generated}")?;
}

Ok(())
Expand Down Expand Up @@ -382,7 +382,7 @@ impl PgrxSql {
create_dir_all(parent)?;
}
let mut out = File::create(path)?;
write!(out, "{:?}", generated)?;
write!(out, "{generated:?}")?;
Ok(())
}

Expand Down Expand Up @@ -456,7 +456,7 @@ impl PgrxSql {
let extname = &self.extension_name;
let extver = &self.control.default_version;
// Note: versioned so-name format must agree with cargo pgrx
format!("$libdir/{}-{}", extname, extver)
format!("$libdir/{extname}-{extver}")
} else {
String::from("MODULE_PATHNAME")
}
Expand Down
2 changes: 1 addition & 1 deletion pgrx-sql-entity-graph/src/postgres_enum/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ToSql for PostgresEnumEntity {
variants = self
.variants
.iter()
.map(|variant| format!("\t'{}'", variant))
.map(|variant| format!("\t'{variant}'"))
.collect::<Vec<_>>()
.join(",\n")
+ "\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
warning: elided lifetime has a name
--> tests/compile-fail/table-iterators-arent-immortal.rs:6:19
|
6 | ) -> TableIterator<(name!(a, &'static str), name!(b, Option<&'static str>))> {
| ^ this elided lifetime gets resolved as `'static`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
help: consider specifying it explicitly
|
6 | ) -> TableIterator<'static, (name!(a, &'static str), name!(b, Option<&'static str>))> {
| ++++++++

error[E0521]: borrowed data escapes outside of function
--> tests/compile-fail/table-iterators-arent-immortal.rs:6:78
|
Expand Down
Loading
Loading