From 80f25d42dca7ea93b4143444219e06242230bf71 Mon Sep 17 00:00:00 2001 From: david-perez Date: Tue, 18 Apr 2023 12:35:22 +0200 Subject: [PATCH] Fix generation of constrained shapes reaching `@sensitive` shapes (#2585) Constrained shapes should always be able to `#[derive(Debug)]`. Fixes #2582. ## Testing The modified integration test fails without this patch applied. ## Checklist - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com> --- CHANGELOG.next.toml | 6 ++++++ codegen-core/common-test-models/constraints.smithy | 9 +++++++++ .../smithy/ConstrainedShapeSymbolMetadataProvider.kt | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index abe0d7fdb4..a428a3186e 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -116,3 +116,9 @@ message = "`aws_smithy_types::date_time::Format` has been re-exported in service references = ["smithy-rs#2534"] meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" } author = "ysaito1001" + +[[smithy-rs]] +message = "Fix generation of constrained shapes reaching `@sensitive` shapes" +references = ["smithy-rs#2582", "smithy-rs#2585"] +meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "server" } +author = "david-perez" diff --git a/codegen-core/common-test-models/constraints.smithy b/codegen-core/common-test-models/constraints.smithy index 2651b77335..bac10a0c15 100644 --- a/codegen-core/common-test-models/constraints.smithy +++ b/codegen-core/common-test-models/constraints.smithy @@ -454,6 +454,7 @@ structure ConA { conBList: ConBList, lengthList: LengthList, + sensitiveLengthList: SensitiveLengthList, conBSet: ConBSet, @@ -866,6 +867,14 @@ list LengthList { member: String } +@length(max: 69) +list SensitiveLengthList { + member: SensitiveStructure +} + +@sensitive +structure SensitiveStructure { } + set ConBSet { member: ConBSetInner } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolMetadataProvider.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolMetadataProvider.kt index 0c83795f2f..2c7b4f1fc5 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolMetadataProvider.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstrainedShapeSymbolMetadataProvider.kt @@ -16,6 +16,7 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.containerDefaultMetadata @@ -47,6 +48,11 @@ class ConstrainedShapeSymbolMetadataProvider( derives += containerDefaultMetadata(shape, model).derives } + // We should _always_ be able to `#[derive(Debug)]`: all constrained shapes' types are simply tuple newtypes + // wrapping a single type which always implements `Debug`. + // The wrapped type may not _derive_ `Debug` though, hence why this line is required; see https://github.com/awslabs/smithy-rs/issues/2582. + derives += RuntimeType.Debug + val visibility = Visibility.publicIf(constrainedTypes, Visibility.PUBCRATE) return RustMetadata(derives, additionalAttributes, visibility) }