Skip to content

Commit 04e5ef8

Browse files
committed
feat: linting
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
1 parent 0d6a753 commit 04e5ef8

File tree

32 files changed

+216
-159
lines changed

32 files changed

+216
-159
lines changed

.devcontainer/setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ echo "export PATH=$DOTNET_PATH:\$PATH" >> ~/.bashrc
2727
# Moonbit
2828
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
2929
echo 'export PATH="$HOME/.moon/bin:$PATH"' >> ~/.bashrc
30+
31+
# Go
32+
curl -OL https://go.dev/dl/go1.25.5.linux-amd64.tar.gz
33+
tar xf go1.25.5.linux-amd64.tar.gz
34+
echo "export PATH=$HOME/go1.25.5.linux-amd64/bin:\$PATH" >> ~/.bashrc

.github/workflows/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,11 @@ jobs:
262262
- name: Report failure on cancellation
263263
if: ${{ contains(needs.*.result, 'cancelled') || cancelled() }}
264264
run: exit 1
265+
266+
clippy:
267+
runs-on: ubuntu-latest
268+
steps:
269+
- uses: actions/checkout@v6
270+
- run: rustup update stable --no-self-update && rustup default stable
271+
- run: rustup component add clippy
272+
- run: cargo clippy --workspace --all-targets

Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ description = """
1111
CLI tool to generate bindings for WIT documents and the component model.
1212
"""
1313

14+
[lints]
15+
workspace = true
16+
1417
[workspace]
1518
resolver = "2"
1619

@@ -52,6 +55,21 @@ wit-bindgen-go = { path = 'crates/go', version = '0.50.0' }
5255
wit-bindgen = { path = 'crates/guest-rust', version = '0.50.0', default-features = false }
5356
wit-bindgen-test = { path = 'crates/test', version = '0.50.0' }
5457

58+
[workspace.lints.clippy]
59+
# The default set of lints in Clippy is viewed as "too noisy" right now so
60+
# they're all turned off by default. Selective lints are then enabled below as
61+
# necessary.
62+
all = { level = 'allow', priority = -1 }
63+
clone_on_copy = 'warn'
64+
map_clone = 'warn'
65+
unnecessary_to_owned = 'warn'
66+
manual_strip = 'warn'
67+
uninlined_format_args = 'warn'
68+
unnecessary_mut_passed = 'warn'
69+
unnecessary_fallible_conversions = 'warn'
70+
unnecessary_cast = 'warn'
71+
allow_attributes_without_reason = 'warn'
72+
5573
[[bin]]
5674
name = "wit-bindgen"
5775

crates/c/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ C bindings generator for WIT and the component model, typically used through the
1212
`wit-bindgen-cli` crate.
1313
"""
1414

15+
[lints]
16+
workspace = true
17+
1518
[lib]
1619
doctest = false
1720
test = false

crates/c/src/lib.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -662,36 +662,36 @@ impl C {
662662
match cast {
663663
Bitcast::I32ToF32 | Bitcast::I64ToF32 => {
664664
self.needs_union_int32_float = true;
665-
format!("((union int32_float){{ (int32_t) {} }}).b", op)
665+
format!("((union int32_float){{ (int32_t) {op} }}).b")
666666
}
667667
Bitcast::F32ToI32 | Bitcast::F32ToI64 => {
668668
self.needs_union_float_int32 = true;
669-
format!("((union float_int32){{ {} }}).b", op)
669+
format!("((union float_int32){{ {op} }}).b")
670670
}
671671
Bitcast::I64ToF64 => {
672672
self.needs_union_int64_double = true;
673-
format!("((union int64_double){{ (int64_t) {} }}).b", op)
673+
format!("((union int64_double){{ (int64_t) {op} }}).b")
674674
}
675675
Bitcast::F64ToI64 => {
676676
self.needs_union_double_int64 = true;
677-
format!("((union double_int64){{ {} }}).b", op)
677+
format!("((union double_int64){{ {op} }}).b")
678678
}
679679
Bitcast::I32ToI64 | Bitcast::LToI64 | Bitcast::PToP64 => {
680-
format!("(int64_t) {}", op)
680+
format!("(int64_t) {op}")
681681
}
682682
Bitcast::I64ToI32 | Bitcast::I64ToL => {
683-
format!("(int32_t) {}", op)
683+
format!("(int32_t) {op}")
684684
}
685685
// P64 is currently represented as int64_t, so no conversion is needed.
686686
Bitcast::I64ToP64 | Bitcast::P64ToI64 => {
687-
format!("{}", op)
687+
format!("{op}")
688688
}
689689
Bitcast::P64ToP | Bitcast::I32ToP | Bitcast::LToP => {
690-
format!("(uint8_t *) {}", op)
690+
format!("(uint8_t *) {op}")
691691
}
692692

693693
// Cast to uintptr_t to avoid implicit pointer-to-int conversions.
694-
Bitcast::PToI32 | Bitcast::PToL => format!("(uintptr_t) {}", op),
694+
Bitcast::PToI32 | Bitcast::PToL => format!("(uintptr_t) {op}"),
695695

696696
Bitcast::I32ToL | Bitcast::LToI32 | Bitcast::None => op.to_string(),
697697

@@ -2034,7 +2034,7 @@ impl InterfaceGenerator<'_> {
20342034
let mut f = FunctionBindgen::new(self, c_sig, &import_name);
20352035
for (pointer, param) in f.sig.params.iter() {
20362036
if *pointer {
2037-
f.params.push(format!("*{}", param));
2037+
f.params.push(format!("*{param}"));
20382038
} else {
20392039
f.params.push(param.clone());
20402040
}
@@ -2332,7 +2332,7 @@ void {name}_return({return_ty}) {{
23322332
} else if single_ret {
23332333
"ret".into()
23342334
} else {
2335-
format!("ret{}", i)
2335+
format!("ret{i}")
23362336
};
23372337
self.src.h_fns(&name);
23382338
retptrs.push(name);
@@ -2897,7 +2897,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
28972897
) {
28982898
self.load(ty, offset, operands, results);
28992899
let result = results.pop().unwrap();
2900-
results.push(format!("(int32_t) {}", result));
2900+
results.push(format!("(int32_t) {result}"));
29012901
}
29022902

29032903
fn store(&mut self, ty: &str, offset: ArchitectureSize, operands: &[String]) {
@@ -2930,10 +2930,7 @@ impl<'a, 'b> FunctionBindgen<'a, 'b> {
29302930
&& self.r#gen.autodrop_enabled()
29312931
&& self.r#gen.contains_droppable_borrow(ty)
29322932
{
2933-
panic!(
2934-
"Unable to autodrop borrows in `{}` values, please disable autodrop",
2935-
context
2936-
)
2933+
panic!("Unable to autodrop borrows in `{context}` values, please disable autodrop")
29372934
}
29382935
}
29392936
}
@@ -3055,7 +3052,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
30553052
}
30563053
Instruction::RecordLift { ty, record, .. } => {
30573054
let name = self.r#gen.r#gen.type_name(&Type::Id(*ty));
3058-
let mut result = format!("({}) {{\n", name);
3055+
let mut result = format!("({name}) {{\n");
30593056
for (field, op) in record.fields.iter().zip(operands.iter()) {
30603057
let field_ty = self.r#gen.r#gen.type_name(&field.ty);
30613058
uwriteln!(result, "({}) {},", field_ty, op);
@@ -3067,12 +3064,12 @@ impl Bindgen for FunctionBindgen<'_, '_> {
30673064
Instruction::TupleLower { tuple, .. } => {
30683065
let op = &operands[0];
30693066
for i in 0..tuple.types.len() {
3070-
results.push(format!("({}).f{}", op, i));
3067+
results.push(format!("({op}).f{i}"));
30713068
}
30723069
}
30733070
Instruction::TupleLift { ty, tuple, .. } => {
30743071
let name = self.r#gen.r#gen.type_name(&Type::Id(*ty));
3075-
let mut result = format!("({}) {{\n", name);
3072+
let mut result = format!("({name}) {{\n");
30763073
for (ty, op) in tuple.types.iter().zip(operands.iter()) {
30773074
let ty = self.r#gen.r#gen.type_name(&ty);
30783075
uwriteln!(result, "({}) {},", ty, op);
@@ -3151,7 +3148,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
31513148

31523149
Instruction::VariantPayloadName => {
31533150
let name = self.locals.tmp("payload");
3154-
results.push(format!("*{}", name));
3151+
results.push(format!("*{name}"));
31553152
self.payloads.push(name);
31563153
}
31573154

@@ -3229,7 +3226,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
32293226
assert!(block_results.len() == (case.ty.is_some() as usize));
32303227

32313228
if let Some(_) = case.ty.as_ref() {
3232-
let mut dst = format!("{}.val", result);
3229+
let mut dst = format!("{result}.val");
32333230
dst.push_str(".");
32343231
dst.push_str(&to_c_ident(&case.name));
32353232
self.store_op(&block_results[0], &dst);
@@ -3665,7 +3662,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
36653662
Some(Scalar::OptionBool(_)) => {
36663663
assert_eq!(operands.len(), 1);
36673664
let variant = &operands[0];
3668-
self.store_in_retptr(&format!("{}.val", variant));
3665+
self.store_in_retptr(&format!("{variant}.val"));
36693666
self.src.push_str("return ");
36703667
self.src.push_str(&variant);
36713668
self.src.push_str(".is_some;\n");
@@ -3677,7 +3674,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
36773674
uwriteln!(self.src, "if (!{}.is_err) {{", variant);
36783675
if ok.is_some() {
36793676
if ok.is_some() {
3680-
self.store_in_retptr(&format!("{}.val.ok", variant));
3677+
self.store_in_retptr(&format!("{variant}.val.ok"));
36813678
} else {
36823679
self.empty_return_value();
36833680
}
@@ -3689,7 +3686,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
36893686
);
36903687
if err.is_some() {
36913688
if err.is_some() {
3692-
self.store_in_retptr(&format!("{}.val.err", variant));
3689+
self.store_in_retptr(&format!("{variant}.val.err"));
36933690
} else {
36943691
self.empty_return_value();
36953692
}
@@ -3797,7 +3794,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
37973794
}
37983795

37993796
Instruction::Flush { amt } => {
3800-
results.extend(operands.iter().take(*amt).map(|v| v.clone()));
3797+
results.extend(operands.iter().take(*amt).cloned());
38013798
}
38023799

38033800
Instruction::AsyncTaskReturn { name, params } => {
@@ -3815,7 +3812,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
38153812
params: params
38163813
.iter()
38173814
.zip(operands)
3818-
.map(|(a, b)| (a.clone(), b.clone()))
3815+
.map(|(a, b)| (*a, b.clone()))
38193816
.collect(),
38203817
};
38213818
}
@@ -3928,7 +3925,7 @@ pub fn flags_repr(f: &Flags) -> Int {
39283925
FlagsRepr::U16 => Int::U16,
39293926
FlagsRepr::U32(1) => Int::U32,
39303927
FlagsRepr::U32(2) => Int::U64,
3931-
repr => panic!("unimplemented flags {:?}", repr),
3928+
repr => panic!("unimplemented flags {repr:?}"),
39323929
}
39333930
}
39343931

crates/core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ Low-level support for bindings generation based on WIT files for use with
1212
`wit-bindgen-cli` and other languages.
1313
"""
1414

15+
[lints]
16+
workspace = true
17+
1518
[lib]
1619
doctest = false
1720

crates/core/src/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ macro_rules! def_instruction {
3737

3838
impl $name<'_> {
3939
/// How many operands does this instruction pop from the stack?
40-
#[allow(unused_variables)]
40+
#[allow(unused_variables, reason = "match arms bind fields for exhaustiveness, not usage")]
4141
pub fn operands_len(&self) -> usize {
4242
match self {
4343
$(
@@ -51,7 +51,7 @@ macro_rules! def_instruction {
5151
}
5252

5353
/// How many results does this instruction push onto the stack?
54-
#[allow(unused_variables)]
54+
#[allow(unused_variables, reason = "match arms bind fields for exhaustiveness, not usage")]
5555
pub fn results_len(&self) -> usize {
5656
match self {
5757
$(

crates/core/src/ns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ impl Ns {
1111
if self.defined.insert(name.to_string()) {
1212
Ok(())
1313
} else {
14-
Err(format!("name `{}` already defined", name))
14+
Err(format!("name `{name}` already defined"))
1515
}
1616
}
1717

crates/cpp/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ description = """
1010
C++ guest and host binding generator for WIT and the component model.
1111
"""
1212

13+
[lints]
14+
workspace = true
15+
1316
[lib]
1417
doctest = false
1518
test = false

0 commit comments

Comments
 (0)