Skip to content

Commit

Permalink
Remove attributes annotation of Builder struct
Browse files Browse the repository at this point in the history
The `struct` created for a Builder should not have attributes because these structs only derive from `Debug`,
`PartialEq`, `Clone` and `Default`. None of these support attributes.

This becomes a problem if a plugin tries to add attributes to the `metadata` field to configure the generated code for
the `struct`. In this case, the attributes will also be added to the `Builder` struct; which is wrong.
  • Loading branch information
Gustavo Muenz committed Jun 3, 2024
1 parent a76dc18 commit dc3a159
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ class BuilderGenerator(
metadata.derives.filter {
it == RuntimeType.Debug || it == RuntimeType.PartialEq || it == RuntimeType.Clone
} + RuntimeType.Default
// Filter out attributes
private val builderAttributes =
metadata.additionalAttributes.filter {
it == Attribute.NonExhaustive
}
private val builderName = symbolProvider.symbolForBuilder(shape).name

fun render(writer: RustWriter) {
Expand Down Expand Up @@ -306,8 +311,8 @@ class BuilderGenerator(

private fun renderBuilder(writer: RustWriter) {
writer.docs("A builder for #D.", structureSymbol)
metadata.additionalAttributes.render(writer)
Attribute(derive(builderDerives)).render(writer)
this.builderAttributes.render(writer)
writer.rustBlock("pub struct $builderName") {
for (member in members) {
val memberName = symbolProvider.toMemberName(member)
Expand Down

0 comments on commit dc3a159

Please sign in to comment.