Skip to content

Commit 5722ae5

Browse files
Benjamin LermanCQ Bot
authored andcommitted
[starnix] Update rust bindgen to sort all the derived traits
Bug: 442365806 Change-Id: Idc120096f08f12935275d0ea81358da6598e4b8a Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1359313 Fuchsia-Auto-Submit: Benjamin Lerman <[email protected]> Commit-Queue: Benjamin Lerman <[email protected]> Reviewed-by: Nathaniel Manista <[email protected]>
1 parent 0e77ea5 commit 5722ae5

File tree

5 files changed

+493
-497
lines changed

5 files changed

+493
-497
lines changed

build/rust/bindgen.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def get_auto_derive_traits(self, line):
211211
if len(results) == 0:
212212
return None
213213
else:
214-
return sorted(results)
214+
return results
215215

216216
def post_process_rust_file(self, rust_file_name):
217217
with open(rust_file_name, "r+") as source_file:
@@ -221,18 +221,14 @@ def post_process_rust_file(self, rust_file_name):
221221
extra_traits = self.get_auto_derive_traits(line)
222222
if extra_traits:
223223
# Parse existing traits, if any.
224+
traits = set(extra_traits)
224225
if len(output_lines) > 0 and output_lines[-1].startswith(
225226
"#[derive(",
226227
):
227-
traits = output_lines[-1][9:-3].split(", ")
228-
traits.extend(
229-
x for x in extra_traits if x not in traits
230-
)
228+
traits.update(output_lines[-1][9:-3].split(", "))
231229
output_lines.pop()
232-
else:
233-
traits = extra_traits
234230
output_lines.append(
235-
"#[derive(" + ", ".join(traits) + ")]\n",
231+
"#[derive(" + ", ".join(sorted(traits)) + ")]\n",
236232
)
237233
output_lines.append(line)
238234

0 commit comments

Comments
 (0)