Skip to content

Commit 76940e9

Browse files
authored
[workerd-cxx] cleanup (#44)
* just format * stricter clippy settings * clippy fixes
1 parent 99d3d88 commit 76940e9

File tree

19 files changed

+83
-56
lines changed

19 files changed

+83
-56
lines changed

.bazelrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ build:windows --copt='/Zc:dllexportInlines-' --host_copt='/Zc:dllexportInlines-'
2929

3030
build:clippy --aspects=@rules_rust//rust:defs.bzl%rust_clippy_aspect
3131
build:clippy --output_groups=+clippy_checks
32-
build:clippy --@rules_rust//:clippy_flags=-Dclippy::all,-Dclippy::pedantic
32+
build:clippy --@rules_rust//:clippy_flags=-Dclippy::all,-Dclippy::pedantic,-Dwarnings
33+
build:clippy --aspects=@rules_rust//rust:defs.bzl%rustfmt_aspect
34+
build:clippy --output_groups=+rustfmt_checks
35+
build:clippy --@rules_rust//:extra_rustc_flag=-Dwarnings
3336

3437
## Sanitizers
3538

gen/build/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
clippy::cast_sign_loss,
5252
clippy::default_trait_access,
5353
clippy::doc_markdown,
54-
clippy::elidable_lifetime_names,
5554
clippy::enum_glob_use,
5655
clippy::explicit_auto_deref,
5756
clippy::inherent_to_string,

gen/src/write.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,15 @@ fn write_rust_function_shim_impl(
10301030
return;
10311031
}
10321032
writeln!(out, " {{");
1033-
sig.args.iter()
1034-
.filter(|arg| {
1035-
matches!(arg.ty, Type::Own(_))
1036-
}).for_each(|arg_own| {
1037-
writeln!(out, " KJ_ASSERT({}.get() != nullptr, \"Cannot pass a null Own to Rust\");", arg_own.name.cxx);
1033+
sig.args
1034+
.iter()
1035+
.filter(|arg| matches!(arg.ty, Type::Own(_)))
1036+
.for_each(|arg_own| {
1037+
writeln!(
1038+
out,
1039+
" KJ_ASSERT({}.get() != nullptr, \"Cannot pass a null Own to Rust\");",
1040+
arg_own.name.cxx
1041+
);
10381042
});
10391043
for arg in &sig.args {
10401044
if arg.ty != RustString && out.types.needs_indirect_abi(&arg.ty) {
@@ -1633,8 +1637,7 @@ fn write_kj_own(out: &mut OutFile, key: NamedImplKey) {
16331637
let ident = key.rust;
16341638
let resolve = out.types.resolve(ident);
16351639
let inner = resolve.name.to_fully_qualified();
1636-
let instance = resolve.name.to_symbol();
1637-
1640+
16381641
out.include.utility = true;
16391642
out.include.kj_rs = true;
16401643

kj-rs/awaiter.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<Data: std::marker::Unpin> PromiseAwaiter<Data> {
5757
let node = this.node.take();
5858

5959
// Safety: `awaiter` stores `rust_waker_ptr` and uses it to call `wake()`. Note that
60-
// `awaiter` is `this.awaiter`, which lives before `this.option_waker`.
60+
// `awaiter` is `this.awaiter`, which lives before `this.option_waker`.
6161
// Since we drop awaiter manually, the `rust_waker_ptr` that `awaiter` stores will always
6262
// be valid during its lifetime.
6363
//
@@ -69,7 +69,9 @@ impl<Data: std::marker::Unpin> PromiseAwaiter<Data> {
6969
// Safety: The memory slot is valid and this type ensures that it will stay pinned.
7070
unsafe {
7171
crate::ffi::guarded_rust_promise_awaiter_new_in_place(
72-
this.awaiter.as_mut_ptr().cast::<GuardedRustPromiseAwaiter>(),
72+
this.awaiter
73+
.as_mut_ptr()
74+
.cast::<GuardedRustPromiseAwaiter>(),
7375
rust_waker_ptr,
7476
node.expect("node should be Some in call to init()"),
7577
);
@@ -98,7 +100,9 @@ impl<Data: std::marker::Unpin> Drop for PromiseAwaiter<Data> {
98100
if self.awaiter_initialized {
99101
unsafe {
100102
crate::ffi::guarded_rust_promise_awaiter_drop_in_place(
101-
self.awaiter.as_mut_ptr().cast::<GuardedRustPromiseAwaiter>()
103+
self.awaiter
104+
.as_mut_ptr()
105+
.cast::<GuardedRustPromiseAwaiter>(),
102106
);
103107
}
104108
}

kj-rs/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ pub use promise::new_callbacks_promise_future;
1212

1313
mod awaiter;
1414
mod future;
15+
mod own;
1516
mod promise;
1617
mod waker;
17-
mod own;
1818

1919
pub mod repr {
2020
pub use crate::future::repr::*;

kj-rs/own.c++

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C" {
55
// This works because disposers work by virtual call, and the disposer is created during creation of
66
// the Own, so the type of the Own at destruction doesn't actually matter for Owns that do not use a
77
// static disposer, which are not currently supported by workerd-cxx.
8-
void cxxbridge$kjrs$own$drop(void *own) {
9-
reinterpret_cast<kj::Own<void> *>(own)->~Own();
8+
void cxxbridge$kjrs$own$drop(void* own) {
9+
reinterpret_cast<kj::Own<void>*>(own)->~Own();
1010
}
1111
}

kj-rs/own.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
#include <kj/memory.h>
44

55
extern "C" {
6-
void cxxbridge$kjrs$own$drop(void* own);
6+
void cxxbridge$kjrs$own$drop(void* own);
77
}

kj-rs/tests/BUILD.bazel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ platform(
1313
)
1414

1515
rust_library(
16-
name = "awaitables-rust",
16+
name = "tests",
1717
srcs = glob(["*.rs"]),
1818
edition = "2024",
1919
deps = [
@@ -28,13 +28,13 @@ rust_unpretty(
2828
name = "expand-rust_test",
2929
testonly = True,
3030
deps = [
31-
":awaitables-rust_test"
31+
":rust_tests"
3232
]
3333
)
3434

3535
rust_test(
36-
name = "awaitables-rust_test",
37-
crate = "awaitables-rust",
36+
name = "rust_tests",
37+
crate = "tests",
3838
deps = [
3939
":test-promises",
4040
],
@@ -80,7 +80,7 @@ cc_test(
8080
"//conditions:default": False,
8181
}),
8282
deps = [
83-
":awaitables-rust",
83+
":tests",
8484
":bridge",
8585
":test-promises",
8686
"//third-party:runtime",

kj-rs/tests/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,26 @@ mod ffi {
4949
#[cxx_name = "setData"]
5050
fn set_data(self: Pin<&mut OpaqueCxxClass>, val: u64);
5151

52+
#[allow(dead_code)]
5253
fn cxx_kj_own() -> Own<OpaqueCxxClass>;
5354
fn null_kj_own() -> Own<OpaqueCxxClass>;
55+
#[allow(dead_code)]
5456
fn give_own_back(own: Own<OpaqueCxxClass>);
57+
#[allow(dead_code)]
5558
fn modify_own_return_test();
59+
#[allow(dead_code)]
5660
fn breaking_things() -> Own<OpaqueCxxClass>;
5761

62+
#[allow(dead_code)]
5863
fn own_integer() -> Own<i64>;
64+
#[allow(dead_code)]
5965
fn own_integer_attached() -> Own<i64>;
6066

67+
#[allow(dead_code)]
6168
fn null_exception_test_driver_1() -> String;
69+
#[allow(dead_code)]
6270
fn null_exception_test_driver_2() -> String;
71+
#[allow(dead_code)]
6372
fn rust_take_own_driver();
6473
}
6574

kj-rs/tests/test-own.c++

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
#include "test-own.h"
2+
23
#include "kj/string.h"
4+
35
#include <exception>
46

57
namespace kj_rs_demo {
68

7-
kj::Own<OpaqueCxxClass> cxx_kj_own() {
8-
return kj::heap<OpaqueCxxClass>(42);
9+
kj::Own<OpaqueCxxClass> cxx_kj_own() {
10+
return kj::heap<OpaqueCxxClass>(42);
911
}
1012

11-
kj::Own<OpaqueCxxClass> null_kj_own() {
12-
return kj::Own<OpaqueCxxClass>();
13+
kj::Own<OpaqueCxxClass> null_kj_own() {
14+
return kj::Own<OpaqueCxxClass>();
1315
}
1416

1517
void give_own_back(kj::Own<OpaqueCxxClass> own) {
@@ -42,19 +44,19 @@ kj::Own<int64_t> own_integer_attached() {
4244

4345
rust::string null_exception_test_driver_1() {
4446
try {
45-
auto _ = modify_own_return(null_kj_own());
46-
return rust::string("");
47-
} catch (const std::exception &e) {
48-
return rust::string(e.what());
47+
auto _ = modify_own_return(null_kj_own());
48+
return rust::string("");
49+
} catch (const std::exception& e) {
50+
return rust::string(e.what());
4951
}
5052
}
5153

5254
rust::string null_exception_test_driver_2() {
5355
try {
54-
auto _ = get_null();
55-
return rust::string("");
56-
} catch (const std::exception &e) {
57-
return rust::string(e.what());
56+
auto _ = get_null();
57+
return rust::string("");
58+
} catch (const std::exception& e) {
59+
return rust::string(e.what());
5860
}
5961
}
6062

@@ -63,4 +65,4 @@ void rust_take_own_driver() {
6365
take_own(kj::mv(own));
6466
}
6567

66-
} // namespace kj_rs_demo
68+
} // namespace kj_rs_demo

0 commit comments

Comments
 (0)