From 8013166c9b97eff43d97efa42292853e0a965c0d Mon Sep 17 00:00:00 2001 From: david-perez Date: Wed, 18 Jan 2023 15:00:17 +0100 Subject: [PATCH] Don't use `#[allow(unused)]` in generated code (#2211) Most usages are in the server constrained types generators, where `#[allow(dead_code)]` suffices and makes the intent clearer. See https://stackoverflow.com/a/64556868 --- .../smithy/endpoint/generators/EndpointResolverGenerator.kt | 4 ++-- .../amazon/smithy/rust/codegen/core/rustlang/RustType.kt | 1 - .../server/smithy/generators/ConstrainedBlobGenerator.kt | 2 +- .../smithy/generators/ConstrainedCollectionGenerator.kt | 2 +- .../server/smithy/generators/ConstrainedMapGenerator.kt | 2 +- .../server/smithy/generators/ConstrainedNumberGenerator.kt | 2 +- .../server/smithy/generators/ConstrainedStringGenerator.kt | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt index 385ab1324..d4f3fe32f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointResolverGenerator.kt @@ -221,7 +221,7 @@ internal class EndpointResolverGenerator(stdlib: List, ru private fun resolverFnBody(endpointRuleSet: EndpointRuleSet) = writable { endpointRuleSet.parameters.toList().forEach { - Attribute.AllowUnused.render(this) + Attribute.AllowUnusedVariables.render(this) rust("let ${it.memberName()} = &$ParamsName.${it.memberName()};") } generateRulesList(endpointRuleSet.rules)(this) @@ -291,7 +291,7 @@ internal class EndpointResolverGenerator(stdlib: List, ru fn.type() is Type.Option || // TODO(https://github.com/awslabs/smithy/pull/1504): ReterminusCore bug: substring should return `Option`: (fn as Function).name == "substring" -> { - Attribute.AllowUnused.render(this) + Attribute.AllowUnusedVariables.render(this) rustTemplate( "if let Some($resultName) = #{target:W} { #{next:W} }", "target" to target, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index c39af9da0..56ff3d7ef 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -458,7 +458,6 @@ class Attribute(val inner: Writable) { val AllowDeprecated = Attribute(allow("deprecated")) val AllowIrrefutableLetPatterns = Attribute(allow("irrefutable_let_patterns")) val AllowUnreachableCode = Attribute(allow("unreachable_code")) - val AllowUnused = Attribute(allow("unused")) val AllowUnusedImports = Attribute(allow("unused_imports")) val AllowUnusedMut = Attribute(allow("unused_mut")) val AllowUnusedVariables = Attribute(allow("unused_variables")) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedBlobGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedBlobGenerator.kt index acaee289a..0afeac069 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedBlobGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedBlobGenerator.kt @@ -70,7 +70,7 @@ class ConstrainedBlobGenerator( constrainedTypeMetadata.render(writer) writer.rust("struct $name(pub(crate) $inner);") if (constrainedTypeVisibility == Visibility.PUBCRATE) { - Attribute.AllowUnused.render(writer) + Attribute.AllowDeadCode.render(writer) } writer.rust( """ diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt index c31a215dd..8dc227e27 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedCollectionGenerator.kt @@ -95,7 +95,7 @@ class ConstrainedCollectionGenerator( *codegenScope, ) if (constrainedTypeVisibility == Visibility.PUBCRATE) { - Attribute.AllowUnused.render(writer) + Attribute.AllowDeadCode.render(writer) } writer.rustTemplate( diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt index bf9dacdd6..a8a891dc3 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedMapGenerator.kt @@ -80,7 +80,7 @@ class ConstrainedMapGenerator( constrainedTypeMetadata.render(writer) writer.rustTemplate("struct $name(pub(crate) $inner);", *codegenScope) if (constrainedTypeVisibility == Visibility.PUBCRATE) { - Attribute.AllowUnused.render(writer) + Attribute.AllowDeadCode.render(writer) } writer.rustTemplate( """ diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt index 6e85ac5c8..863f20af9 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedNumberGenerator.kt @@ -100,7 +100,7 @@ class ConstrainedNumberGenerator( writer.rust("struct $name(pub(crate) $unconstrainedTypeName);") if (constrainedTypeVisibility == Visibility.PUBCRATE) { - Attribute.AllowUnused.render(writer) + Attribute.AllowDeadCode.render(writer) } writer.rustTemplate( """ diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt index 2c7fcaa50..8c2876f53 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ConstrainedStringGenerator.kt @@ -89,7 +89,7 @@ class ConstrainedStringGenerator( constrainedTypeMetadata.render(writer) writer.rust("struct $name(pub(crate) $inner);") if (constrainedTypeVisibility == Visibility.PUBCRATE) { - Attribute.AllowUnused.render(writer) + Attribute.AllowDeadCode.render(writer) } writer.rust( """ -- GitLab