Skip to content

Commit

Permalink
Generate more concise @rust.Serde in structured annotations codemod
Browse files Browse the repository at this point in the history
Summary: Since {D69065617}, `rust.Serde{enabled = true}` is redundant. We can just write `rust.Serde`, similar to other Rust Thrift annotations like `rust.Ord` and `rust.Copy`.

Reviewed By: zertosh

Differential Revision: D69065616

fbshipit-source-id: a0bc8035063270521f73f56137912558a581d135
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Feb 4, 2025
1 parent 62209f3 commit d0bc263
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,11 @@ class structure_annotations {
to_remove.emplace_back(name, data);
} else if (name == "rust.serde") {
to_remove.emplace_back(name, data);
to_add.insert(fmt::format("@rust.Serde{{enabled = {}}}", data.value));
if (data.value == "false") {
to_add.insert("@rust.Serde{enabled = false}");
} else {
to_add.insert("@rust.Serde");
}
fm_.add_include("thrift/annotation/rust.thrift");
} else if (name == "rust.mod") {
to_remove.emplace_back(name, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ def test_rust(self):
1: i32 (rust.type = "u32") f (rust.name = "foo", rust.box, rust.type = "foo");
} (rust.arc, rust.copy, rust.exhaustive, rust.ord, rust.serde = "true", rust.mod = "foo", rust.derive = "Foo, Bar")
struct SerdeOptOut {} (rust.serde = "false")
service S {} (rust.request_context)
"""
Expand All @@ -467,14 +469,17 @@ def test_rust(self):
@rust.Exhaustive
@rust.Mod{name = "foo"}
@rust.Ord
@rust.Serde{enabled = true}
@rust.Serde
struct S {
@rust.Box
@rust.Name{name = "foo"}
@rust.Type{name = "u32"}
1: i32 f ;
}
@rust.Serde{enabled = false}
struct SerdeOptOut {}
@rust.RequestContext
service S {}
"""
Expand Down

0 comments on commit d0bc263

Please sign in to comment.