Skip to content

Commit 3f6fddf

Browse files
committed
Fix unused object parameters in empty structure serialization
Extends the unused variable fix to handle function parameters in addition to union match variables. For empty structures, both object and input parameters are prefixed with underscore to prevent unused variable warnings in CI. Addresses CI failure in shape_player_action.rs
1 parent 04956de commit 3f6fddf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,19 +355,22 @@ class JsonSerializerGenerator(
355355
Attribute.AllowUnusedVariables.render(this)
356356
}
357357
}
358+
val objectParam = if (members.isEmpty()) "_object" else "object"
359+
val inputParam = if (members.isEmpty()) "_input" else "input"
358360
rustBlockTemplate(
359361
"""
360362
pub fn $fnName(
361-
#{AllowUnusedVariables:W} object: &mut #{JsonObjectWriter},
362-
#{AllowUnusedVariables:W} input: &#{StructureSymbol},
363+
#{AllowUnusedVariables:W} $objectParam: &mut #{JsonObjectWriter},
364+
#{AllowUnusedVariables:W} $inputParam: &#{StructureSymbol},
363365
) -> #{Result}<(), #{Error}>
364366
""",
365367
"StructureSymbol" to symbolProvider.toSymbol(context.shape),
366368
"AllowUnusedVariables" to allowUnusedVariables,
367369
*codegenScope,
368370
) {
369371
for (member in members) {
370-
serializeMember(MemberContext.structMember(inner, member, symbolProvider, jsonName))
372+
val actualInner = inner.copy(objectName = objectParam, localName = inputParam)
373+
serializeMember(MemberContext.structMember(actualInner, member, symbolProvider, jsonName))
371374
}
372375
rust("Ok(())")
373376
}

0 commit comments

Comments
 (0)