Skip to content

Commit

Permalink
fixed warnings (google#6355)
Browse files Browse the repository at this point in the history
* semver-compatible deprecations

* removed unneeded lifetimes (+ clippy warnings)

* silenced too many args warning
  • Loading branch information
krojew authored Jan 4, 2021
1 parent 0168178 commit 46545e6
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 106 deletions.
37 changes: 19 additions & 18 deletions samples/monster_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub mod sample {
extern crate flatbuffers;
use self::flatbuffers::EndianScalar;

#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_COLOR: i8 = 0;
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_COLOR: i8 = 2;
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_COLOR: [Color; 3] = [
Color::Red,
Expand Down Expand Up @@ -105,20 +105,20 @@ impl flatbuffers::EndianScalar for Color {

impl<'a> flatbuffers::Verifiable for Color {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
i8::run_verifier(v, pos)
}
}

impl flatbuffers::SimpleToVerifyInSlice for Color {}
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_EQUIPMENT: u8 = 0;
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_EQUIPMENT: u8 = 1;
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_EQUIPMENT: [Equipment; 2] = [
Equipment::NONE,
Expand Down Expand Up @@ -190,8 +190,8 @@ impl flatbuffers::EndianScalar for Equipment {

impl<'a> flatbuffers::Verifiable for Equipment {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
u8::run_verifier(v, pos)
Expand Down Expand Up @@ -257,14 +257,15 @@ impl<'b> flatbuffers::Push for &'b Vec3 {

impl<'a> flatbuffers::Verifiable for Vec3 {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.in_buffer::<Self>(pos)
}
}
impl Vec3 {
#[allow(clippy::too_many_arguments)]
pub fn new(_x: f32, _y: f32, _z: f32) -> Self {
Vec3 {
x_: _x.to_little_endian(),
Expand Down Expand Up @@ -389,8 +390,8 @@ impl<'a> Monster<'a> {

impl flatbuffers::Verifiable for Monster<'_> {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
Expand Down Expand Up @@ -576,8 +577,8 @@ impl<'a> Weapon<'a> {

impl flatbuffers::Verifiable for Weapon<'_> {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
Expand Down Expand Up @@ -637,13 +638,13 @@ impl std::fmt::Debug for Weapon<'_> {
}
}
#[inline]
#[deprecated(since="1.13", note="Deprecated in favor of `root_as...` methods.")]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
unsafe { flatbuffers::root_unchecked::<Monster<'a>>(buf) }
}

#[inline]
#[deprecated(since="1.13", note="Deprecated in favor of `root_as...` methods.")]
#[deprecated(since="2.0.0", note="Deprecated in favor of `root_as...` methods.")]
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster<'a>>(buf) }
}
Expand Down
19 changes: 10 additions & 9 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ class RustGenerator : public BaseGenerator {
// Normal, c-modelled enums.
// Deprecated associated constants;
const std::string deprecation_warning =
"#[deprecated(since = \"1.13\", note = \"Use associated constants"
"#[deprecated(since = \"2.0.0\", note = \"Use associated constants"
" instead. This will no longer be generated in 2021.\")]";
code_ += deprecation_warning;
code_ += "pub const ENUM_MIN_{{ENUM_NAME_CAPS}}: {{BASE_TYPE}}"
Expand Down Expand Up @@ -670,8 +670,8 @@ class RustGenerator : public BaseGenerator {
// Generate verifier - deferring to the base type.
code_ += "impl<'a> flatbuffers::Verifiable for {{ENUM_NAME}} {";
code_ += " #[inline]";
code_ += " fn run_verifier<'o, 'b>(";
code_ += " v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize";
code_ += " fn run_verifier(";
code_ += " v: &mut flatbuffers::Verifier, pos: usize";
code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {";
code_ += " use self::flatbuffers::Verifiable;";
code_ += " {{BASE_TYPE}}::run_verifier(v, pos)";
Expand Down Expand Up @@ -1332,8 +1332,8 @@ class RustGenerator : public BaseGenerator {
// Generate Verifier;
code_ += "impl flatbuffers::Verifiable for {{STRUCT_NAME}}<'_> {";
code_ += " #[inline]";
code_ += " fn run_verifier<'o, 'b>(";
code_ += " v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize";
code_ += " fn run_verifier(";
code_ += " v: &mut flatbuffers::Verifier, pos: usize";
code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {";
code_ += " use self::flatbuffers::Verifiable;";
code_ += " v.visit_table(pos)?\\";
Expand Down Expand Up @@ -1542,7 +1542,7 @@ class RustGenerator : public BaseGenerator {

// The root datatype accessors:
code_ += "#[inline]";
code_ += "#[deprecated(since=\"1.13\", "
code_ += "#[deprecated(since=\"2.0.0\", "
"note=\"Deprecated in favor of `root_as...` methods.\")]";
code_ +=
"pub fn get_root_as_{{STRUCT_NAME_SNAKECASE}}<'a>(buf: &'a [u8])"
Expand All @@ -1553,7 +1553,7 @@ class RustGenerator : public BaseGenerator {
code_ += "";

code_ += "#[inline]";
code_ += "#[deprecated(since=\"1.13\", "
code_ += "#[deprecated(since=\"2.0.0\", "
"note=\"Deprecated in favor of `root_as...` methods.\")]";
code_ +=
"pub fn get_size_prefixed_root_as_{{STRUCT_NAME_SNAKECASE}}"
Expand Down Expand Up @@ -1831,8 +1831,8 @@ class RustGenerator : public BaseGenerator {
// all that need to be checked.
code_ += "impl<'a> flatbuffers::Verifiable for {{STRUCT_NAME}} {";
code_ += " #[inline]";
code_ += " fn run_verifier<'o, 'b>(";
code_ += " v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize";
code_ += " fn run_verifier(";
code_ += " v: &mut flatbuffers::Verifier, pos: usize";
code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {";
code_ += " use self::flatbuffers::Verifiable;";
code_ += " v.in_buffer::<Self>(pos)";
Expand All @@ -1843,6 +1843,7 @@ class RustGenerator : public BaseGenerator {
code_ += "impl {{STRUCT_NAME}} {";
// TODO(cneo): Stop generating args on one line. Make it simpler.
bool first_arg = true;
code_ += " #[allow(clippy::too_many_arguments)]";
code_ += " pub fn new(\\";
ForAllStructFields(struct_def, [&](const FieldDef &field) {
if (first_arg) first_arg = false; else code_ += ", \\";
Expand Down
4 changes: 2 additions & 2 deletions tests/include_test/include_test1_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ impl<'a> TableA<'a> {

impl flatbuffers::Verifiable for TableA<'_> {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
Expand Down
19 changes: 10 additions & 9 deletions tests/include_test/sub/include_test2_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub mod other_name_space {
extern crate flatbuffers;
use self::flatbuffers::EndianScalar;

#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MIN_FROM_INCLUDE: i64 = 0;
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
pub const ENUM_MAX_FROM_INCLUDE: i64 = 0;
#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
#[allow(non_camel_case_types)]
pub const ENUM_VALUES_FROM_INCLUDE: [FromInclude; 1] = [
FromInclude::IncludeVal,
Expand Down Expand Up @@ -100,8 +100,8 @@ impl flatbuffers::EndianScalar for FromInclude {

impl<'a> flatbuffers::Verifiable for FromInclude {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
i64::run_verifier(v, pos)
Expand Down Expand Up @@ -163,14 +163,15 @@ impl<'b> flatbuffers::Push for &'b Unused {

impl<'a> flatbuffers::Verifiable for Unused {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.in_buffer::<Self>(pos)
}
}
impl Unused {
#[allow(clippy::too_many_arguments)]
pub fn new(_a: i32) -> Self {
Unused {
a_: _a.to_little_endian(),
Expand Down Expand Up @@ -223,8 +224,8 @@ impl<'a> TableB<'a> {

impl flatbuffers::Verifiable for TableB<'_> {
#[inline]
fn run_verifier<'o, 'b>(
v: &mut flatbuffers::Verifier<'o, 'b>, pos: usize
fn run_verifier(
v: &mut flatbuffers::Verifier, pos: usize
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
use self::flatbuffers::Verifiable;
v.visit_table(pos)?
Expand Down
Loading

0 comments on commit 46545e6

Please sign in to comment.