Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rust1.85 compile warnings #8540

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/rust_generated/my_game/sample/color_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> flatbuffers::Follow<'a> for Color {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
let b = unsafe { flatbuffers::read_scalar_at::<i8>(buf, loc) };
Self(b)
}
}
Expand All @@ -69,7 +69,7 @@ impl flatbuffers::Push for Color {
type Output = Color;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions samples/rust_generated/my_game/sample/equipment_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'a> flatbuffers::Follow<'a> for Equipment {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
let b = unsafe { flatbuffers::read_scalar_at::<u8>(buf, loc) };
Self(b)
}
}
Expand All @@ -65,7 +65,7 @@ impl flatbuffers::Push for Equipment {
type Output = Equipment;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<u8>(dst, self.0);
unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0) };
}
}

Expand Down
6 changes: 3 additions & 3 deletions samples/rust_generated/my_game/sample/monster_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
type Inner = Monster<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down Expand Up @@ -451,14 +451,14 @@ pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>(
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid `Monster`.
pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster {
flatbuffers::root_unchecked::<Monster>(buf)
unsafe { flatbuffers::root_unchecked::<Monster>(buf) }
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`.
pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster {
flatbuffers::size_prefixed_root_unchecked::<Monster>(buf)
unsafe { flatbuffers::size_prefixed_root_unchecked::<Monster>(buf) }
}
#[inline]
pub fn finish_monster_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
Expand Down
6 changes: 3 additions & 3 deletions samples/rust_generated/my_game/sample/vec_3_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ impl<'a> flatbuffers::Follow<'a> for Vec3 {
type Inner = &'a Vec3;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Vec3>::follow(buf, loc)
unsafe { <&'a Vec3>::follow(buf, loc) }
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
type Inner = &'a Vec3;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
unsafe { flatbuffers::follow_cast_ref::<Vec3>(buf, loc) }
}
}
impl<'b> flatbuffers::Push for Vec3 {
type Output = Vec3;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, <Self as flatbuffers::Push>::size());
let src = unsafe { ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, <Self as flatbuffers::Push>::size()) };
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion samples/rust_generated/my_game/sample/weapon_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
type Inner = Weapon<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down
26 changes: 15 additions & 11 deletions src/idl_gen_rust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,8 @@ class RustGenerator : public BaseGenerator {
code_ += " #[inline]";
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
code_ +=
" let b = flatbuffers::read_scalar_at::<{{BASE_TYPE}}>(buf, loc);";
" let b = unsafe { "
"flatbuffers::read_scalar_at::<{{BASE_TYPE}}>(buf, loc) };";
if (IsBitFlagsEnum(enum_def)) {
code_ += " Self::from_bits_retain(b)";
} else {
Expand All @@ -855,8 +856,8 @@ class RustGenerator : public BaseGenerator {
code_ += " #[inline]";
code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {";
code_ +=
" flatbuffers::emplace_scalar::<{{BASE_TYPE}}>(dst, "
"{{INTO_BASE}});";
" unsafe { flatbuffers::emplace_scalar::<{{BASE_TYPE}}>(dst, "
"{{INTO_BASE}}) };";
code_ += " }";
code_ += "}";
code_ += "";
Expand Down Expand Up @@ -1658,7 +1659,7 @@ class RustGenerator : public BaseGenerator {
code_ += " type Inner = {{STRUCT_TY}}<'a>;";
code_ += " #[inline]";
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
code_ += " Self { _tab: flatbuffers::Table::new(buf, loc) }";
code_ += " Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }";
code_ += " }";
code_ += "}";
code_ += "";
Expand Down Expand Up @@ -2481,7 +2482,7 @@ class RustGenerator : public BaseGenerator {
code_ +=
"pub unsafe fn root_as_{{STRUCT_FN}}_unchecked"
"(buf: &[u8]) -> {{STRUCT_TY}} {";
code_ += " flatbuffers::root_unchecked::<{{STRUCT_TY}}>(buf)";
code_ += " unsafe { flatbuffers::root_unchecked::<{{STRUCT_TY}}>(buf) }";
code_ += "}";
code_ += "#[inline]";
code_ +=
Expand All @@ -2495,8 +2496,8 @@ class RustGenerator : public BaseGenerator {
"pub unsafe fn size_prefixed_root_as_{{STRUCT_FN}}"
"_unchecked(buf: &[u8]) -> {{STRUCT_TY}} {";
code_ +=
" flatbuffers::size_prefixed_root_unchecked::<{{STRUCT_TY}}>"
"(buf)";
" unsafe { flatbuffers::size_prefixed_root_unchecked::<{{STRUCT_TY}}>"
"(buf) }";
code_ += "}";

if (parser_.file_identifier_.length()) {
Expand Down Expand Up @@ -2656,23 +2657,26 @@ class RustGenerator : public BaseGenerator {
code_ += " type Inner = &'a {{STRUCT_TY}};";
code_ += " #[inline]";
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
code_ += " <&'a {{STRUCT_TY}}>::follow(buf, loc)";
code_ += " unsafe { <&'a {{STRUCT_TY}}>::follow(buf, loc) }";
code_ += " }";
code_ += "}";
code_ += "impl<'a> flatbuffers::Follow<'a> for &'a {{STRUCT_TY}} {";
code_ += " type Inner = &'a {{STRUCT_TY}};";
code_ += " #[inline]";
code_ += " unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {";
code_ += " flatbuffers::follow_cast_ref::<{{STRUCT_TY}}>(buf, loc)";
code_ +=
" unsafe { flatbuffers::follow_cast_ref::<{{STRUCT_TY}}>(buf, loc) "
"}";
code_ += " }";
code_ += "}";
code_ += "impl<'b> flatbuffers::Push for {{STRUCT_TY}} {";
code_ += " type Output = {{STRUCT_TY}};";
code_ += " #[inline]";
code_ += " unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {";
code_ +=
" let src = ::core::slice::from_raw_parts(self as *const "
"{{STRUCT_TY}} as *const u8, <Self as flatbuffers::Push>::size());";
" let src = unsafe { ::core::slice::from_raw_parts(self as "
"*const {{STRUCT_TY}} as *const u8, <Self as "
"flatbuffers::Push>::size()) };";
code_ += " dst.copy_from_slice(src);";
code_ += " }";
code_ += " #[inline]";
Expand Down
6 changes: 3 additions & 3 deletions tests/arrays_test/my_game/example/array_struct_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ impl<'a> flatbuffers::Follow<'a> for ArrayStruct {
type Inner = &'a ArrayStruct;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a ArrayStruct>::follow(buf, loc)
unsafe { <&'a ArrayStruct>::follow(buf, loc) }
}
}
impl<'a> flatbuffers::Follow<'a> for &'a ArrayStruct {
type Inner = &'a ArrayStruct;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<ArrayStruct>(buf, loc)
unsafe { flatbuffers::follow_cast_ref::<ArrayStruct>(buf, loc) }
}
}
impl<'b> flatbuffers::Push for ArrayStruct {
type Output = ArrayStruct;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, <Self as flatbuffers::Push>::size());
let src = unsafe { ::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, <Self as flatbuffers::Push>::size()) };
dst.copy_from_slice(src);
}
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions tests/arrays_test/my_game/example/array_table_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for ArrayTable<'a> {
type Inner = ArrayTable<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down Expand Up @@ -193,14 +193,14 @@ pub fn size_prefixed_root_as_array_table_with_opts<'b, 'o>(
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid `ArrayTable`.
pub unsafe fn root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable {
flatbuffers::root_unchecked::<ArrayTable>(buf)
unsafe { flatbuffers::root_unchecked::<ArrayTable>(buf) }
}
#[inline]
/// Assumes, without verification, that a buffer of bytes contains a size prefixed ArrayTable and returns it.
/// # Safety
/// Callers must trust the given bytes do indeed contain a valid size prefixed `ArrayTable`.
pub unsafe fn size_prefixed_root_as_array_table_unchecked(buf: &[u8]) -> ArrayTable {
flatbuffers::size_prefixed_root_unchecked::<ArrayTable>(buf)
unsafe { flatbuffers::size_prefixed_root_unchecked::<ArrayTable>(buf) }
}
pub const ARRAY_TABLE_IDENTIFIER: &str = "ARRT";

Expand Down
6 changes: 3 additions & 3 deletions tests/arrays_test/my_game/example/nested_struct_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ impl<'a> flatbuffers::Follow<'a> for NestedStruct {
type Inner = &'a NestedStruct;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a NestedStruct>::follow(buf, loc)
unsafe { <&'a NestedStruct>::follow(buf, loc) }
}
}
impl<'a> flatbuffers::Follow<'a> for &'a NestedStruct {
type Inner = &'a NestedStruct;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<NestedStruct>(buf, loc)
unsafe { flatbuffers::follow_cast_ref::<NestedStruct>(buf, loc) }
}
}
impl<'b> flatbuffers::Push for NestedStruct {
type Output = NestedStruct;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, <Self as flatbuffers::Push>::size());
let src = unsafe { ::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, <Self as flatbuffers::Push>::size()) };
dst.copy_from_slice(src);
}
#[inline]
Expand Down
4 changes: 2 additions & 2 deletions tests/arrays_test/my_game/example/test_enum_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> flatbuffers::Follow<'a> for TestEnum {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
let b = unsafe { flatbuffers::read_scalar_at::<i8>(buf, loc) };
Self(b)
}
}
Expand All @@ -69,7 +69,7 @@ impl flatbuffers::Push for TestEnum {
type Output = TestEnum;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i8>(dst, self.0);
unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0) };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
let b = unsafe { flatbuffers::read_scalar_at::<i64>(buf, loc) };
Self(b)
}
}
Expand All @@ -61,7 +61,7 @@ impl flatbuffers::Push for FromInclude {
type Output = FromInclude;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i64>(dst, self.0);
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0) };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ impl<'a> flatbuffers::Follow<'a> for Unused {
type Inner = &'a Unused;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Unused>::follow(buf, loc)
unsafe { <&'a Unused>::follow(buf, loc) }
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
type Inner = &'a Unused;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
unsafe { flatbuffers::follow_cast_ref::<Unused>(buf, loc) }
}
}
impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size());
let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size()) };
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion tests/include_test1/table_a_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a> flatbuffers::Follow<'a> for FromInclude {
type Inner = Self;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
let b = flatbuffers::read_scalar_at::<i64>(buf, loc);
let b = unsafe { flatbuffers::read_scalar_at::<i64>(buf, loc) };
Self(b)
}
}
Expand All @@ -61,7 +61,7 @@ impl flatbuffers::Push for FromInclude {
type Output = FromInclude;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
flatbuffers::emplace_scalar::<i64>(dst, self.0);
unsafe { flatbuffers::emplace_scalar::<i64>(dst, self.0) };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for TableB<'a> {
type Inner = TableB<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ impl<'a> flatbuffers::Follow<'a> for Unused {
type Inner = &'a Unused;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
<&'a Unused>::follow(buf, loc)
unsafe { <&'a Unused>::follow(buf, loc) }
}
}
impl<'a> flatbuffers::Follow<'a> for &'a Unused {
type Inner = &'a Unused;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
flatbuffers::follow_cast_ref::<Unused>(buf, loc)
unsafe { flatbuffers::follow_cast_ref::<Unused>(buf, loc) }
}
}
impl<'b> flatbuffers::Push for Unused {
type Output = Unused;
#[inline]
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
let src = ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size());
let src = unsafe { ::core::slice::from_raw_parts(self as *const Unused as *const u8, <Self as flatbuffers::Push>::size()) };
dst.copy_from_slice(src);
}
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion tests/include_test2/table_a_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> flatbuffers::Follow<'a> for TableA<'a> {
type Inner = TableA<'a>;
#[inline]
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
Self { _tab: flatbuffers::Table::new(buf, loc) }
Self { _tab: unsafe { flatbuffers::Table::new(buf, loc) } }
}
}

Expand Down
Loading