diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fea153453a..f0a3bf3c70 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -478,3 +478,9 @@ x-amzn-errortype: com.example.service#InvalidRequestException references = ["smithy-rs#1982"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } author = "david-perez" + +[[smithy-rs]] +message = "Make generated enum `values()` functions callable in const contexts." +references = ["smithy-rs#2011"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" } +author = "lsr0" diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index 0acfe2641d..95a46649ea 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -141,7 +141,7 @@ open class EnumGenerator( } docs("Returns all the `&str` representations of the enum members.") - rustBlock("pub fn $Values() -> &'static [&'static str]") { + rustBlock("pub const fn $Values() -> &'static [&'static str]") { withBlock("&[", "]") { val memberList = sortedMembers.joinToString(", ") { it.value.dq() } rust(memberList) @@ -198,7 +198,7 @@ open class EnumGenerator( } rust("/// Returns all the `&str` values of the enum members.") - rustBlock("pub fn $Values() -> &'static [&'static str]") { + rustBlock("pub const fn $Values() -> &'static [&'static str]") { withBlock("&[", "]") { val memberList = sortedMembers.joinToString(", ") { it.value.doubleQuote() } write(memberList)