Skip to content

Commit

Permalink
chore: fix map_unwrap_or clippy lint
Browse files Browse the repository at this point in the history
auto-fixed trailing semicolons by running

```
clippy --fix --all-features --all-targets --workspace -- -W clippy::map_unwrap_or
```

See [`map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or) clippy lint.
  • Loading branch information
nyurik committed Feb 1, 2025
1 parent a5657ae commit 725d5da
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 45 deletions.
3 changes: 1 addition & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ fn main() {
.as_ref()
.and_then(|p| p.file_stem())
.and_then(|f| f.to_str())
.map(|s| s.starts_with("rls"))
.unwrap_or(false);
.is_some_and(|s| s.starts_with("rls"));

// Early exit
if is_cargo_doc || is_rls {
Expand Down
6 changes: 4 additions & 2 deletions examples/cppgc-object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ fn execute_script(
let exception_string = try_catch
.stack_trace()
.or_else(|| try_catch.exception())
.map(|value| value.to_rust_string_lossy(try_catch))
.unwrap_or_else(|| "no stack trace".into());
.map_or_else(
|| "no stack trace".into(),
|value| value.to_rust_string_lossy(try_catch),
);

panic!("{}", exception_string);
}
Expand Down
2 changes: 1 addition & 1 deletion src/array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl ArrayBuffer {
// V8 terminates when the ArrayBuffer is not detachable. Non-detachable
// buffers are buffers that are in use by WebAssembly or asm.js.
if self.is_detachable() {
let key = key.map(|v| &*v as *const Value).unwrap_or(null());
let key = key.map_or(null(), |v| &*v as *const Value);
unsafe { v8__ArrayBuffer__Detach(self, key) }.into()
} else {
Some(true)
Expand Down
13 changes: 3 additions & 10 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,8 @@ impl Context {
sd.get_isolate_ptr(),
options
.global_template
.map(|t| &*t as *const _)
.unwrap_or_else(null),
options
.global_object
.map(|o| &*o as *const _)
.unwrap_or_else(null),
.map_or_else(null, |t| &*t as *const _),
options.global_object.map_or_else(null, |o| &*o as *const _),
options.microtask_queue.unwrap_or_else(null_mut),
)
})
Expand Down Expand Up @@ -358,10 +354,7 @@ impl Context {
v8__Context__FromSnapshot(
sd.get_isolate_mut(),
context_snapshot_index,
options
.global_object
.map(|o| &*o as *const _)
.unwrap_or_else(null),
options.global_object.map_or_else(null, |o| &*o as *const _),
options.microtask_queue.unwrap_or_else(null_mut),
)
})
Expand Down
6 changes: 2 additions & 4 deletions src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ impl From<&'_ mut Isolate> for HandleHost {
impl From<&'_ IsolateHandle> for HandleHost {
fn from(isolate_handle: &IsolateHandle) -> Self {
NonNull::new(unsafe { isolate_handle.get_isolate_ptr() })
.map(Self::Isolate)
.unwrap_or(Self::DisposedIsolate)
.map_or(Self::DisposedIsolate, Self::Isolate)
}
}

Expand Down Expand Up @@ -1097,8 +1096,7 @@ impl<T> TracedReference<T> {
self as *mut Self as *mut TracedReference<Data>,
scope.get_isolate_ptr(),
data
.map(|h| h.as_non_null().as_ptr())
.unwrap_or(std::ptr::null_mut())
.map_or(std::ptr::null_mut(), |h| h.as_non_null().as_ptr())
.cast(),
);
}
Expand Down
10 changes: 3 additions & 7 deletions src/isolate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,7 @@ where
specifier,
import_assertions,
)
.map(|return_value| return_value.as_non_null().as_ptr())
.unwrap_or_else(null_mut)
.map_or_else(null_mut, |return_value| return_value.as_non_null().as_ptr())
}

#[cfg(all(target_family = "windows", target_arch = "x86_64"))]
Expand Down Expand Up @@ -846,8 +845,7 @@ impl Isolate {
) {
let scope_data_ptr = scope_data
.map(NonNull::cast)
.map(NonNull::as_ptr)
.unwrap_or_else(null_mut);
.map_or_else(null_mut, NonNull::as_ptr);
self.set_data_internal(Self::CURRENT_SCOPE_DATA_SLOT, scope_data_ptr);
}

Expand Down Expand Up @@ -1105,9 +1103,7 @@ impl Isolate {
.get_slot::<HostCreateShadowRealmContextCallback>()
.unwrap();
let context = callback(&mut scope);
context
.map(|l| l.as_non_null().as_ptr())
.unwrap_or_else(null_mut)
context.map_or_else(null_mut, |l| l.as_non_null().as_ptr())
}

// Windows x64 ABI: MaybeLocal<Context> must be returned on the stack.
Expand Down
7 changes: 2 additions & 5 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ where
let f = |context, specifier, import_assertions, referrer| {
ResolveModuleCallbackRet(
(F::get())(context, specifier, import_assertions, referrer)
.map(|r| -> *const Module { &*r })
.unwrap_or(null()),
.map_or(null(), |r| -> *const Module { &*r }),
)
};
f.to_c_fn()
Expand Down Expand Up @@ -127,9 +126,7 @@ where
fn mapping() -> Self {
let f = |context, module| {
SyntheticModuleEvaluationStepsRet(
(F::get())(context, module)
.map(|r| -> *const Value { &*r })
.unwrap_or(null()),
(F::get())(context, module).map_or(null(), |r| -> *const Value { &*r }),
)
};
f.to_c_fn()
Expand Down
10 changes: 3 additions & 7 deletions src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Script {
v8__Script__Compile(
sd.get_current_context(),
&*source,
origin.map(|r| r as *const _).unwrap_or_else(null),
origin.map_or_else(null, |r| r as *const _),
)
})
}
Expand Down Expand Up @@ -128,15 +128,11 @@ impl<'s> ScriptOrigin<'s> {
resource_column_offset,
resource_is_shared_cross_origin,
script_id,
source_map_url
.map(|l| &*l as *const Value)
.unwrap_or_else(null),
source_map_url.map_or_else(null, |l| &*l as *const Value),
resource_is_opaque,
is_wasm,
is_module,
host_defined_options
.map(|l| &*l as *const Data)
.unwrap_or_else(null),
host_defined_options.map_or_else(null, |l| &*l as *const Data),
);
buf.assume_init()
}
Expand Down
4 changes: 2 additions & 2 deletions src/script_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Source {
v8__ScriptCompiler__Source__CONSTRUCT(
&mut buf,
&*source_string,
origin.map(|x| x as *const _).unwrap_or(std::ptr::null()),
origin.map_or(std::ptr::null(), |x| x as *const _),
std::ptr::null_mut(),
);
buf.assume_init()
Expand All @@ -169,7 +169,7 @@ impl Source {
v8__ScriptCompiler__Source__CONSTRUCT(
&mut buf,
&*source_string,
origin.map(|x| x as *const _).unwrap_or(std::ptr::null()),
origin.map_or(std::ptr::null(), |x| x as *const _),
cached_data.into_raw(), // Source constructor takes ownership.
);
buf.assume_init()
Expand Down
3 changes: 1 addition & 2 deletions src/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ impl<T> UniquePtr<T> {
pub fn into_raw(self) -> *mut T {
self
.0
.map(|unique_ref| unique_ref.into_raw())
.unwrap_or_else(null_mut)
.map_or_else(null_mut, |unique_ref| unique_ref.into_raw())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl WasmStreaming {
/// {exception} does not have value, the promise does not get rejected.
#[inline(always)]
pub fn abort(mut self, exception: Option<Local<Value>>) {
let exception = exception.map(|v| &*v as *const Value).unwrap_or(null());
let exception = exception.map_or(null(), |v| &*v as *const Value);
unsafe { v8__WasmStreaming__Abort(&mut self.0, exception) }
}

Expand Down
6 changes: 4 additions & 2 deletions tests/test_cppgc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ fn execute_script(
let exception_string = scope
.stack_trace()
.or_else(|| scope.exception())
.map(|value| value.to_rust_string_lossy(scope))
.unwrap_or_else(|| "no stack trace".into());
.map_or_else(
|| "no stack trace".into(),
|value| value.to_rust_string_lossy(scope),
);

panic!("{}", exception_string);
}
Expand Down

0 comments on commit 725d5da

Please sign in to comment.