Skip to content
Open
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
12 changes: 6 additions & 6 deletions cargo-pgrx/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ impl Cargo {
}

// subcommand *must* go first among subcommand-relative args
if self.subcmd != "" {
if !self.subcmd.is_empty() {
cmd.arg(&self.subcmd);
} else {
panic!("`Cargo::into_command` requires a subcommand to be set, was: {self:?}")
}

let Cargo {
let Self {
features,
stdio,
manifest,
Expand Down Expand Up @@ -186,9 +186,9 @@ pub enum Stdio {
impl Stdio {
fn into_stdio(self) -> Option<process::Stdio> {
match self {
Stdio::Inherit => Some(process::Stdio::inherit()),
Stdio::Null => Some(process::Stdio::null()),
Stdio::Default => None,
Self::Inherit => Some(process::Stdio::inherit()),
Self::Null => Some(process::Stdio::null()),
Self::Default => None,
}
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ pub enum CargoProfile {
}

impl CargoProfile {
pub fn from_flags(profile: Option<&str>, default: CargoProfile) -> eyre::Result<Self> {
pub fn from_flags(profile: Option<&str>, default: Self) -> eyre::Result<Self> {
match profile {
// Cargo treats `--profile release` the same as `--release`.
Some("release") => Ok(Self::Release),
Expand Down
6 changes: 2 additions & 4 deletions cargo-pgrx/src/command/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,8 @@ impl CommandExecute for Bench {
baseline.as_ref(),
compare_group.as_ref().map(|group| group.group_name.as_str()),
));
if show_human_output {
if let Some(completed_benchmark) = summary_benchmarks.last() {
print_completed_benchmark(completed_benchmark);
}
if show_human_output && let Some(completed_benchmark) = summary_benchmarks.last() {
print_completed_benchmark(completed_benchmark);
}
}

Expand Down
27 changes: 13 additions & 14 deletions cargo-pgrx/src/command/regress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ impl CommandExecute for Regress {

// When the user explicitly filters, error if any matched test
// has no expected output (they should use --add first)
let output_names =
output_files.iter().map(|e| make_test_name(e)).collect::<HashSet<_>>();
let output_names = output_files.iter().map(make_test_name).collect::<HashSet<_>>();
for entry in &test_files {
let name = make_test_name(entry);
if !output_names.contains(&name) {
Expand Down Expand Up @@ -577,7 +576,7 @@ impl Regress {
} else {
// Run setup.sql normally to establish schema/data
let verbosity = &self.psql_verbosity.clone().unwrap_or("terse".into());
run_tests(pg_config, pgregress_path, dbname, &[&setup_entry], verbosity, 0)?;
run_tests(pg_config, pgregress_path, dbname, &[setup_entry], verbosity, 0)?;
}
}

Expand Down Expand Up @@ -633,16 +632,16 @@ impl Regress {
// List test files (without setup, then report)
let test_files = self.list_sql_tests(manifest_path, false)?;
let output_files = self.list_expected_outputs(manifest_path, false)?;
let output_names = output_files.iter().map(|e| make_test_name(e)).collect::<HashSet<_>>();
let output_names = output_files.iter().map(make_test_name).collect::<HashSet<_>>();

let mut ready = Vec::new();
let mut skipped = Vec::new();
for entry in &test_files {
let name = make_test_name(entry);
if let Some(ref filter) = self.test_filter {
if !name.contains(filter) {
continue;
}
if let Some(ref filter) = self.test_filter
&& !name.contains(filter)
{
continue;
}
if output_names.contains(&name) {
ready.push(name);
Expand Down Expand Up @@ -767,7 +766,7 @@ fn pg_regress(
use std::os::unix::fs::PermissionsExt;

let launcher_script =
format!("#! /bin/bash\n$* -v VERBOSITY={}", verbosity.to_string(),).into_bytes();
format!("#! /bin/bash\n$* -v VERBOSITY={}", verbosity,).into_bytes();

let path = temp_dir().join(format!("pgrx-pg_regress-runner-{}.sh", std::process::id()));
let mut tmpfile = File::create(&path)?;
Expand Down Expand Up @@ -837,11 +836,11 @@ fn print_regression_diffs(manifest_path: &Path, verbose: u8, run: u32, repeat: u
return;
}

if verbose >= 1 {
if let Ok(content) = std::fs::read_to_string(&diffs_path) {
eprintln!();
eprintln!("{content}");
}
if verbose >= 1
&& let Ok(content) = std::fs::read_to_string(&diffs_path)
{
eprintln!();
eprintln!("{content}");
}

// When repeating, rename to regression.<run>.diffs so each run's output is preserved
Expand Down
11 changes: 6 additions & 5 deletions cargo-pgrx/src/command/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) struct Run {

impl From<&Regress> for Run {
fn from(regress: &Regress) -> Self {
Run {
Self {
pg_version: regress.pg_version.clone(),
dbname: regress.dbname.clone(),
package: regress.package.clone(),
Expand All @@ -87,10 +87,11 @@ impl Run {

// If the first positional arg isn't a recognized PG version (pgXX)
// and no dbname was given, treat it as a dbname
if let Some(ref v) = self.pg_version {
if !pgrx.is_feature_flag(v) && self.dbname.is_none() {
self.dbname = self.pg_version.take();
}
if let Some(ref v) = self.pg_version
&& !pgrx.is_feature_flag(v)
&& self.dbname.is_none()
{
self.dbname = self.pg_version.take();
}

let (package_manifest, package_manifest_path) = get_package_manifest(
Expand Down
2 changes: 1 addition & 1 deletion cargo-pgrx/src/command/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ pub(crate) fn generate_schema_implicit(
.to_file(path)
.wrap_err_with(|| format!("Could not write SQL to {}", path.display()))?;
} else {
eprintln!("{} SQL entities to {}", " Writing".bold().green(), "/dev/stdout");
eprintln!("{} SQL entities to /dev/stdout", " Writing".bold().green());
pgrx_sql.write(&mut std::io::stdout()).wrap_err("Could not write SQL to stdout")?;
}

Expand Down
2 changes: 1 addition & 1 deletion cargo-pgrx/src/command/sudo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl From<Install> for SudoInstall {

impl From<SudoInstall> for Package {
fn from(value: SudoInstall) -> Self {
Package {
Self {
package: value.package,
manifest_path: value.manifest_path,
debug: !value.release,
Expand Down
10 changes: 6 additions & 4 deletions cargo-pgrx/src/command/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ impl CommandExecute for Test {

// If the first positional arg isn't a recognized PG version (pgXX or "all")
// and no testname was given, treat it as a testname filter
if let Some(ref v) = self.pg_version {
if v != "all" && !pgrx.is_feature_flag(v) && self.testname.is_none() {
self.testname = self.pg_version.take();
}
if let Some(ref v) = self.pg_version
&& v != "all"
&& !pgrx.is_feature_flag(v)
&& self.testname.is_none()
{
self.testname = self.pg_version.take();
}

if self.pg_version.as_deref() == Some("all") {
Expand Down
5 changes: 1 addition & 4 deletions cargo-pgrx/src/command/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ mod rss {
let mut buf = Vec::new();
let _count = response.body_mut().as_reader().read_to_end(&mut buf)?;
let body = String::from_utf8(buf)?;
let rss: Rss = match serde_xml_rs::from_str(&body) {
Ok(rss) => rss,
Err(e) => return Err(e.into()),
};
let rss: Rss = serde_xml_rs::from_str(&body)?;

let mut versions: BTreeMap<u16, PgVersion> = BTreeMap::from_iter(
supported_versions.iter().map(|pgver| (pgver.major, pgver.clone())),
Expand Down
8 changes: 4 additions & 4 deletions cargo-pgrx/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ impl From<PgVersionSource> for String {
impl PgVersionSource {
fn label(&self) -> &String {
match self {
PgVersionSource::CliArgument(s) => s,
PgVersionSource::FeatureFlag(s) => s,
PgVersionSource::DefaultFeature(s) => s,
PgVersionSource::PgConfig(s) => s,
Self::CliArgument(s) => s,
Self::FeatureFlag(s) => s,
Self::DefaultFeature(s) => s,
Self::PgConfig(s) => s,
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cargo-pgrx/src/object_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,15 @@ fn target_architecture() -> object::Architecture {
}
}

fn slice_arch32<'a>(data: &'a [u8], arch: object::Architecture) -> Option<&'a [u8]> {
fn slice_arch32(data: &[u8], arch: object::Architecture) -> Option<&[u8]> {
let candidates = MachOFatFile32::parse(data).ok()?;
let architecture =
candidates.arches().iter().find(|candidate| candidate.architecture() == arch)?;

architecture.data(data).ok()
}

fn slice_arch64<'a>(data: &'a [u8], arch: object::Architecture) -> Option<&'a [u8]> {
fn slice_arch64(data: &[u8], arch: object::Architecture) -> Option<&[u8]> {
let candidates = MachOFatFile64::parse(data).ok()?;
let architecture =
candidates.arches().iter().find(|candidate| candidate.architecture() == arch)?;
Expand Down
4 changes: 2 additions & 2 deletions pgrx-bindgen/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl BindingOverride {
fn new_from(enum_names: InnerMut<EnumMap>) -> Self {
// these cause duplicate definition problems on linux
// see: https://github.com/rust-lang/rust-bindgen/issues/687
BindingOverride {
Self {
ignore_macros: HashSet::from_iter([
"FP_INFINITE",
"FP_NAN",
Expand Down Expand Up @@ -599,7 +599,7 @@ struct StructGraph<'a> {
}

impl<'a> From<&'a [syn::Item]> for StructGraph<'a> {
fn from(items: &'a [syn::Item]) -> StructGraph<'a> {
fn from(items: &'a [syn::Item]) -> Self {
let mut descriptors = Vec::new();

// a table mapping struct names to their offset in `descriptors`
Expand Down
3 changes: 1 addition & 2 deletions pgrx-macros/src/rewriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ pub fn item_fn_without_rewrite(
let generics = func.sig.generics.clone();

// looking for this pattern: #[pg_guard(unsafe_entry_thread)]
let unsafe_entry_thread =
attr.into_iter().find(|tt| tt.to_string() == "unsafe_entry_thread").is_some();
let unsafe_entry_thread = attr.into_iter().any(|tt| tt.to_string() == "unsafe_entry_thread");

if sig.abi.clone().and_then(|abi| abi.name).is_none_or(|name| name.value() != "C-unwind") {
panic!("#[pg_guard] must be combined with extern \"C-unwind\"");
Expand Down
44 changes: 19 additions & 25 deletions pgrx-pg-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,19 @@ pub enum PgMinorVersion {
impl Display for PgMinorVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
PgMinorVersion::Latest => write!(f, ".LATEST"),
PgMinorVersion::Release(v) => write!(f, ".{v}"),
PgMinorVersion::Beta(v) => write!(f, "beta{v}"),
PgMinorVersion::Rc(v) => write!(f, "rc{v}"),
Self::Latest => write!(f, ".LATEST"),
Self::Release(v) => write!(f, ".{v}"),
Self::Beta(v) => write!(f, "beta{v}"),
Self::Rc(v) => write!(f, "rc{v}"),
}
}
}

impl PgMinorVersion {
fn version(&self) -> Option<u16> {
match self {
PgMinorVersion::Latest => None,
PgMinorVersion::Release(v) | PgMinorVersion::Beta(v) | PgMinorVersion::Rc(v) => {
Some(*v)
}
Self::Latest => None,
Self::Release(v) | Self::Beta(v) | Self::Rc(v) => Some(*v),
}
}
}
Expand All @@ -103,8 +101,8 @@ pub struct PgVersion {
}

impl PgVersion {
pub const fn new(major: u16, minor: PgMinorVersion, url: Option<Url>) -> PgVersion {
PgVersion { major, minor, url }
pub const fn new(major: u16, minor: PgMinorVersion, url: Option<Url>) -> Self {
Self { major, minor, url }
}

pub fn minor(&self) -> Option<u16> {
Expand Down Expand Up @@ -136,7 +134,7 @@ impl Display for PgConfig {

impl Default for PgConfig {
fn default() -> Self {
PgConfig {
Self {
version: None,
pg_config: None,
known_props: None,
Expand All @@ -149,13 +147,13 @@ impl Default for PgConfig {

impl From<PgVersion> for PgConfig {
fn from(version: PgVersion) -> Self {
PgConfig { version: Some(version), pg_config: None, ..Default::default() }
Self { version: Some(version), pg_config: None, ..Default::default() }
}
}

impl PgConfig {
pub fn new(pg_config: PathBuf, base_port: u16, base_testing_port: u16) -> Self {
PgConfig {
Self {
version: None,
pg_config: Some(pg_config),
known_props: None,
Expand All @@ -166,7 +164,7 @@ impl PgConfig {
}

pub fn new_with_defaults(pg_config: PathBuf) -> Self {
PgConfig {
Self {
version: None,
pg_config: Some(pg_config),
known_props: None,
Expand Down Expand Up @@ -579,33 +577,29 @@ pub enum PgrxHomeError {
impl From<PgrxHomeError> for std::io::Error {
fn from(value: PgrxHomeError) -> Self {
match value {
PgrxHomeError::NoHomeDirectory => {
std::io::Error::new(ErrorKind::NotFound, value.to_string())
}
PgrxHomeError::MissingPgrxHome(_) => {
std::io::Error::new(ErrorKind::NotFound, value.to_string())
}
PgrxHomeError::NoHomeDirectory => Self::new(ErrorKind::NotFound, value.to_string()),
PgrxHomeError::MissingPgrxHome(_) => Self::new(ErrorKind::NotFound, value.to_string()),
PgrxHomeError::IoError(e) => e,
}
}
}

impl Pgrx {
pub fn new(base_port: u16, base_testing_port: u16) -> Self {
Pgrx { pg_configs: vec![], base_port, base_testing_port }
Self { pg_configs: vec![], base_port, base_testing_port }
}

pub fn from_config() -> eyre::Result<Self> {
match std::env::var("PGRX_PG_CONFIG_PATH") {
Ok(pg_config) => {
// we have an environment variable that tells us the pg_config to use
let mut pgrx = Pgrx::default();
let mut pgrx = Self::default();
pgrx.push(PgConfig::new(pg_config.into(), pgrx.base_port, pgrx.base_testing_port));
Ok(pgrx)
}
Err(_) => {
// we'll get what we need from cargo-pgrx' config.toml file
let path = Pgrx::config_toml()?;
let path = Self::config_toml()?;
if !path.try_exists()? {
return Err(eyre!(
"{} not found. Have you run `{}` yet?",
Expand All @@ -616,7 +610,7 @@ impl Pgrx {

match toml::from_str::<ConfigToml>(&std::fs::read_to_string(&path)?) {
Ok(configs) => {
let mut pgrx = Pgrx::new(
let mut pgrx = Self::new(
configs.base_port.unwrap_or(BASE_POSTGRES_PORT_NO),
configs.base_testing_port.unwrap_or(BASE_POSTGRES_TESTING_PORT_NO),
);
Expand Down Expand Up @@ -723,7 +717,7 @@ impl Pgrx {
}

pub fn config_toml() -> Result<PathBuf, std::io::Error> {
let mut path = Pgrx::home()?;
let mut path = Self::home()?;
path.push("config.toml");
Ok(path)
}
Expand Down
Loading