Skip to content

Commit 4ba35f0

Browse files
Replace with let-chains in pgrx-sql-entity-graph (pgcentralfoundation#2169)
The real reason for pgcentralfoundation#2165
1 parent 5bc9418 commit 4ba35f0

5 files changed

Lines changed: 29 additions & 35 deletions

File tree

pgrx-sql-entity-graph/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,3 @@ syntect = { version = "5.2.0", default-features = false, features = ["default-fa
4343
[lints.clippy]
4444
assigning-clones = "allow" # wrong diagnosis and wrong suggestions
4545
too-many-arguments = "allow" # I argue with myself all the time
46-
collapsible-if = "allow" # nuisance in the way of updating editions

pgrx-sql-entity-graph/src/aggregate/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,18 @@ fn extract_generic_from_trait(item_impl: &ItemImpl) -> Result<&Type, syn::Error>
158158
}
159159

160160
fn get_generic_type_name(ty: &syn::Type) -> Result<String, syn::Error> {
161-
if let Type::Path(type_path) = ty {
162-
if let Some(ident) = type_path.path.segments.last().map(|s| &s.ident) {
163-
let ident = ident.to_string();
164-
165-
match ident.as_str() {
166-
"!" => Ok("never".to_string()),
167-
"()" => Ok("unit".to_string()),
168-
_ => Ok(ident),
169-
}
170-
} else {
171-
Err(syn::Error::new_spanned(ty, "Generic type path is empty or malformed."))
161+
if let Type::Path(type_path) = ty
162+
&& let Some(ident) = type_path.path.segments.last().map(|s| &s.ident)
163+
{
164+
let ident = ident.to_string();
165+
166+
match ident.as_str() {
167+
"!" => Ok("never".to_string()),
168+
"()" => Ok("unit".to_string()),
169+
_ => Ok(ident),
172170
}
173171
} else {
174-
Err(syn::Error::new_spanned(ty, "Expected a path type for the generic argument."))
172+
Err(syn::Error::new_spanned(ty, "Generic type path is empty or malformed."))
175173
}
176174
}
177175

pgrx-sql-entity-graph/src/pgrx_sql.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,15 @@ fn initialize_extension_sqls(
522522
}
523523
for (item, index) in &mapped_extension_sqls {
524524
graph.add_edge(root, *index, SqlGraphRequires::By);
525-
if !item.bootstrap {
526-
if let Some(bootstrap) = bootstrap {
527-
graph.add_edge(bootstrap, *index, SqlGraphRequires::By);
528-
}
525+
if !item.bootstrap
526+
&& let Some(bootstrap) = bootstrap
527+
{
528+
graph.add_edge(bootstrap, *index, SqlGraphRequires::By);
529529
}
530-
if !item.finalize {
531-
if let Some(finalize) = finalize {
532-
graph.add_edge(*index, finalize, SqlGraphRequires::By);
533-
}
530+
if !item.finalize
531+
&& let Some(finalize) = finalize
532+
{
533+
graph.add_edge(*index, finalize, SqlGraphRequires::By);
534534
}
535535
}
536536
Ok((mapped_extension_sqls, bootstrap, finalize))

pgrx-sql-entity-graph/src/postgres_type/entity.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ impl Alignment {
8282

8383
pub fn from_attributes(attrs: &[Attribute]) -> Result<Self, syn::Error> {
8484
for attr in attrs {
85-
if attr.path().is_ident("pgrx") {
86-
if let Some(v) = Self::from_attribute(attr)? {
87-
return Ok(v);
88-
}
85+
if attr.path().is_ident("pgrx")
86+
&& let Some(v) = Self::from_attribute(attr)?
87+
{
88+
return Ok(v);
8989
}
9090
}
9191
Ok(Self::Off)

pgrx-sql-entity-graph/src/used_type.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,13 @@ impl UsedType {
274274

275275
// if the Type is like `Result<T, E>`, this finds the `T`
276276
let mut resolved_ty_inner: Option<syn::Type> = None;
277-
if result {
278-
if let syn::Type::Path(tp) = &resolved_ty {
279-
if let Some(first_segment) = tp.path.segments.first() {
280-
if let syn::PathArguments::AngleBracketed(ab) = &first_segment.arguments {
281-
if let Some(syn::GenericArgument::Type(ty)) = ab.args.first() {
282-
resolved_ty_inner = Some(ty.clone());
283-
}
284-
}
285-
}
286-
}
277+
if result
278+
&& let syn::Type::Path(tp) = &resolved_ty
279+
&& let Some(first_segment) = tp.path.segments.first()
280+
&& let syn::PathArguments::AngleBracketed(ab) = &first_segment.arguments
281+
&& let Some(syn::GenericArgument::Type(ty)) = ab.args.first()
282+
{
283+
resolved_ty_inner = Some(ty.clone());
287284
}
288285

289286
Ok(Self {

0 commit comments

Comments
 (0)