Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5364

Remove clippy::vec_box lint override

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Rust - Compiler
    • None

    Description

      Currently the rust code generator wraps types in a Box in two functions:

      1. to_rust_type
      2. 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):

      struct RecTree {
        1: list<RecTree> children
        2: i16 item
      }
      

      generates the following rust:

      #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
      pub struct RecTree {
        pub children: Option<Vec<Box<RecTree>>>,
        pub item: Option<i16>,
      }
      

      Clippy trips this code up with the following error:

      /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`.
      

      This happens because all container elements (Vec,BTreeSet,BTreeMap) are automatically placed on the heap, so a Box is an additional level of indirection.

      Attachments

        Activity

          People

            Unassigned Unassigned
            allengeorge Allen George
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: