Skip to content

Commit

Permalink
Pretty clippy suggestions to use .flatten() instead of if let Some
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed May 14, 2021
1 parent a79772e commit 844a812
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 69 deletions.
126 changes: 62 additions & 64 deletions src/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,76 +1033,74 @@ impl Library {
let namespace_name = self.namespaces[MAIN_NAMESPACE as usize].name.clone();
let mut parents = HashSet::new();

for x in &self.namespace(MAIN_NAMESPACE).types {
if let Some(x) = x {
let name = x.get_name();
let full_name = format!("{}.{}", namespace_name, name);
let mut check_methods = true;

if !not_allowed_ending.iter().any(|s| name.ends_with(s))
|| x.is_enumeration()
|| x.is_bitfield()
for x in self.namespace(MAIN_NAMESPACE).types.iter().flatten() {
let name = x.get_name();
let full_name = format!("{}.{}", namespace_name, name);
let mut check_methods = true;

if !not_allowed_ending.iter().any(|s| name.ends_with(s))
|| x.is_enumeration()
|| x.is_bitfield()
{
let version = x.get_deprecated_version();
let depr_version = version.unwrap_or(env.config.min_cfg_version);
if !env.analysis.objects.contains_key(&full_name)
&& !env.analysis.records.contains_key(&full_name)
&& !env.config.objects.iter().any(|o| o.1.name == full_name)
&& depr_version >= env.config.min_cfg_version
{
let version = x.get_deprecated_version();
let depr_version = version.unwrap_or(env.config.min_cfg_version);
if !env.analysis.objects.contains_key(&full_name)
&& !env.analysis.records.contains_key(&full_name)
&& !env.config.objects.iter().any(|o| o.1.name == full_name)
&& depr_version >= env.config.min_cfg_version
check_methods = false;
if let Some(version) = version {
println!("[NOT GENERATED] {} (deprecated in {})", full_name, version);
} else {
println!("[NOT GENERATED] {}", full_name);
}
} else if let Type::Class(Class { properties, .. }) = x {
if !env
.config
.objects
.get(&full_name)
.map(|obj| obj.generate_builder)
.unwrap_or_else(|| false)
&& properties
.iter()
.any(|prop| prop.construct_only || prop.construct || prop.writable)
{
check_methods = false;
if let Some(version) = version {
println!("[NOT GENERATED] {} (deprecated in {})", full_name, version);
} else {
println!("[NOT GENERATED] {}", full_name);
}
} else if let Type::Class(Class { properties, .. }) = x {
if !env
.config
.objects
.get(&full_name)
.map(|obj| obj.generate_builder)
.unwrap_or_else(|| false)
&& properties
.iter()
.any(|prop| prop.construct_only || prop.construct || prop.writable)
{
println!("[NOT GENERATED BUILDER] {}Builder", full_name);
}
println!("[NOT GENERATED BUILDER] {}Builder", full_name);
}
}
if let Some(tid) = env.library.find_type(0, &full_name) {
let gobject_id = env.library.find_type(0, "GObject.Object").unwrap();

for &super_tid in env.class_hierarchy.supertypes(tid) {
let ty = env.library.type_(super_tid);
let ns_id = super_tid.ns_id as usize;
let full_parent_name =
format!("{}.{}", self.namespaces[ns_id].name, ty.get_name());
if super_tid != gobject_id
&& env
.type_status(&super_tid.full_name(&env.library))
.ignored()
&& parents.insert(full_parent_name.clone())
{
if let Some(version) = ty.get_deprecated_version() {
println!(
"[NOT GENERATED PARENT] {} (deprecated in {})",
full_parent_name, version
);
} else {
println!("[NOT GENERATED PARENT] {}", full_parent_name);
}
}
if let Some(tid) = env.library.find_type(0, &full_name) {
let gobject_id = env.library.find_type(0, "GObject.Object").unwrap();

for &super_tid in env.class_hierarchy.supertypes(tid) {
let ty = env.library.type_(super_tid);
let ns_id = super_tid.ns_id as usize;
let full_parent_name =
format!("{}.{}", self.namespaces[ns_id].name, ty.get_name());
if super_tid != gobject_id
&& env
.type_status(&super_tid.full_name(&env.library))
.ignored()
&& parents.insert(full_parent_name.clone())
{
if let Some(version) = ty.get_deprecated_version() {
println!(
"[NOT GENERATED PARENT] {} (deprecated in {})",
full_parent_name, version
);
} else {
println!("[NOT GENERATED PARENT] {}", full_parent_name);
}
}
if check_methods {
self.not_bound_functions(
env,
&format!("{}::", full_name),
x.functions(),
"METHOD",
);
}
}
if check_methods {
self.not_bound_functions(
env,
&format!("{}::", full_name),
x.functions(),
"METHOD",
);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ pub trait FunctionsMutVisitor {

impl Namespace {
pub fn visit_functions_mut<V: FunctionsMutVisitor>(&mut self, visitor: &mut V) -> bool {
for type_ in &mut self.types {
if let Some(type_) = type_ {
if !type_.visit_functions_mut(visitor) {
return false;
}
for type_ in self.types.iter_mut().flatten() {
if !type_.visit_functions_mut(visitor) {
return false;
}
}
true
Expand Down

0 comments on commit 844a812

Please sign in to comment.