Skip to content

Commit 068c63c

Browse files
committed
Allow clippy::derive_partial_eq_without_eq on structs and builders
1 parent 625c6d4 commit 068c63c

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ sealed class Attribute {
387387
val AllowDeadCode = Custom("allow(dead_code)")
388388
val DocHidden = Custom("doc(hidden)")
389389
val DocInline = Custom("doc(inline)")
390+
val DerivePartialEqWithoutEq = Custom("allow(clippy::derive_partial_eq_without_eq)")
390391
}
391392

392393
data class Derives(val derives: Set<RuntimeType>) : Attribute() {

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import software.amazon.smithy.codegen.core.Symbol
99
import software.amazon.smithy.model.Model
1010
import software.amazon.smithy.model.shapes.MemberShape
1111
import software.amazon.smithy.model.shapes.StructureShape
12+
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
1213
import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords
1314
import software.amazon.smithy.rust.codegen.core.rustlang.RustType
1415
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
@@ -159,10 +160,12 @@ class BuilderGenerator(
159160

160161
writer.docs("A builder for #D.", structureSymbol)
161162
// Matching derives to the main structure + `Default` since we are a builder and everything is optional.
162-
val baseDerives = structureSymbol.expectRustMetadata().derives
163-
val derives = baseDerives.derives.intersect(setOf(RuntimeType.Debug, RuntimeType.PartialEq, RuntimeType.Clone)) + RuntimeType.Default
164-
baseDerives.copy(derives = derives).render(writer)
165-
writer.rustBlock("pub struct $builderName") {
163+
val containerMeta = structureSymbol.expectRustMetadata()
164+
val derives = containerMeta.derives.copy(derives = containerMeta.derives.derives.intersect(setOf(RuntimeType.Debug, RuntimeType.PartialEq, RuntimeType.Clone)) + RuntimeType.Default)
165+
val additionalAttributes = containerMeta.additionalAttributes.toMutableList();
166+
additionalAttributes.add(Attribute.DerivePartialEqWithoutEq)
167+
containerMeta.copy(derives = derives, additionalAttributes = additionalAttributes).render(writer)
168+
writer.rustBlock("struct $builderName") {
166169
for (member in members) {
167170
val memberName = symbolProvider.toMemberName(member)
168171
// All fields in the builder are optional.

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.isDeref
2424
import software.amazon.smithy.rust.codegen.core.rustlang.render
2525
import software.amazon.smithy.rust.codegen.core.rustlang.rust
2626
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
27+
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
2728
import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget
2829
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
2930
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
@@ -160,10 +161,14 @@ open class StructureGenerator(
160161
writer.documentShape(shape, model)
161162
writer.deprecatedShape(shape)
162163
val withoutDebug = containerMeta.derives.copy(derives = containerMeta.derives.derives - RuntimeType.Debug)
163-
containerMeta.copy(derives = withoutDebug).render(writer)
164+
val additionalAttributes = containerMeta.additionalAttributes.toMutableList();
165+
additionalAttributes.add(Attribute.DerivePartialEqWithoutEq)
166+
containerMeta.copy(
167+
derives = withoutDebug,
168+
additionalAttributes = additionalAttributes).render(writer)
164169

165170
writer.rustBlock("struct $name ${lifetimeDeclaration()}") {
166-
writer.forEachMember(members) { member, memberName, memberSymbol ->
171+
writer.forEachMember(members) { member, memberName, memberSymbol ->
167172
renderStructureMember(writer, member, memberName, memberSymbol)
168173
}
169174
}

0 commit comments

Comments
 (0)