Skip to content

Commit

Permalink
Manual: replace unwrap_or(false|true, ...) -> is_some_and(...) or…
Browse files Browse the repository at this point in the history
… comparison
  • Loading branch information
Bromeon committed Jan 11, 2025
1 parent ac26a44 commit 82168d0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
6 changes: 3 additions & 3 deletions godot-core/src/builtin/variant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ impl Drop for Variant {
// Variant is not Eq because it can contain floats and other types composed of floats.
impl PartialEq for Variant {
fn eq(&self, other: &Self) -> bool {
Self::evaluate(self, other, VariantOperator::EQUAL)
.map(|v| v.to::<bool>())
.unwrap_or(false) // if there is no defined conversion, then they are non-equal
Self::evaluate(self, other, VariantOperator::EQUAL) //.
.is_some_and(|v| v.to::<bool>())
// If there is no defined conversion (-> None), then they are non-equal.
}
}

Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/meta/args/ref_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,6 @@ where
}

fn is_null(&self) -> bool {
self.shared_ref.map(|r| r.is_null()).unwrap_or(true)
self.shared_ref.map_or(true, T::is_null)
}
}
6 changes: 2 additions & 4 deletions godot-core/src/obj/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ impl MemDynamic {
/// Check whether dynamic type is ref-counted.
fn inherits_refcounted<T: GodotClass>(obj: &RawGd<T>) -> bool {
obj.instance_id_unchecked()
.map(|id| id.is_ref_counted())
.unwrap_or(false)
.is_some_and(|id| id.is_ref_counted())
}
}
impl Sealed for MemDynamic {}
Expand Down Expand Up @@ -301,8 +300,7 @@ impl DynMemory for MemDynamic {
out!(" MemDyn::dec <{}>", std::any::type_name::<T>());
if obj
.instance_id_unchecked()
.map(|id| id.is_ref_counted())
.unwrap_or(false)
.is_some_and(|id| id.is_ref_counted())
{
// Will call `RefCounted::unreference()` which checks for liveness.
MemRefCounted::maybe_dec_ref(obj)
Expand Down
3 changes: 1 addition & 2 deletions godot-core/src/obj/raw_gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ impl<T: GodotClass> RawGd<T> {
pub(crate) fn is_instance_valid(&self) -> bool {
self.cached_rtti
.as_ref()
.map(|rtti| rtti.instance_id().lookup_validity())
.unwrap_or(false)
.is_some_and(|rtti| rtti.instance_id().lookup_validity())
}

// See use-site for explanation.
Expand Down
16 changes: 6 additions & 10 deletions godot-macros/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,15 @@ pub(crate) fn path_is_single(path: &[TokenTree], expected: &str) -> bool {

pub(crate) fn path_ends_with(path: &[TokenTree], expected: &str) -> bool {
// Could also use TypeExpr::as_path(), or fn below this one.
path.last()
.map(|last| last.to_string() == expected)
.unwrap_or(false)
path.last().is_some_and(|last| last.to_string() == expected)
}

pub(crate) fn path_ends_with_complex(path: &venial::TypeExpr, expected: &str) -> bool {
path.as_path()
.map(|path| {
path.segments
.last()
.is_some_and(|seg| seg.ident == expected)
})
.unwrap_or(false)
path.as_path().is_some_and(|path| {
path.segments
.last()
.is_some_and(|seg| seg.ident == expected)
})
}

pub(crate) fn extract_cfg_attrs(
Expand Down

0 comments on commit 82168d0

Please sign in to comment.