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

Make sql-entity-graph clippy-clean #1420

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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ jobs:
- name: Clippy -Awarnings
run: cargo clippy -p pgrx --features pg$PG_VER -- -Awarnings

- name: Clippy -Dwarnings sql-entity-graph
run: cargo clippy -p pgrx-sql-entity-graph -- -Dwarnings

- name: Check doc-links
run: |
cargo rustdoc -p pgrx --features pg$PG_VER -- \
Expand Down
82 changes: 35 additions & 47 deletions pgrx-sql-entity-graph/src/aggregate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,47 +782,41 @@ fn pg_extern_attr(item: &ImplItemMethod) -> syn::Attribute {

fn get_impl_type_by_name<'a>(item_impl: &'a ItemImpl, name: &str) -> Option<&'a ImplItemType> {
let mut needle = None;
for impl_item in item_impl.items.iter() {
match impl_item {
syn::ImplItem::Type(impl_item_type) => {
let ident_string = impl_item_type.ident.to_string();
if ident_string == name {
needle = Some(impl_item_type);
}
}
_ => (),
for impl_item_type in item_impl.items.iter().filter_map(|impl_item| match impl_item {
syn::ImplItem::Type(iitype) => Some(iitype),
_ => None,
}) {
let ident_string = impl_item_type.ident.to_string();
if ident_string == name {
needle = Some(impl_item_type);
}
}
needle
}

fn get_impl_func_by_name<'a>(item_impl: &'a ItemImpl, name: &str) -> Option<&'a ImplItemMethod> {
let mut needle = None;
for impl_item in item_impl.items.iter() {
match impl_item {
syn::ImplItem::Method(impl_item_method) => {
let ident_string = impl_item_method.sig.ident.to_string();
if ident_string == name {
needle = Some(impl_item_method);
}
}
_ => (),
for impl_item_method in item_impl.items.iter().filter_map(|impl_item| match impl_item {
syn::ImplItem::Method(iimethod) => Some(iimethod),
_ => None,
}) {
let ident_string = impl_item_method.sig.ident.to_string();
if ident_string == name {
needle = Some(impl_item_method);
}
}
needle
}

fn get_impl_const_by_name<'a>(item_impl: &'a ItemImpl, name: &str) -> Option<&'a ImplItemConst> {
let mut needle = None;
for impl_item in item_impl.items.iter() {
match impl_item {
syn::ImplItem::Const(impl_item_const) => {
let ident_string = impl_item_const.ident.to_string();
if ident_string == name {
needle = Some(impl_item_const);
}
}
_ => (),
for impl_item_const in item_impl.items.iter().filter_map(|impl_item| match impl_item {
syn::ImplItem::Const(iiconst) => Some(iiconst),
_ => None,
}) {
let ident_string = impl_item_const.ident.to_string();
if ident_string == name {
needle = Some(impl_item_const);
}
}
needle
Expand Down Expand Up @@ -868,30 +862,24 @@ fn get_const_litstr(item: &ImplItemConst) -> syn::Result<Option<String>> {
}

fn remap_self_to_target(ty: &mut syn::Type, target: &syn::Ident) {
match ty {
Type::Path(ref mut ty_path) => {
for segment in ty_path.path.segments.iter_mut() {
if segment.ident == "Self" {
segment.ident = target.clone()
}
use syn::{GenericArgument, PathArguments};
match segment.arguments {
PathArguments::AngleBracketed(ref mut angle_args) => {
for arg in angle_args.args.iter_mut() {
match arg {
GenericArgument::Type(inner_ty) => {
remap_self_to_target(inner_ty, target)
}
_ => (),
}
if let Type::Path(ref mut ty_path) = ty {
for segment in ty_path.path.segments.iter_mut() {
if segment.ident == "Self" {
segment.ident = target.clone()
}
use syn::{GenericArgument, PathArguments};
match segment.arguments {
PathArguments::AngleBracketed(ref mut angle_args) => {
for arg in angle_args.args.iter_mut() {
if let GenericArgument::Type(inner_ty) = arg {
remap_self_to_target(inner_ty, target)
}
}
PathArguments::Parenthesized(_) => (),
PathArguments::None => (),
}
PathArguments::Parenthesized(_) => (),
PathArguments::None => (),
}
}
_ => (),
}
}

Expand All @@ -908,7 +896,7 @@ fn get_pgrx_attr_macro(attr_name: impl AsRef<str>, ty: &syn::Type) -> Option<Tok
_ => (),
}
}
if (ty_macro.mac.path.segments.len() == 1 && found_attr) || (found_pgrx && found_attr) {
if (found_pgrx || ty_macro.mac.path.segments.len() == 1) && found_attr {
Some(ty_macro.mac.tokens.clone())
} else {
None
Expand Down
18 changes: 9 additions & 9 deletions pgrx-sql-entity-graph/src/extension_sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ impl Parse for CodeEnrichment<ExtensionSql> {
let sql = input.parse()?;
let _after_sql_comma: Option<Token![,]> = input.parse()?;
let attrs = input.parse_terminated(ExtensionSqlAttribute::parse)?;
let mut name = None;
for attr in &attrs {
match attr {
ExtensionSqlAttribute::Name(found_name) => {
name = Some(found_name.clone());
}
_ => (),
}
}
// it's rfind_map
let name = attrs
.iter()
.filter_map(|attr| match attr {
ExtensionSqlAttribute::Name(found_name) => Some(found_name),
_ => None,
})
.cloned()
.next_back();
let name =
name.ok_or_else(|| syn::Error::new(input.span(), "expected `name` to be set"))?;
Ok(CodeEnrichment(ExtensionSql { sql, attrs, name }))
Expand Down
21 changes: 9 additions & 12 deletions pgrx-sql-entity-graph/src/pg_extern/returning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ impl Returning {
}
}

fn match_type(ty: &Box<Type>) -> Result<Returning, Error> {
let mut ty = *ty.clone();
fn match_type(ty: &Type) -> Result<Returning, Error> {
let mut ty = Box::new(ty.clone());

match ty {
match *ty {
syn::Type::Path(mut typepath) => {
let path = &mut typepath.path;
let mut saw_option_ident = false;
Expand Down Expand Up @@ -120,15 +120,12 @@ impl Returning {
"Option" => match &segment.arguments {
PathArguments::AngleBracketed(bracketed) => {
match bracketed.args.first().unwrap() {
GenericArgument::Type(ty) => match ty {
Type::Path(this_path) => {
segments = this_path.path.segments.clone();
saw_option_ident = true;
found_option = true;
continue 'outer;
}
_ => continue,
},
GenericArgument::Type(Type::Path(this_path)) => {
segments = this_path.path.segments.clone();
saw_option_ident = true;
found_option = true;
continue 'outer;
}
_ => continue,
};
}
Expand Down
Loading