mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 02:04:13 +00:00
fix lints in rust tests (#6743)
Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -33,7 +33,7 @@ pub use monster_generated::my_game::sample::{Color, Equipment,
|
|||||||
fn main() {
|
fn main() {
|
||||||
// Build up a serialized buffer algorithmically.
|
// Build up a serialized buffer algorithmically.
|
||||||
// Initialize it with a capacity of 1024 bytes.
|
// Initialize it with a capacity of 1024 bytes.
|
||||||
let mut builder = flatbuffers::FlatBufferBuilder::new_with_capacity(1024);
|
let mut builder = flatbuffers::FlatBufferBuilder::with_capacity(1024);
|
||||||
|
|
||||||
// Serialize some weapons for the Monster: A 'sword' and an 'axe'.
|
// Serialize some weapons for the Monster: A 'sword' and an 'axe'.
|
||||||
let weapon_one_name = builder.create_string("Sword");
|
let weapon_one_name = builder.create_string("Sword");
|
||||||
|
|||||||
@@ -2589,9 +2589,10 @@ class RustGenerator : public BaseGenerator {
|
|||||||
// Setter.
|
// Setter.
|
||||||
if (IsStruct(field.value.type)) {
|
if (IsStruct(field.value.type)) {
|
||||||
code_.SetValue("FIELD_SIZE", NumToString(InlineSize(field.value.type)));
|
code_.SetValue("FIELD_SIZE", NumToString(InlineSize(field.value.type)));
|
||||||
|
code_ += " #[allow(clippy::identity_op)]"; // If FIELD_OFFSET=0.
|
||||||
code_ += " pub fn set_{{FIELD_NAME}}(&mut self, x: &{{FIELD_TYPE}}) {";
|
code_ += " pub fn set_{{FIELD_NAME}}(&mut self, x: &{{FIELD_TYPE}}) {";
|
||||||
code_ +=
|
code_ +=
|
||||||
" self.0[{{FIELD_OFFSET}}..{{FIELD_OFFSET}}+{{FIELD_SIZE}}]"
|
" self.0[{{FIELD_OFFSET}}..{{FIELD_OFFSET}} + {{FIELD_SIZE}}]"
|
||||||
".copy_from_slice(&x.0)";
|
".copy_from_slice(&x.0)";
|
||||||
} else if (IsArray(field.value.type)) {
|
} else if (IsArray(field.value.type)) {
|
||||||
if (GetFullType(field.value.type) == ftArrayOfBuiltin) {
|
if (GetFullType(field.value.type) == ftArrayOfBuiltin) {
|
||||||
|
|||||||
@@ -1341,8 +1341,9 @@ impl<'a> Vec3 {
|
|||||||
unsafe { &*(self.0[26..].as_ptr() as *const Test) }
|
unsafe { &*(self.0[26..].as_ptr() as *const Test) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::identity_op)]
|
||||||
pub fn set_test3(&mut self, x: &Test) {
|
pub fn set_test3(&mut self, x: &Test) {
|
||||||
self.0[26..26+4].copy_from_slice(&x.0)
|
self.0[26..26 + 4].copy_from_slice(&x.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unpack(&self) -> Vec3T {
|
pub fn unpack(&self) -> Vec3T {
|
||||||
@@ -1626,24 +1627,27 @@ impl<'a> StructOfStructs {
|
|||||||
unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
|
unsafe { &*(self.0[0..].as_ptr() as *const Ability) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::identity_op)]
|
||||||
pub fn set_a(&mut self, x: &Ability) {
|
pub fn set_a(&mut self, x: &Ability) {
|
||||||
self.0[0..0+8].copy_from_slice(&x.0)
|
self.0[0..0 + 8].copy_from_slice(&x.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn b(&self) -> &Test {
|
pub fn b(&self) -> &Test {
|
||||||
unsafe { &*(self.0[8..].as_ptr() as *const Test) }
|
unsafe { &*(self.0[8..].as_ptr() as *const Test) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::identity_op)]
|
||||||
pub fn set_b(&mut self, x: &Test) {
|
pub fn set_b(&mut self, x: &Test) {
|
||||||
self.0[8..8+4].copy_from_slice(&x.0)
|
self.0[8..8 + 4].copy_from_slice(&x.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn c(&self) -> &Ability {
|
pub fn c(&self) -> &Ability {
|
||||||
unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
|
unsafe { &*(self.0[12..].as_ptr() as *const Ability) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::identity_op)]
|
||||||
pub fn set_c(&mut self, x: &Ability) {
|
pub fn set_c(&mut self, x: &Ability) {
|
||||||
self.0[12..12+8].copy_from_slice(&x.0)
|
self.0[12..12 + 8].copy_from_slice(&x.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unpack(&self) -> StructOfStructsT {
|
pub fn unpack(&self) -> StructOfStructsT {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
use super::rwyw::NonNullString;
|
use super::rwyw::NonNullString;
|
||||||
use flexbuffers::*;
|
use flexbuffers::*;
|
||||||
use quickcheck::{Arbitrary, Gen};
|
use quickcheck::{Arbitrary, Gen};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ fn test_object_api_reads_correctly() -> Result<(), &'static str>{
|
|||||||
#[should_panic]
|
#[should_panic]
|
||||||
#[test]
|
#[test]
|
||||||
fn builder_abort_with_greater_than_maximum_buffer_size() {
|
fn builder_abort_with_greater_than_maximum_buffer_size() {
|
||||||
flatbuffers::FlatBufferBuilder::new_with_capacity(flatbuffers::FLATBUFFERS_MAX_BUFFER_SIZE+1);
|
flatbuffers::FlatBufferBuilder::with_capacity(flatbuffers::FLATBUFFERS_MAX_BUFFER_SIZE+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -2605,7 +2605,7 @@ mod byte_layouts {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn layout_03b_11xbyte_vector_matches_builder_size() {
|
fn layout_03b_11xbyte_vector_matches_builder_size() {
|
||||||
let mut b = flatbuffers::FlatBufferBuilder::new_with_capacity(12);
|
let mut b = flatbuffers::FlatBufferBuilder::with_capacity(12);
|
||||||
b.start_vector::<u8>(8);
|
b.start_vector::<u8>(8);
|
||||||
|
|
||||||
let mut gold = vec![0u8; 0];
|
let mut gold = vec![0u8; 0];
|
||||||
|
|||||||
Reference in New Issue
Block a user