Skip to content

Commit 3dafef1

Browse files
authored
Merge pull request #1010 from godot-rust/qol/nodepath-subpath-clippy
Follow clippy 1.84; limit `NodePath::subpath()` polyfill again
2 parents 6a5d19d + a23bf9f commit 3dafef1

File tree

9 files changed

+43
-46
lines changed

9 files changed

+43
-46
lines changed

godot-codegen/src/special_cases/codegen_special_cases.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,16 @@ pub(crate) fn is_class_method_excluded(method: &JsonClassMethod, ctx: &mut Conte
7474
};
7575

7676
// Exclude if return type contains an excluded type.
77-
if method.return_value.as_ref().map_or(false, |ret| {
78-
is_arg_or_return_excluded(ret.type_.as_str(), ctx)
79-
}) {
77+
if method
78+
.return_value
79+
.as_ref()
80+
.is_some_and(|ret| is_arg_or_return_excluded(ret.type_.as_str(), ctx))
81+
{
8082
return true;
8183
}
8284

8385
// Exclude if any argument contains an excluded type.
84-
if method.arguments.as_ref().map_or(false, |args| {
86+
if method.arguments.as_ref().is_some_and(|args| {
8587
args.iter()
8688
.any(|arg| is_arg_or_return_excluded(arg.type_.as_str(), ctx))
8789
}) {
@@ -107,8 +109,8 @@ pub(crate) fn is_utility_function_excluded(
107109
function
108110
.return_type
109111
.as_ref()
110-
.map_or(false, |ret| is_type_excluded(ret.as_str(), ctx))
111-
|| function.arguments.as_ref().map_or(false, |args| {
112+
.is_some_and(|ret| is_type_excluded(ret.as_str(), ctx))
113+
|| function.arguments.as_ref().is_some_and(|args| {
112114
args.iter()
113115
.any(|arg| is_type_excluded(arg.type_.as_str(), ctx))
114116
})

godot-core/src/builtin/string/node_path.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::fmt;
99

1010
use godot_ffi as sys;
11-
use godot_ffi::{ffi_methods, GodotFfi};
11+
use godot_ffi::{ffi_methods, GdextBuild, GodotFfi};
1212

1313
use crate::builtin::inner;
1414

@@ -142,19 +142,23 @@ impl NodePath {
142142
#[cfg(since_api = "4.3")]
143143
#[doc(alias = "slice")]
144144
pub fn subpath(&self, begin: i32, exclusive_end: i32) -> NodePath {
145-
// Polyfill for bug https://github.com/godotengine/godot/pull/100954.
146-
// TODO(v0.3) make polyfill (everything but last line) conditional if PR is merged in 4.4.
147-
let name_count = self.get_name_count() as i32;
148-
let subname_count = self.get_subname_count() as i32;
149-
let total_count = name_count + subname_count;
150-
151-
let mut begin = begin.clamp(-total_count, total_count);
152-
if begin < 0 {
153-
begin += total_count;
154-
}
155-
if begin > name_count {
156-
begin += 1;
157-
}
145+
// Polyfill for bug https://github.com/godotengine/godot/pull/100954, fixed in 4.4.
146+
let begin = if GdextBuild::since_api("4.4") {
147+
begin
148+
} else {
149+
let name_count = self.get_name_count() as i32;
150+
let subname_count = self.get_subname_count() as i32;
151+
let total_count = name_count + subname_count;
152+
153+
let mut begin = begin.clamp(-total_count, total_count);
154+
if begin < 0 {
155+
begin += total_count;
156+
}
157+
if begin > name_count {
158+
begin += 1;
159+
}
160+
begin
161+
};
158162

159163
self.as_inner().slice(begin as i64, exclusive_end as i64)
160164
}

godot-core/src/builtin/variant/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ impl Drop for Variant {
453453
// Variant is not Eq because it can contain floats and other types composed of floats.
454454
impl PartialEq for Variant {
455455
fn eq(&self, other: &Self) -> bool {
456-
Self::evaluate(self, other, VariantOperator::EQUAL)
457-
.map(|v| v.to::<bool>())
458-
.unwrap_or(false) // if there is no defined conversion, then they are non-equal
456+
Self::evaluate(self, other, VariantOperator::EQUAL) //.
457+
.is_some_and(|v| v.to::<bool>())
458+
// If there is no defined conversion (-> None), then they are non-equal.
459459
}
460460
}
461461

godot-core/src/meta/args/ref_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,6 @@ where
193193
}
194194

195195
fn is_null(&self) -> bool {
196-
self.shared_ref.map(|r| r.is_null()).unwrap_or(true)
196+
self.shared_ref.map_or(true, T::is_null)
197197
}
198198
}

godot-core/src/obj/bounds.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ impl MemDynamic {
272272
/// Check whether dynamic type is ref-counted.
273273
fn inherits_refcounted<T: GodotClass>(obj: &RawGd<T>) -> bool {
274274
obj.instance_id_unchecked()
275-
.map(|id| id.is_ref_counted())
276-
.unwrap_or(false)
275+
.is_some_and(|id| id.is_ref_counted())
277276
}
278277
}
279278
impl Sealed for MemDynamic {}
@@ -301,8 +300,7 @@ impl DynMemory for MemDynamic {
301300
out!(" MemDyn::dec <{}>", std::any::type_name::<T>());
302301
if obj
303302
.instance_id_unchecked()
304-
.map(|id| id.is_ref_counted())
305-
.unwrap_or(false)
303+
.is_some_and(|id| id.is_ref_counted())
306304
{
307305
// Will call `RefCounted::unreference()` which checks for liveness.
308306
MemRefCounted::maybe_dec_ref(obj)

godot-core/src/obj/raw_gd.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ impl<T: GodotClass> RawGd<T> {
103103
pub(crate) fn is_instance_valid(&self) -> bool {
104104
self.cached_rtti
105105
.as_ref()
106-
.map(|rtti| rtti.instance_id().lookup_validity())
107-
.unwrap_or(false)
106+
.is_some_and(|rtti| rtti.instance_id().lookup_validity())
108107
}
109108

110109
// See use-site for explanation.

godot-ffi/src/toolbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn strip_module_paths(full_name: &str) -> String {
227227
result.push(c);
228228

229229
// Handle spaces after commas for readability.
230-
if c == ',' && chars.peek().map_or(false, |&next_c| next_c != ' ') {
230+
if c == ',' && chars.peek().is_some_and(|&next_c| next_c != ' ') {
231231
result.push(' ');
232232
}
233233
}

godot-macros/src/util/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn delimiter_opening_char(delimiter: Delimiter) -> char {
141141
/// declaration of the form `impl MyTrait for SomeType`. The type `SomeType` is irrelevant in this example.
142142
pub(crate) fn is_impl_named(original_impl: &venial::Impl, name: &str) -> bool {
143143
let trait_name = original_impl.trait_ty.as_ref().unwrap(); // unwrap: already checked outside
144-
extract_typename(trait_name).map_or(false, |seg| seg.ident == name)
144+
extract_typename(trait_name).is_some_and(|seg| seg.ident == name)
145145
}
146146

147147
/// Validates either:
@@ -228,27 +228,23 @@ pub(crate) fn path_is_single(path: &[TokenTree], expected: &str) -> bool {
228228

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

236234
pub(crate) fn path_ends_with_complex(path: &venial::TypeExpr, expected: &str) -> bool {
237-
path.as_path()
238-
.map(|path| {
239-
path.segments
240-
.last()
241-
.map_or(false, |seg| seg.ident == expected)
242-
})
243-
.unwrap_or(false)
235+
path.as_path().is_some_and(|path| {
236+
path.segments
237+
.last()
238+
.is_some_and(|seg| seg.ident == expected)
239+
})
244240
}
245241

246242
pub(crate) fn extract_cfg_attrs(
247243
attrs: &[venial::Attribute],
248244
) -> impl IntoIterator<Item = &venial::Attribute> {
249245
attrs.iter().filter(|attr| {
250246
attr.get_single_path_segment()
251-
.map_or(false, |name| name == "cfg")
247+
.is_some_and(|name| name == "cfg")
252248
})
253249
}
254250

itest/rust/src/framework/runner.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,7 @@ fn print_test_pre(test_case: &str, test_file: String, last_file: &mut Option<Str
333333

334334
fn print_file_header(file: String, last_file: &mut Option<String>) {
335335
// Check if we need to open a new category for a file.
336-
let print_file = last_file
337-
.as_ref()
338-
.map_or(true, |last_file| last_file != &file);
336+
let print_file = last_file.as_ref() != Some(&file);
339337

340338
if print_file {
341339
println!("\n {}:", extract_file_subtitle(&file));

0 commit comments

Comments
 (0)