[
https://issues.apache.org/jira/browse/THRIFT-5364?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17296551#comment-17296551
]
Allen George commented on THRIFT-5364:
--------------------------------------
Also something to note: {{is_typedef}} and {{is_forward_typedef}} is used in
the Rust code generation to determine if the structs are potentially recursive.
This is the case because these flags are set when the IDL parser is generating
types and hits a type that isn't fully defined. Unfortunately this set of flags
_also_ gets defined for the following non-recursive thrift:
{noformat}
struct Foo {
1: Bar item
}
struct Bar {
1: i16 index
}
{noformat}
In this case we'd end up boxing unnecessarily.
> Remove clippy::box_vec lint override
> ------------------------------------
>
> Key: THRIFT-5364
> URL: https://issues.apache.org/jira/browse/THRIFT-5364
> Project: Thrift
> Issue Type: Improvement
> Components: Rust - Compiler
> Reporter: Allen George
> Priority: Major
>
> Currently the rust code generator wraps types in a `Box` in two functions:
> # {{to_rust_type}}
> # {{render_type_sync_read}}
> We do this only when a type is a {{typedef}} and
> {{ttypedef->is_forward_typedef() == true}}. This can result in situations
> where the following thrift ({{test/Recursive.thrift}}):
> {noformat}
> struct RecTree {
> 1: list<RecTree> children
> 2: i16 item
> }
> {noformat}
> generates the following rust:
> {noformat}
> #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
> pub struct RecTree {
> pub children: Option<Vec<Box<RecTree>>>,
> pub item: Option<i16>,
> }
> {noformat}
> Clippy trips this code up with the following error:
> {noformat}
> /root/.cargo/bin/cargo fmt --all -- --check
> /root/.cargo/bin/cargo clippy --all -- -D warnings
> Checking kitchen-sink v0.1.0 (/thrift/src/lib/rs/test)
> error: `Vec<T>` is already on the heap, the boxing is unnecessary.
> --> src/recursive.rs:35:24
> |
> 35 | pub children: Option<Vec<Box<RecTree>>>,
> | ^^^^^^^^^^^^^^^^^ help: try:
> `Vec<recursive::RecTree>`
> |
> = note: `-D clippy::vec-box` implied by `-D warnings`
> = help: for further information visit
> https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
> error: aborting due to previous error
> error: could not compile `kitchen-sink`.
> {noformat}
> This happens because all container elements
> ({{Vec}},{{BTreeSet}},{{BTreeMap}}) are automatically placed on the heap, so
> a {{Box}} is an additional level of indirection.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)