From 8b5e920597d9b49c3c6f3053cf50bd3e7b11c709 Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Wed, 22 May 2019 07:24:59 -0400 Subject: [PATCH 1/6] Support alloc-only no_std platforms --- rust/flatbuffers/Cargo.toml | 4 ++++ rust/flatbuffers/src/builder.rs | 13 ++++++++----- rust/flatbuffers/src/endian_scalar.rs | 2 +- rust/flatbuffers/src/follow.rs | 2 +- rust/flatbuffers/src/lib.rs | 8 ++++++++ rust/flatbuffers/src/primitives.rs | 6 +++--- rust/flatbuffers/src/push.rs | 4 ++-- rust/flatbuffers/src/vtable_writer.rs | 2 +- 8 files changed, 28 insertions(+), 13 deletions(-) diff --git a/rust/flatbuffers/Cargo.toml b/rust/flatbuffers/Cargo.toml index b3114bd7674..f436b4425e5 100644 --- a/rust/flatbuffers/Cargo.toml +++ b/rust/flatbuffers/Cargo.toml @@ -15,3 +15,7 @@ rust = "1.51" smallvec = "1.6.1" bitflags = "1.2.1" thiserror = "1.0.23" + +[features] +default = ["std"] +std = [] diff --git a/rust/flatbuffers/src/builder.rs b/rust/flatbuffers/src/builder.rs index 9309877116b..aed94fad45c 100644 --- a/rust/flatbuffers/src/builder.rs +++ b/rust/flatbuffers/src/builder.rs @@ -16,11 +16,14 @@ extern crate smallvec; -use std::cmp::max; -use std::iter::{DoubleEndedIterator, ExactSizeIterator}; -use std::marker::PhantomData; -use std::ptr::write_bytes; -use std::slice::from_raw_parts; +#[cfg(not(feature = "std"))] +use alloc::{vec, vec::Vec}; + +use core::cmp::max; +use core::iter::{DoubleEndedIterator, ExactSizeIterator}; +use core::marker::PhantomData; +use core::ptr::write_bytes; +use core::slice::from_raw_parts; use crate::endian_scalar::{emplace_scalar, read_scalar_at}; use crate::primitives::*; diff --git a/rust/flatbuffers/src/endian_scalar.rs b/rust/flatbuffers/src/endian_scalar.rs index 7e8d8e3e442..5f50cf1f36e 100644 --- a/rust/flatbuffers/src/endian_scalar.rs +++ b/rust/flatbuffers/src/endian_scalar.rs @@ -15,7 +15,7 @@ */ #![allow(clippy::wrong_self_convention)] -use std::mem::size_of; +use core::mem::size_of; /// Trait for values that must be stored in little-endian byte order, but /// might be represented in memory as big-endian. Every type that implements diff --git a/rust/flatbuffers/src/follow.rs b/rust/flatbuffers/src/follow.rs index a09003d7d5d..d1d6483ae67 100644 --- a/rust/flatbuffers/src/follow.rs +++ b/rust/flatbuffers/src/follow.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::marker::PhantomData; +use core::marker::PhantomData; /// Follow is a trait that allows us to access FlatBuffers in a declarative, /// type safe, and fast way. They compile down to almost no code (after diff --git a/rust/flatbuffers/src/lib.rs b/rust/flatbuffers/src/lib.rs index 465e169062f..58d81c668e6 100644 --- a/rust/flatbuffers/src/lib.rs +++ b/rust/flatbuffers/src/lib.rs @@ -28,6 +28,14 @@ //! At this time, to generate Rust code, you will need the latest `master` version of `flatc`, available from here: //! (On OSX, you can install FlatBuffers from `HEAD` with the Homebrew package manager.) +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(feature = "std")] +extern crate core; + +#[cfg(not(feature = "std"))] +extern crate alloc; + mod array; mod builder; mod endian_scalar; diff --git a/rust/flatbuffers/src/primitives.rs b/rust/flatbuffers/src/primitives.rs index b7b4942d6cd..72764b21365 100644 --- a/rust/flatbuffers/src/primitives.rs +++ b/rust/flatbuffers/src/primitives.rs @@ -14,9 +14,9 @@ * limitations under the License. */ -use std::marker::PhantomData; -use std::mem::size_of; -use std::ops::Deref; +use core::marker::PhantomData; +use core::mem::size_of; +use core::ops::Deref; use crate::endian_scalar::{emplace_scalar, read_scalar, read_scalar_at}; use crate::follow::Follow; diff --git a/rust/flatbuffers/src/push.rs b/rust/flatbuffers/src/push.rs index 72ff88cd719..8bb8fe9a7df 100644 --- a/rust/flatbuffers/src/push.rs +++ b/rust/flatbuffers/src/push.rs @@ -14,8 +14,8 @@ * limitations under the License. */ -use std::cmp::max; -use std::mem::{align_of, size_of}; +use core::cmp::max; +use core::mem::{align_of, size_of}; use crate::endian_scalar::emplace_scalar; diff --git a/rust/flatbuffers/src/vtable_writer.rs b/rust/flatbuffers/src/vtable_writer.rs index 92e8522eb27..9b61dac7fcb 100644 --- a/rust/flatbuffers/src/vtable_writer.rs +++ b/rust/flatbuffers/src/vtable_writer.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::ptr::write_bytes; +use core::ptr::write_bytes; use crate::endian_scalar::emplace_scalar; use crate::primitives::*; From d10ca859a3a413076290c3d2e610205e700847b5 Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Wed, 22 May 2019 07:39:07 -0400 Subject: [PATCH 2/6] Update rust generator for no_std Also re-run generator on sample. --- conan/travis/build.sh | 2 +- conan/travis/install.sh | 2 +- grpc/build_grpc.sh | 2 +- grpc/examples/generate.sh | 2 +- grpc/examples/go/format.sh | 2 +- reflection/generate_code.sh | 2 +- samples/csharp_sample.sh | 2 +- samples/dart_sample.sh | 2 +- samples/go_sample.sh | 2 +- samples/java_sample.sh | 2 +- samples/javascript_sample.sh | 2 +- samples/kotlin_sample.sh | 2 +- samples/php_sample.sh | 2 +- samples/python_sample.sh | 2 +- .../my_game/sample/color_generated.rs | 13 ++++-- .../my_game/sample/equipment_generated.rs | 15 ++++--- .../my_game/sample/monster_generated.rs | 13 ++++-- .../my_game/sample/vec_3_generated.rs | 17 ++++--- .../my_game/sample/weapon_generated.rs | 13 ++++-- scripts/check-generate-code.sh | 2 +- scripts/check-grpc-generated-code.sh | 2 +- src/idl_gen_rust.cpp | 44 +++++++++++-------- tests/GoTest.sh | 2 +- tests/JavaTest.sh | 2 +- tests/LuaTest.sh | 2 +- tests/PythonTest.sh | 2 +- .../my_game/example/array_struct_generated.rs | 19 +++++--- .../my_game/example/array_table_generated.rs | 13 ++++-- .../example/nested_struct_generated.rs | 19 +++++--- .../my_game/example/test_enum_generated.rs | 13 ++++-- tests/generate_code.sh | 2 +- .../from_include_generated.rs | 13 ++++-- .../other_name_space/table_b_generated.rs | 13 ++++-- .../other_name_space/unused_generated.rs | 17 ++++--- tests/include_test1/table_a_generated.rs | 13 ++++-- .../from_include_generated.rs | 13 ++++-- .../other_name_space/table_b_generated.rs | 13 ++++-- .../other_name_space/unused_generated.rs | 17 ++++--- tests/include_test2/table_a_generated.rs | 13 ++++-- .../keyword_test/abc_generated.rs | 13 ++++-- .../keywords_in_table_generated.rs | 13 ++++-- .../keywords_in_union_generated.rs | 17 ++++--- .../keyword_test/public_generated.rs | 13 ++++-- .../my_game/example/ability_generated.rs | 19 +++++--- .../any_ambiguous_aliases_generated.rs | 19 +++++--- .../my_game/example/any_generated.rs | 19 +++++--- .../example/any_unique_aliases_generated.rs | 19 +++++--- .../my_game/example/color_generated.rs | 9 +++- .../my_game/example/monster_generated.rs | 15 ++++--- .../my_game/example/race_generated.rs | 13 ++++-- .../my_game/example/referrable_generated.rs | 15 ++++--- .../my_game/example/stat_generated.rs | 15 ++++--- .../example/struct_of_structs_generated.rs | 17 ++++--- .../my_game/example/test_generated.rs | 17 ++++--- .../test_simple_table_with_enum_generated.rs | 13 ++++-- .../my_game/example/type_aliases_generated.rs | 13 ++++-- .../my_game/example/vec_3_generated.rs | 17 ++++--- .../my_game/example_2/monster_generated.rs | 13 ++++-- .../my_game/in_parent_namespace_generated.rs | 13 ++++-- .../from_include_generated.rs | 13 ++++-- .../other_name_space/table_b_generated.rs | 13 ++++-- .../other_name_space/unused_generated.rs | 17 ++++--- tests/monster_test/table_a_generated.rs | 13 ++++-- tests/more_defaults/abc_generated.rs | 13 ++++-- .../more_defaults/more_defaults_generated.rs | 13 ++++-- .../enum_in_nested_ns_generated.rs | 13 ++++-- .../struct_in_nested_ns_generated.rs | 17 ++++--- .../table_in_nested_ns_generated.rs | 13 ++++-- .../union_in_nested_ns_generated.rs | 15 ++++--- .../second_table_in_a_generated.rs | 13 ++++-- .../table_in_first_ns_generated.rs | 13 ++++-- .../namespace_c/table_in_c_generated.rs | 13 ++++-- .../optional_byte_generated.rs | 13 ++++-- .../scalar_stuff_generated.rs | 13 ++++-- tests/phpUnionVectorTest.sh | 2 +- 75 files changed, 555 insertions(+), 287 deletions(-) diff --git a/conan/travis/build.sh b/conan/travis/build.sh index 069ced202f8..ede93ad9c6d 100755 --- a/conan/travis/build.sh +++ b/conan/travis/build.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e set -x diff --git a/conan/travis/install.sh b/conan/travis/install.sh index f4208d82643..c96c42b6603 100755 --- a/conan/travis/install.sh +++ b/conan/travis/install.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e set -x diff --git a/grpc/build_grpc.sh b/grpc/build_grpc.sh index 49c5a60f0eb..380f67400c8 100755 --- a/grpc/build_grpc.sh +++ b/grpc/build_grpc.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash grpc_1_39_0_githash=58602e20a3f3e48f24a4114c757099b25b947f7b diff --git a/grpc/examples/generate.sh b/grpc/examples/generate.sh index 39ca6620c3a..49f4be2629a 100755 --- a/grpc/examples/generate.sh +++ b/grpc/examples/generate.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/grpc/examples/go/format.sh b/grpc/examples/go/format.sh index a7ee9e3156a..3281ff7a08c 100644 --- a/grpc/examples/go/format.sh +++ b/grpc/examples/go/format.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/reflection/generate_code.sh b/reflection/generate_code.sh index 694baa2d74a..4b7d2f242c5 100755 --- a/reflection/generate_code.sh +++ b/reflection/generate_code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2016 Google Inc. All rights reserved. # diff --git a/samples/csharp_sample.sh b/samples/csharp_sample.sh index ea472ed9c05..465da209794 100755 --- a/samples/csharp_sample.sh +++ b/samples/csharp_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/dart_sample.sh b/samples/dart_sample.sh index 40326790dfc..6192e738a33 100755 --- a/samples/dart_sample.sh +++ b/samples/dart_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo # # Copyright 2018 Dan Field. All rights reserved. diff --git a/samples/go_sample.sh b/samples/go_sample.sh index 13a96c12932..5131ed3c3b4 100755 --- a/samples/go_sample.sh +++ b/samples/go_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/java_sample.sh b/samples/java_sample.sh index bd1315f4ce4..53064906557 100755 --- a/samples/java_sample.sh +++ b/samples/java_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/javascript_sample.sh b/samples/javascript_sample.sh index 4bbc478d7f5..805719d9e4e 100755 --- a/samples/javascript_sample.sh +++ b/samples/javascript_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/kotlin_sample.sh b/samples/kotlin_sample.sh index ca4ea86dca8..bd9e0d6fb88 100755 --- a/samples/kotlin_sample.sh +++ b/samples/kotlin_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/php_sample.sh b/samples/php_sample.sh index c23edc380f9..0d7d61b4fdb 100755 --- a/samples/php_sample.sh +++ b/samples/php_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/python_sample.sh b/samples/python_sample.sh index ca5de2b03fd..a59565f5fe4 100755 --- a/samples/python_sample.sh +++ b/samples/python_sample.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 Google Inc. All rights reserved. # diff --git a/samples/rust_generated/my_game/sample/color_generated.rs b/samples/rust_generated/my_game/sample/color_generated.rs index 1ef1d31b5c7..595eb297b7a 100644 --- a/samples/rust_generated/my_game/sample/color_generated.rs +++ b/samples/rust_generated/my_game/sample/color_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl Color { } } } -impl std::fmt::Debug for Color { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Color { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/samples/rust_generated/my_game/sample/equipment_generated.rs b/samples/rust_generated/my_game/sample/equipment_generated.rs index 919958a355a..8ef42ce2f95 100644 --- a/samples/rust_generated/my_game/sample/equipment_generated.rs +++ b/samples/rust_generated/my_game/sample/equipment_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -38,8 +43,8 @@ impl Equipment { } } } -impl std::fmt::Debug for Equipment { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Equipment { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -121,7 +126,7 @@ impl EquipmentT { /// If the union variant matches, return the owned WeaponT, setting the union to NONE. pub fn take_weapon(&mut self) -> Option> { if let Self::Weapon(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::Weapon(w) = v { Some(w) } else { diff --git a/samples/rust_generated/my_game/sample/monster_generated.rs b/samples/rust_generated/my_game/sample/monster_generated.rs index d8988321247..4a197a3c38d 100644 --- a/samples/rust_generated/my_game/sample/monster_generated.rs +++ b/samples/rust_generated/my_game/sample/monster_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum MonsterOffset {} @@ -265,8 +270,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("Monster"); ds.field("pos", &self.pos()); ds.field("mana", &self.mana()); diff --git a/samples/rust_generated/my_game/sample/vec_3_generated.rs b/samples/rust_generated/my_game/sample/vec_3_generated.rs index 33805b3f90a..0957ff3931f 100644 --- a/samples/rust_generated/my_game/sample/vec_3_generated.rs +++ b/samples/rust_generated/my_game/sample/vec_3_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Vec3, aligned to 4 @@ -13,8 +18,8 @@ impl Default for Vec3 { Self([0; 12]) } } -impl std::fmt::Debug for Vec3 { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Vec3 { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Vec3") .field("x", &self.x()) .field("y", &self.y()) @@ -44,7 +49,7 @@ impl<'b> flatbuffers::Push for Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -55,7 +60,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/samples/rust_generated/my_game/sample/weapon_generated.rs b/samples/rust_generated/my_game/sample/weapon_generated.rs index e2cede9d666..aaf56a8d559 100644 --- a/samples/rust_generated/my_game/sample/weapon_generated.rs +++ b/samples/rust_generated/my_game/sample/weapon_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum WeaponOffset {} @@ -117,8 +122,8 @@ impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> { } } -impl std::fmt::Debug for Weapon<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for Weapon<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("Weapon"); ds.field("name", &self.name()); ds.field("damage", &self.damage()); diff --git a/scripts/check-generate-code.sh b/scripts/check-generate-code.sh index 1f2d84d4d56..019999ea3e3 100755 --- a/scripts/check-generate-code.sh +++ b/scripts/check-generate-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2018 Google Inc. All rights reserved. # diff --git a/scripts/check-grpc-generated-code.sh b/scripts/check-grpc-generated-code.sh index 4541be16eff..95d400bf58e 100755 --- a/scripts/check-grpc-generated-code.sh +++ b/scripts/check-grpc-generated-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 813a4c199bf..6c8e43b3aee 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -322,6 +322,7 @@ class RustGenerator : public BaseGenerator { "yield", // other rust terms we should not use + "core" "std", "usize", "isize", @@ -382,8 +383,13 @@ class RustGenerator : public BaseGenerator { code_.Clear(); code_ += "// " + std::string(FlatBuffersGeneratedWarning()); code_ += "extern crate flatbuffers;"; - code_ += "use std::mem;"; - code_ += "use std::cmp::Ordering;"; + code_ += "extern crate core;"; + code_ += "extern crate alloc;"; + code_ += "use self::alloc::vec::Vec;"; + code_ += "use self::alloc::boxed::Box;"; + code_ += "use self::alloc::string::{String, ToString as _};"; + code_ += "use self::core::mem;"; + code_ += "use self::core::cmp::Ordering;"; code_ += "use self::flatbuffers::{EndianScalar, Follow};"; code_ += "use super::*;"; cur_name_space_ = symbol.defined_namespace; @@ -826,10 +832,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; // Generate Debug. Unknown variants are printed like "". - code_ += "impl std::fmt::Debug for {{ENUM_NAME}} {"; + code_ += "impl self::core::fmt::Debug for {{ENUM_NAME}} {"; code_ += - " fn fmt(&self, f: &mut std::fmt::Formatter) ->" - " std::fmt::Result {"; + " fn fmt(&self, f: &mut self::core::fmt::Formatter) ->" + " self::core::fmt::Result {"; code_ += " if let Some(name) = self.variant_name() {"; code_ += " f.write_str(name)"; code_ += " } else {"; @@ -981,7 +987,7 @@ class RustGenerator : public BaseGenerator { "pub fn take_{{U_ELEMENT_NAME}}(&mut self) -> " "Option> {"; code_ += " if let Self::{{NATIVE_VARIANT}}(_) = self {"; - code_ += " let v = std::mem::replace(self, Self::NONE);"; + code_ += " let v = self::core::mem::replace(self, Self::NONE);"; code_ += " if let Self::{{NATIVE_VARIANT}}(w) = v {"; code_ += " Some(w)"; code_ += " } else {"; @@ -2078,10 +2084,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; code_ += ""; - code_ += "impl std::fmt::Debug for {{STRUCT_NAME}}<'_> {"; + code_ += "impl self::core::fmt::Debug for {{STRUCT_NAME}}<'_> {"; code_ += - " fn fmt(&self, f: &mut std::fmt::Formatter<'_>" - ") -> std::fmt::Result {"; + " fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>" + ") -> self::core::fmt::Result {"; code_ += " let mut ds = f.debug_struct(\"{{STRUCT_NAME}}\");"; ForAllTableFields(struct_def, [&](const FieldDef &field) { if (GetFullType(field.value.type) == ftUnionValue) { @@ -2302,7 +2308,7 @@ class RustGenerator : public BaseGenerator { code_ += "#[inline]"; code_ += "pub fn key_compare_with_value(&self, val: {{KEY_TYPE}}) -> " - "::std::cmp::Ordering {"; + " self::core::cmp::Ordering {"; code_ += " let key = self.{{FIELD_NAME}}();"; code_ += " key.cmp({{REF}}val)"; code_ += "}"; @@ -2565,10 +2571,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; // Debug for structs. - code_ += "impl std::fmt::Debug for {{STRUCT_NAME}} {"; + code_ += "impl self::core::fmt::Debug for {{STRUCT_NAME}} {"; code_ += - " fn fmt(&self, f: &mut std::fmt::Formatter" - ") -> std::fmt::Result {"; + " fn fmt(&self, f: &mut self::core::fmt::Formatter" + ") -> self::core::fmt::Result {"; code_ += " f.debug_struct(\"{{STRUCT_NAME}}\")"; ForAllStructFields(struct_def, [&](const FieldDef &unused) { (void)unused; @@ -2604,7 +2610,7 @@ class RustGenerator : public BaseGenerator { code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {"; code_ += " let src = unsafe {"; code_ += - " ::std::slice::from_raw_parts(" + " self::core::slice::from_raw_parts(" "self as *const {{STRUCT_NAME}} as *const u8, Self::size())"; code_ += " };"; code_ += " dst.copy_from_slice(src);"; @@ -2617,7 +2623,7 @@ class RustGenerator : public BaseGenerator { code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {"; code_ += " let src = unsafe {"; code_ += - " ::std::slice::from_raw_parts(" + " self::core::slice::from_raw_parts(" "*self as *const {{STRUCT_NAME}} as *const u8, Self::size())"; code_ += " };"; code_ += " dst.copy_from_slice(src);"; @@ -2718,7 +2724,7 @@ class RustGenerator : public BaseGenerator { NumToString(InlineSize(field.value.type))); code_ += "pub fn set_{{FIELD_NAME}}(&mut self, x: &{{FIELD_TYPE}}) {"; code_ += " unsafe {"; - code_ += " std::ptr::copy("; + code_ += " self::core::ptr::copy("; code_ += " x.as_ptr() as *const u8,"; code_ += " self.0.as_mut_ptr().add({{FIELD_OFFSET}}),"; code_ += " {{FIELD_SIZE}},"; @@ -2831,8 +2837,10 @@ class RustGenerator : public BaseGenerator { } } } - code_ += indent + "use std::mem;"; - code_ += indent + "use std::cmp::Ordering;"; + code_ += indent + "extern crate core;"; + code_ += ""; + code_ += indent + "use self::core::mem;"; + code_ += indent + "use self::core::cmp::Ordering;"; code_ += ""; code_ += indent + "extern crate flatbuffers;"; code_ += indent + "use self::flatbuffers::{EndianScalar, Follow};"; diff --git a/tests/GoTest.sh b/tests/GoTest.sh index 8cbadcb56f6..605e88689a3 100755 --- a/tests/GoTest.sh +++ b/tests/GoTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu # # Copyright 2014 Google Inc. All rights reserved. # diff --git a/tests/JavaTest.sh b/tests/JavaTest.sh index 099447e8bb6..8fe2a41859e 100755 --- a/tests/JavaTest.sh +++ b/tests/JavaTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2014 Google Inc. All rights reserved. # diff --git a/tests/LuaTest.sh b/tests/LuaTest.sh index d736a6b1ea2..a68dcecfed2 100755 --- a/tests/LuaTest.sh +++ b/tests/LuaTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu # # Copyright 2019 Google Inc. All rights reserved. # diff --git a/tests/PythonTest.sh b/tests/PythonTest.sh index b387ec1b2e0..4a6c48c042e 100755 --- a/tests/PythonTest.sh +++ b/tests/PythonTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash -eu +#!/usr/bin/env bash -eu # # Copyright 2014 Google Inc. All rights reserved. # diff --git a/tests/arrays_test/my_game/example/array_struct_generated.rs b/tests/arrays_test/my_game/example/array_struct_generated.rs index ded58e6e3f7..a98cf25b48f 100644 --- a/tests/arrays_test/my_game/example/array_struct_generated.rs +++ b/tests/arrays_test/my_game/example/array_struct_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct ArrayStruct, aligned to 8 @@ -13,8 +18,8 @@ impl Default for ArrayStruct { Self([0; 160]) } } -impl std::fmt::Debug for ArrayStruct { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for ArrayStruct { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("ArrayStruct") .field("a", &self.a()) .field("b", &self.b()) @@ -47,7 +52,7 @@ impl<'b> flatbuffers::Push for ArrayStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +63,7 @@ impl<'b> flatbuffers::Push for &'b ArrayStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -157,7 +162,7 @@ impl<'a> ArrayStruct { pub fn set_d(&mut self, x: &[NestedStruct; 2]) { unsafe { - std::ptr::copy( + self::core::ptr::copy( x.as_ptr() as *const u8, self.0.as_mut_ptr().add(72), 64, diff --git a/tests/arrays_test/my_game/example/array_table_generated.rs b/tests/arrays_test/my_game/example/array_table_generated.rs index 9a2fe7d03f0..ab96443625a 100644 --- a/tests/arrays_test/my_game/example/array_table_generated.rs +++ b/tests/arrays_test/my_game/example/array_table_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum ArrayTableOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> ArrayTableBuilder<'a, 'b> { } } -impl std::fmt::Debug for ArrayTable<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for ArrayTable<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("ArrayTable"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/arrays_test/my_game/example/nested_struct_generated.rs b/tests/arrays_test/my_game/example/nested_struct_generated.rs index 511c64aaf4c..a422fcf9242 100644 --- a/tests/arrays_test/my_game/example/nested_struct_generated.rs +++ b/tests/arrays_test/my_game/example/nested_struct_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct NestedStruct, aligned to 8 @@ -13,8 +18,8 @@ impl Default for NestedStruct { Self([0; 32]) } } -impl std::fmt::Debug for NestedStruct { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for NestedStruct { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("NestedStruct") .field("a", &self.a()) .field("b", &self.b()) @@ -45,7 +50,7 @@ impl<'b> flatbuffers::Push for NestedStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -56,7 +61,7 @@ impl<'b> flatbuffers::Push for &'b NestedStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -128,7 +133,7 @@ impl<'a> NestedStruct { pub fn set_c(&mut self, x: &[TestEnum; 2]) { unsafe { - std::ptr::copy( + self::core::ptr::copy( x.as_ptr() as *const u8, self.0.as_mut_ptr().add(9), 2, diff --git a/tests/arrays_test/my_game/example/test_enum_generated.rs b/tests/arrays_test/my_game/example/test_enum_generated.rs index 6dcc1cb970b..2523b35d191 100644 --- a/tests/arrays_test/my_game/example/test_enum_generated.rs +++ b/tests/arrays_test/my_game/example/test_enum_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl TestEnum { } } } -impl std::fmt::Debug for TestEnum { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for TestEnum { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/generate_code.sh b/tests/generate_code.sh index ccb262bb47f..b4ad29bb4bc 100755 --- a/tests/generate_code.sh +++ b/tests/generate_code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2021 Google Inc. All rights reserved. # diff --git a/tests/include_test1/my_game/other_name_space/from_include_generated.rs b/tests/include_test1/my_game/other_name_space/from_include_generated.rs index 048bafdb8d0..79d6bbf0aa0 100644 --- a/tests/include_test1/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test1/my_game/other_name_space/from_include_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -34,8 +39,8 @@ impl FromInclude { } } } -impl std::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for FromInclude { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/include_test1/my_game/other_name_space/table_b_generated.rs b/tests/include_test1/my_game/other_name_space/table_b_generated.rs index d7aee6407b1..4c17a745ec4 100644 --- a/tests/include_test1/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test1/my_game/other_name_space/table_b_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableBOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/include_test1/my_game/other_name_space/unused_generated.rs b/tests/include_test1/my_game/other_name_space/unused_generated.rs index f3fb099ff61..10aab3250c4 100644 --- a/tests/include_test1/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test1/my_game/other_name_space/unused_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 @@ -13,8 +18,8 @@ impl Default for Unused { Self([0; 4]) } } -impl std::fmt::Debug for Unused { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Unused { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -42,7 +47,7 @@ impl<'b> flatbuffers::Push for Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -53,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/include_test1/table_a_generated.rs b/tests/include_test1/table_a_generated.rs index 89c6a5fc80c..f128cc7104c 100644 --- a/tests/include_test1/table_a_generated.rs +++ b/tests/include_test1/table_a_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableAOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> { } } -impl std::fmt::Debug for TableA<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/include_test2/my_game/other_name_space/from_include_generated.rs b/tests/include_test2/my_game/other_name_space/from_include_generated.rs index 048bafdb8d0..79d6bbf0aa0 100644 --- a/tests/include_test2/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test2/my_game/other_name_space/from_include_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -34,8 +39,8 @@ impl FromInclude { } } } -impl std::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for FromInclude { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/include_test2/my_game/other_name_space/table_b_generated.rs b/tests/include_test2/my_game/other_name_space/table_b_generated.rs index d7aee6407b1..4c17a745ec4 100644 --- a/tests/include_test2/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test2/my_game/other_name_space/table_b_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableBOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/include_test2/my_game/other_name_space/unused_generated.rs b/tests/include_test2/my_game/other_name_space/unused_generated.rs index f3fb099ff61..10aab3250c4 100644 --- a/tests/include_test2/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test2/my_game/other_name_space/unused_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 @@ -13,8 +18,8 @@ impl Default for Unused { Self([0; 4]) } } -impl std::fmt::Debug for Unused { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Unused { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -42,7 +47,7 @@ impl<'b> flatbuffers::Push for Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -53,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/include_test2/table_a_generated.rs b/tests/include_test2/table_a_generated.rs index 89c6a5fc80c..f128cc7104c 100644 --- a/tests/include_test2/table_a_generated.rs +++ b/tests/include_test2/table_a_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableAOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> { } } -impl std::fmt::Debug for TableA<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/keyword_test/keyword_test/abc_generated.rs b/tests/keyword_test/keyword_test/abc_generated.rs index 99b43e46659..2ee30bed367 100644 --- a/tests/keyword_test/keyword_test/abc_generated.rs +++ b/tests/keyword_test/keyword_test/abc_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl ABC { } } } -impl std::fmt::Debug for ABC { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for ABC { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs index 17bcd0c097a..54ac9dfaabf 100644 --- a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum KeywordsInTableOffset {} @@ -130,8 +135,8 @@ impl<'a: 'b, 'b> KeywordsInTableBuilder<'a, 'b> { } } -impl std::fmt::Debug for KeywordsInTable<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for KeywordsInTable<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("KeywordsInTable"); ds.field("is", &self.is()); ds.field("private", &self.private()); diff --git a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs index cf03797f9d4..eee85d005fa 100644 --- a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl KeywordsInUnion { } } } -impl std::fmt::Debug for KeywordsInUnion { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for KeywordsInUnion { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -128,7 +133,7 @@ impl KeywordsInUnionT { /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_static_(&mut self) -> Option> { if let Self::Static_(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::Static_(w) = v { Some(w) } else { @@ -149,7 +154,7 @@ impl KeywordsInUnionT { /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_internal(&mut self) -> Option> { if let Self::Internal(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::Internal(w) = v { Some(w) } else { diff --git a/tests/keyword_test/keyword_test/public_generated.rs b/tests/keyword_test/keyword_test/public_generated.rs index 2de4c0b24e7..70dc3c88d8f 100644 --- a/tests/keyword_test/keyword_test/public_generated.rs +++ b/tests/keyword_test/keyword_test/public_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -34,8 +39,8 @@ impl public { } } } -impl std::fmt::Debug for public { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for public { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/monster_test/my_game/example/ability_generated.rs b/tests/monster_test/my_game/example/ability_generated.rs index 444e41b8f70..b8c5057d7ab 100644 --- a/tests/monster_test/my_game/example/ability_generated.rs +++ b/tests/monster_test/my_game/example/ability_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Ability, aligned to 4 @@ -13,8 +18,8 @@ impl Default for Ability { Self([0; 8]) } } -impl std::fmt::Debug for Ability { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Ability { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Ability") .field("id", &self.id()) .field("distance", &self.distance()) @@ -43,7 +48,7 @@ impl<'b> flatbuffers::Push for Ability { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Ability as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -54,7 +59,7 @@ impl<'b> flatbuffers::Push for &'b Ability { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -114,7 +119,7 @@ impl<'a> Ability { } #[inline] - pub fn key_compare_with_value(&self, val: u32) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u32) -> self::core::cmp::Ordering { let key = self.id(); key.cmp(&val) } diff --git a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs index 321007abe08..77145fc1d5f 100644 --- a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -46,8 +51,8 @@ impl AnyAmbiguousAliases { } } } -impl std::fmt::Debug for AnyAmbiguousAliases { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for AnyAmbiguousAliases { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -135,7 +140,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::M1(w) = v { Some(w) } else { @@ -156,7 +161,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::M2(w) = v { Some(w) } else { @@ -177,7 +182,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m3(&mut self) -> Option> { if let Self::M3(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::M3(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/any_generated.rs b/tests/monster_test/my_game/example/any_generated.rs index 6f7f6fdac49..a437cfe372f 100644 --- a/tests/monster_test/my_game/example/any_generated.rs +++ b/tests/monster_test/my_game/example/any_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -46,8 +51,8 @@ impl Any { } } } -impl std::fmt::Debug for Any { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Any { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -135,7 +140,7 @@ impl AnyT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::Monster(w) = v { Some(w) } else { @@ -156,7 +161,7 @@ impl AnyT { /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. pub fn take_test_simple_table_with_enum(&mut self) -> Option> { if let Self::TestSimpleTableWithEnum(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::TestSimpleTableWithEnum(w) = v { Some(w) } else { @@ -177,7 +182,7 @@ impl AnyT { /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. pub fn take_my_game_example_2_monster(&mut self) -> Option> { if let Self::MyGameExample2Monster(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::MyGameExample2Monster(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs index 1749d5d7a24..14ba17bff94 100644 --- a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -46,8 +51,8 @@ impl AnyUniqueAliases { } } } -impl std::fmt::Debug for AnyUniqueAliases { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for AnyUniqueAliases { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -135,7 +140,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::M(w) = v { Some(w) } else { @@ -156,7 +161,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. pub fn take_ts(&mut self) -> Option> { if let Self::TS(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::TS(w) = v { Some(w) } else { @@ -177,7 +182,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::M2(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/color_generated.rs b/tests/monster_test/my_game/example/color_generated.rs index 4a3282b4687..c4635b37c89 100644 --- a/tests/monster_test/my_game/example/color_generated.rs +++ b/tests/monster_test/my_game/example/color_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[allow(non_upper_case_globals)] diff --git a/tests/monster_test/my_game/example/monster_generated.rs b/tests/monster_test/my_game/example/monster_generated.rs index d30525fde94..7951f4c035d 100644 --- a/tests/monster_test/my_game/example/monster_generated.rs +++ b/tests/monster_test/my_game/example/monster_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum MonsterOffset {} @@ -365,7 +370,7 @@ impl<'a> Monster<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: & str) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: & str) -> self::core::cmp::Ordering { let key = self.name(); key.cmp(val) } @@ -1068,8 +1073,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("Monster"); ds.field("pos", &self.pos()); ds.field("mana", &self.mana()); diff --git a/tests/monster_test/my_game/example/race_generated.rs b/tests/monster_test/my_game/example/race_generated.rs index ab012f9bfaa..ced60232503 100644 --- a/tests/monster_test/my_game/example/race_generated.rs +++ b/tests/monster_test/my_game/example/race_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -46,8 +51,8 @@ impl Race { } } } -impl std::fmt::Debug for Race { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Race { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/monster_test/my_game/example/referrable_generated.rs b/tests/monster_test/my_game/example/referrable_generated.rs index b706f1d8c52..4ff479a4121 100644 --- a/tests/monster_test/my_game/example/referrable_generated.rs +++ b/tests/monster_test/my_game/example/referrable_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum ReferrableOffset {} @@ -57,7 +62,7 @@ impl<'a> Referrable<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: u64) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u64) -> self::core::cmp::Ordering { let key = self.id(); key.cmp(&val) } @@ -110,8 +115,8 @@ impl<'a: 'b, 'b> ReferrableBuilder<'a, 'b> { } } -impl std::fmt::Debug for Referrable<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for Referrable<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("Referrable"); ds.field("id", &self.id()); ds.finish() diff --git a/tests/monster_test/my_game/example/stat_generated.rs b/tests/monster_test/my_game/example/stat_generated.rs index 338c44396c0..ef6c7355aae 100644 --- a/tests/monster_test/my_game/example/stat_generated.rs +++ b/tests/monster_test/my_game/example/stat_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum StatOffset {} @@ -75,7 +80,7 @@ impl<'a> Stat<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: u16) -> ::std::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u16) -> self::core::cmp::Ordering { let key = self.count(); key.cmp(&val) } @@ -142,8 +147,8 @@ impl<'a: 'b, 'b> StatBuilder<'a, 'b> { } } -impl std::fmt::Debug for Stat<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for Stat<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("Stat"); ds.field("id", &self.id()); ds.field("val", &self.val()); diff --git a/tests/monster_test/my_game/example/struct_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_generated.rs index 47a1250581e..b1b0ea630fe 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructOfStructs, aligned to 4 @@ -13,8 +18,8 @@ impl Default for StructOfStructs { Self([0; 20]) } } -impl std::fmt::Debug for StructOfStructs { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for StructOfStructs { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("StructOfStructs") .field("a", &self.a()) .field("b", &self.b()) @@ -44,7 +49,7 @@ impl<'b> flatbuffers::Push for StructOfStructs { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -55,7 +60,7 @@ impl<'b> flatbuffers::Push for &'b StructOfStructs { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/monster_test/my_game/example/test_generated.rs b/tests/monster_test/my_game/example/test_generated.rs index 5308a520bf9..edfb70ab8d9 100644 --- a/tests/monster_test/my_game/example/test_generated.rs +++ b/tests/monster_test/my_game/example/test_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Test, aligned to 2 @@ -13,8 +18,8 @@ impl Default for Test { Self([0; 4]) } } -impl std::fmt::Debug for Test { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Test { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Test") .field("a", &self.a()) .field("b", &self.b()) @@ -43,7 +48,7 @@ impl<'b> flatbuffers::Push for Test { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Test as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -54,7 +59,7 @@ impl<'b> flatbuffers::Push for &'b Test { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs index 74014e74ac5..9188f7fc306 100644 --- a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs +++ b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TestSimpleTableWithEnumOffset {} @@ -100,8 +105,8 @@ impl<'a: 'b, 'b> TestSimpleTableWithEnumBuilder<'a, 'b> { } } -impl std::fmt::Debug for TestSimpleTableWithEnum<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TestSimpleTableWithEnum<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TestSimpleTableWithEnum"); ds.field("color", &self.color()); ds.finish() diff --git a/tests/monster_test/my_game/example/type_aliases_generated.rs b/tests/monster_test/my_game/example/type_aliases_generated.rs index aee59bdd1d2..a5dce0c5cb3 100644 --- a/tests/monster_test/my_game/example/type_aliases_generated.rs +++ b/tests/monster_test/my_game/example/type_aliases_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TypeAliasesOffset {} @@ -269,8 +274,8 @@ impl<'a: 'b, 'b> TypeAliasesBuilder<'a, 'b> { } } -impl std::fmt::Debug for TypeAliases<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TypeAliases<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TypeAliases"); ds.field("i8_", &self.i8_()); ds.field("u8_", &self.u8_()); diff --git a/tests/monster_test/my_game/example/vec_3_generated.rs b/tests/monster_test/my_game/example/vec_3_generated.rs index d4efb24eb48..d6a08b2b0c5 100644 --- a/tests/monster_test/my_game/example/vec_3_generated.rs +++ b/tests/monster_test/my_game/example/vec_3_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Vec3, aligned to 8 @@ -13,8 +18,8 @@ impl Default for Vec3 { Self([0; 32]) } } -impl std::fmt::Debug for Vec3 { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Vec3 { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Vec3") .field("x", &self.x()) .field("y", &self.y()) @@ -47,7 +52,7 @@ impl<'b> flatbuffers::Push for Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +63,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/monster_test/my_game/example_2/monster_generated.rs b/tests/monster_test/my_game/example_2/monster_generated.rs index b1defc42ae7..6133241d260 100644 --- a/tests/monster_test/my_game/example_2/monster_generated.rs +++ b/tests/monster_test/my_game/example_2/monster_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum MonsterOffset {} @@ -84,8 +89,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl std::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("Monster"); ds.finish() } diff --git a/tests/monster_test/my_game/in_parent_namespace_generated.rs b/tests/monster_test/my_game/in_parent_namespace_generated.rs index 84d25bf6177..7d0f9c34242 100644 --- a/tests/monster_test/my_game/in_parent_namespace_generated.rs +++ b/tests/monster_test/my_game/in_parent_namespace_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum InParentNamespaceOffset {} @@ -84,8 +89,8 @@ impl<'a: 'b, 'b> InParentNamespaceBuilder<'a, 'b> { } } -impl std::fmt::Debug for InParentNamespace<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for InParentNamespace<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("InParentNamespace"); ds.finish() } diff --git a/tests/monster_test/my_game/other_name_space/from_include_generated.rs b/tests/monster_test/my_game/other_name_space/from_include_generated.rs index 048bafdb8d0..79d6bbf0aa0 100644 --- a/tests/monster_test/my_game/other_name_space/from_include_generated.rs +++ b/tests/monster_test/my_game/other_name_space/from_include_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -34,8 +39,8 @@ impl FromInclude { } } } -impl std::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for FromInclude { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/monster_test/my_game/other_name_space/table_b_generated.rs b/tests/monster_test/my_game/other_name_space/table_b_generated.rs index d7aee6407b1..4c17a745ec4 100644 --- a/tests/monster_test/my_game/other_name_space/table_b_generated.rs +++ b/tests/monster_test/my_game/other_name_space/table_b_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableBOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/monster_test/my_game/other_name_space/unused_generated.rs b/tests/monster_test/my_game/other_name_space/unused_generated.rs index f3fb099ff61..10aab3250c4 100644 --- a/tests/monster_test/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test/my_game/other_name_space/unused_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct Unused, aligned to 4 @@ -13,8 +18,8 @@ impl Default for Unused { Self([0; 4]) } } -impl std::fmt::Debug for Unused { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for Unused { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -42,7 +47,7 @@ impl<'b> flatbuffers::Push for Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -53,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/monster_test/table_a_generated.rs b/tests/monster_test/table_a_generated.rs index 89c6a5fc80c..f128cc7104c 100644 --- a/tests/monster_test/table_a_generated.rs +++ b/tests/monster_test/table_a_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableAOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> { } } -impl std::fmt::Debug for TableA<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/more_defaults/abc_generated.rs b/tests/more_defaults/abc_generated.rs index 8622d9ba187..1520220c2bb 100644 --- a/tests/more_defaults/abc_generated.rs +++ b/tests/more_defaults/abc_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl ABC { } } } -impl std::fmt::Debug for ABC { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for ABC { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/more_defaults/more_defaults_generated.rs b/tests/more_defaults/more_defaults_generated.rs index 87f6ba36a83..d820465b19b 100644 --- a/tests/more_defaults/more_defaults_generated.rs +++ b/tests/more_defaults/more_defaults_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum MoreDefaultsOffset {} @@ -193,8 +198,8 @@ impl<'a: 'b, 'b> MoreDefaultsBuilder<'a, 'b> { } } -impl std::fmt::Debug for MoreDefaults<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for MoreDefaults<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("MoreDefaults"); ds.field("ints", &self.ints()); ds.field("floats", &self.floats()); diff --git a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs index b6366385a29..8a815e82e8d 100644 --- a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl EnumInNestedNS { } } } -impl std::fmt::Debug for EnumInNestedNS { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for EnumInNestedNS { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs index 0fbd86e05f6..39306136d62 100644 --- a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; // struct StructInNestedNS, aligned to 4 @@ -13,8 +18,8 @@ impl Default for StructInNestedNS { Self([0; 8]) } } -impl std::fmt::Debug for StructInNestedNS { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for StructInNestedNS { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { f.debug_struct("StructInNestedNS") .field("a", &self.a()) .field("b", &self.b()) @@ -43,7 +48,7 @@ impl<'b> flatbuffers::Push for StructInNestedNS { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size()) + self::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -54,7 +59,7 @@ impl<'b> flatbuffers::Push for &'b StructInNestedNS { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - ::std::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size()) + self::core::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size()) }; dst.copy_from_slice(src); } diff --git a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs index 575a855686d..1c1991a5e81 100644 --- a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableInNestedNSOffset {} @@ -100,8 +105,8 @@ impl<'a: 'b, 'b> TableInNestedNSBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableInNestedNS<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableInNestedNS<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableInNestedNS"); ds.field("foo", &self.foo()); ds.finish() diff --git a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs index 8d650a5139c..923812b8617 100644 --- a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -38,8 +43,8 @@ impl UnionInNestedNS { } } } -impl std::fmt::Debug for UnionInNestedNS { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for UnionInNestedNS { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -121,7 +126,7 @@ impl UnionInNestedNST { /// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE. pub fn take_table_in_nested_ns(&mut self) -> Option> { if let Self::TableInNestedNS(_) = self { - let v = std::mem::replace(self, Self::NONE); + let v = self::core::mem::replace(self, Self::NONE); if let Self::TableInNestedNS(w) = v { Some(w) } else { diff --git a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs index 385e8dd7c80..9de56d6928a 100644 --- a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs +++ b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum SecondTableInAOffset {} @@ -102,8 +107,8 @@ impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> { } } -impl std::fmt::Debug for SecondTableInA<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for SecondTableInA<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("SecondTableInA"); ds.field("refer_to_c", &self.refer_to_c()); ds.finish() diff --git a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs index 018e526a928..256d88595eb 100644 --- a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs +++ b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableInFirstNSOffset {} @@ -184,8 +189,8 @@ impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableInFirstNS<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableInFirstNS<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableInFirstNS"); ds.field("foo_table", &self.foo_table()); ds.field("foo_enum", &self.foo_enum()); diff --git a/tests/namespace_test/namespace_c/table_in_c_generated.rs b/tests/namespace_test/namespace_c/table_in_c_generated.rs index 5a1bdc9a683..0221bbf9e57 100644 --- a/tests/namespace_test/namespace_c/table_in_c_generated.rs +++ b/tests/namespace_test/namespace_c/table_in_c_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum TableInCOffset {} @@ -119,8 +124,8 @@ impl<'a: 'b, 'b> TableInCBuilder<'a, 'b> { } } -impl std::fmt::Debug for TableInC<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for TableInC<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("TableInC"); ds.field("refer_to_a1", &self.refer_to_a1()); ds.field("refer_to_a2", &self.refer_to_a2()); diff --git a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs index 226e9ecefd0..9c1c45b36fb 100644 --- a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs +++ b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] @@ -42,8 +47,8 @@ impl OptionalByte { } } } -impl std::fmt::Debug for OptionalByte { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl self::core::fmt::Debug for OptionalByte { + fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { diff --git a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs index 4b610f48763..65a01847228 100644 --- a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs +++ b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs @@ -1,7 +1,12 @@ // automatically generated by the FlatBuffers compiler, do not modify extern crate flatbuffers; -use std::mem; -use std::cmp::Ordering; +extern crate core; +extern crate alloc; +use self::alloc::vec::Vec; +use self::alloc::boxed::Box; +use self::alloc::string::{String, ToString as _}; +use self::core::mem; +use self::core::cmp::Ordering; use self::flatbuffers::{EndianScalar, Follow}; use super::*; pub enum ScalarStuffOffset {} @@ -625,8 +630,8 @@ impl<'a: 'b, 'b> ScalarStuffBuilder<'a, 'b> { } } -impl std::fmt::Debug for ScalarStuff<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl self::core::fmt::Debug for ScalarStuff<'_> { + fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { let mut ds = f.debug_struct("ScalarStuff"); ds.field("just_i8", &self.just_i8()); ds.field("maybe_i8", &self.maybe_i8()); diff --git a/tests/phpUnionVectorTest.sh b/tests/phpUnionVectorTest.sh index a6c3f264401..d40ac66687b 100755 --- a/tests/phpUnionVectorTest.sh +++ b/tests/phpUnionVectorTest.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e From 6e113692b844a307a3520d2c4e63b70b7a3a81cd Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Fri, 24 May 2019 16:46:18 -0400 Subject: [PATCH 3/6] Add no_std tests --- .../languages/Dockerfile.testing.rust.no_std | 7 +++ tests/rust_usage_test/tests/no_std_test.rs | 60 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 tests/docker/languages/Dockerfile.testing.rust.no_std create mode 100644 tests/rust_usage_test/tests/no_std_test.rs diff --git a/tests/docker/languages/Dockerfile.testing.rust.no_std b/tests/docker/languages/Dockerfile.testing.rust.no_std new file mode 100644 index 00000000000..05ce7513605 --- /dev/null +++ b/tests/docker/languages/Dockerfile.testing.rust.no_std @@ -0,0 +1,7 @@ +FROM rust +WORKDIR /code +ADD . . +WORKDIR /code/rust/flatbuffers +RUN rustup default nightly +RUN rustc --version +RUN cargo test --no-default-features diff --git a/tests/rust_usage_test/tests/no_std_test.rs b/tests/rust_usage_test/tests/no_std_test.rs new file mode 100644 index 00000000000..d1a270434d5 --- /dev/null +++ b/tests/rust_usage_test/tests/no_std_test.rs @@ -0,0 +1,60 @@ +#![no_std] + +extern crate flatbuffers; + +#[allow(dead_code, unused_imports)] +#[path = "../../monster_test/mod.rs"] +mod monster_test_generated; +pub use monster_test_generated::my_game; + +static MONSTER_DATA: &[u8] = include_bytes!("../../monsterdata_test.mon"); + +// Note: Copied from `bin/monster_example.rs` +#[test] +fn no_std_example_data() { + let monster = my_game::example::get_root_as_monster(MONSTER_DATA); + + assert_eq!(monster.hp(), 80); + assert_eq!(monster.mana(), 150); + assert_eq!(monster.name(), "MyMonster"); +} + +// Note: the rest was copied from the `roundtrip_generated_code` module in +// `tests/integration_test.rs`. Really just making sure that everything compiles +// here, the behavior has already been tested. + +fn build_mon<'a, 'b>( + builder: &'a mut flatbuffers::FlatBufferBuilder, + args: &'b my_game::example::MonsterArgs, +) -> my_game::example::Monster<'a> { + let mon = my_game::example::Monster::create(builder, &args); + my_game::example::finish_monster_buffer(builder, mon); + my_game::example::get_root_as_monster(builder.finished_data()) +} + +#[test] +fn vector_of_struct_store_with_type_inference() { + let mut b = flatbuffers::FlatBufferBuilder::new(); + let v = b.create_vector(&[ + my_game::example::Test::new(127, -128), + my_game::example::Test::new(3, 123), + my_game::example::Test::new(100, 101), + ]); + let name = b.create_string("foo"); + let m = build_mon( + &mut b, + &my_game::example::MonsterArgs { + name: Some(name), + test4: Some(v), + ..Default::default() + }, + ); + assert_eq!( + m.test4().unwrap(), + &[ + my_game::example::Test::new(127, -128), + my_game::example::Test::new(3, 123), + my_game::example::Test::new(100, 101) + ][..] + ); +} \ No newline at end of file From 6754d5a5c17ee16f62797a0a66c7c4995c9d58a0 Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Tue, 19 Oct 2021 07:53:15 -0400 Subject: [PATCH 4/6] rust/flatbuffers: Fix lingering references to std This includes making thiserror optional. Additionally, tests are now run both with and without default features, which will ensure that the runtime continues to build/run without std support. --- rust/flatbuffers/Cargo.toml | 4 +- rust/flatbuffers/src/array.rs | 6 +- rust/flatbuffers/src/builder.rs | 2 - rust/flatbuffers/src/lib.rs | 6 +- rust/flatbuffers/src/vector.rs | 12 ++-- rust/flatbuffers/src/verifier.rs | 79 ++++++++++++++-------- tests/RustTest.bat | 1 + tests/RustTest.sh | 5 +- tests/rust_usage_test/Cargo.toml | 6 +- tests/rust_usage_test/tests/no_std_test.rs | 2 +- 10 files changed, 74 insertions(+), 49 deletions(-) diff --git a/rust/flatbuffers/Cargo.toml b/rust/flatbuffers/Cargo.toml index f436b4425e5..00e505bf839 100644 --- a/rust/flatbuffers/Cargo.toml +++ b/rust/flatbuffers/Cargo.toml @@ -14,8 +14,8 @@ rust = "1.51" [dependencies] smallvec = "1.6.1" bitflags = "1.2.1" -thiserror = "1.0.23" +thiserror = { version = "1.0.23", optional = true } [features] default = ["std"] -std = [] +std = ["thiserror"] diff --git a/rust/flatbuffers/src/array.rs b/rust/flatbuffers/src/array.rs index f00a56036a2..3765a5fcf40 100644 --- a/rust/flatbuffers/src/array.rs +++ b/rust/flatbuffers/src/array.rs @@ -17,9 +17,9 @@ use crate::follow::Follow; use crate::vector::VectorIter; use crate::EndianScalar; -use std::fmt::{Debug, Formatter, Result}; -use std::marker::PhantomData; -use std::mem::size_of; +use core::fmt::{Debug, Formatter, Result}; +use core::marker::PhantomData; +use core::mem::size_of; #[derive(Copy, Clone)] pub struct Array<'a, T: 'a, const N: usize>(&'a [u8], PhantomData); diff --git a/rust/flatbuffers/src/builder.rs b/rust/flatbuffers/src/builder.rs index aed94fad45c..e931eff651e 100644 --- a/rust/flatbuffers/src/builder.rs +++ b/rust/flatbuffers/src/builder.rs @@ -16,9 +16,7 @@ extern crate smallvec; -#[cfg(not(feature = "std"))] use alloc::{vec, vec::Vec}; - use core::cmp::max; use core::iter::{DoubleEndedIterator, ExactSizeIterator}; use core::marker::PhantomData; diff --git a/rust/flatbuffers/src/lib.rs b/rust/flatbuffers/src/lib.rs index 58d81c668e6..a3e3b4470be 100644 --- a/rust/flatbuffers/src/lib.rs +++ b/rust/flatbuffers/src/lib.rs @@ -28,12 +28,12 @@ //! At this time, to generate Rust code, you will need the latest `master` version of `flatc`, available from here: //! (On OSX, you can install FlatBuffers from `HEAD` with the Homebrew package manager.) -#![cfg_attr(not(feature = "std"), no_std)] +#![no_std] +// Needed for thiserror #[cfg(feature = "std")] -extern crate core; +extern crate std; -#[cfg(not(feature = "std"))] extern crate alloc; mod array; diff --git a/rust/flatbuffers/src/vector.rs b/rust/flatbuffers/src/vector.rs index fe46c503691..9237df1fa6b 100644 --- a/rust/flatbuffers/src/vector.rs +++ b/rust/flatbuffers/src/vector.rs @@ -14,12 +14,12 @@ * limitations under the License. */ -use std::fmt::{Debug, Formatter, Result}; -use std::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator}; -use std::marker::PhantomData; -use std::mem::size_of; -use std::slice::from_raw_parts; -use std::str::from_utf8_unchecked; +use core::fmt::{Debug, Formatter, Result}; +use core::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator}; +use core::marker::PhantomData; +use core::mem::size_of; +use core::slice::from_raw_parts; +use core::str::from_utf8_unchecked; use crate::endian_scalar::read_scalar_at; #[cfg(target_endian = "little")] diff --git a/rust/flatbuffers/src/verifier.rs b/rust/flatbuffers/src/verifier.rs index 12a02f96503..0e8cb27db88 100644 --- a/rust/flatbuffers/src/verifier.rs +++ b/rust/flatbuffers/src/verifier.rs @@ -1,6 +1,9 @@ use crate::follow::Follow; use crate::{ForwardsUOffset, SOffsetT, SkipSizePrefix, UOffsetT, VOffsetT, Vector, SIZE_UOFFSET}; -use std::ops::Range; +use alloc::vec::Vec; +use core::ops::Range; + +#[cfg(feature = "std")] use thiserror::Error; /// Traces the location of data errors. Not populated for Dos detecting errors. @@ -23,7 +26,7 @@ pub enum ErrorTraceDetail { } #[derive(PartialEq, Eq, Default, Debug, Clone)] pub struct ErrorTrace(Vec); -impl std::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace { +impl core::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace { #[inline] fn as_ref(&self) -> &[ErrorTraceDetail] { &self.0 @@ -32,49 +35,65 @@ impl std::convert::AsRef<[ErrorTraceDetail]> for ErrorTrace { /// Describes how a flatuffer is invalid and, for data errors, roughly where. No extra tracing /// information is given for DoS detecting errors since it will probably be a lot. -#[derive(Clone, Error, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Error))] pub enum InvalidFlatbuffer { - #[error("Missing required field `{required}`.\n{error_trace}")] + #[cfg_attr( + feature = "std", + error("Missing required field `{required}`.\n{error_trace}") + )] MissingRequiredField { required: &'static str, error_trace: ErrorTrace, }, - #[error( - "Union exactly one of union discriminant (`{field_type}`) and value \ + #[cfg_attr( + feature = "std", + error( + "Union exactly one of union discriminant (`{field_type}`) and value \ (`{field}`) are present.\n{error_trace}" + ) )] InconsistentUnion { field: &'static str, field_type: &'static str, error_trace: ErrorTrace, }, - #[error("Utf8 error for string in {range:?}: {error}\n{error_trace}")] + #[cfg_attr( + feature = "std", + error("Utf8 error for string in {range:?}: {error}\n{error_trace}") + )] Utf8Error { - #[source] - error: std::str::Utf8Error, + #[cfg_attr(feature = "std", source)] + error: core::str::Utf8Error, range: Range, error_trace: ErrorTrace, }, - #[error("String in range [{}, {}) is missing its null terminator.\n{error_trace}", - range.start, range.end)] + #[cfg_attr(feature = "std", error("String in range [{}, {}) is missing its null terminator.\n{error_trace}", + range.start, range.end))] MissingNullTerminator { range: Range, error_trace: ErrorTrace, }, - #[error("Type `{unaligned_type}` at position {position} is unaligned.\n{error_trace}")] + #[cfg_attr( + feature = "std", + error("Type `{unaligned_type}` at position {position} is unaligned.\n{error_trace}") + )] Unaligned { position: usize, unaligned_type: &'static str, error_trace: ErrorTrace, }, - #[error("Range [{}, {}) is out of bounds.\n{error_trace}", range.start, range.end)] + #[cfg_attr(feature = "std", error("Range [{}, {}) is out of bounds.\n{error_trace}", range.start, range.end))] RangeOutOfBounds { range: Range, error_trace: ErrorTrace, }, - #[error( - "Signed offset at position {position} has value {soffset} which points out of bounds.\ + #[cfg_attr( + feature = "std", + error( + "Signed offset at position {position} has value {soffset} which points out of bounds.\ \n{error_trace}" + ) )] SignedOffsetOutOfBounds { soffset: SOffsetT, @@ -82,16 +101,16 @@ pub enum InvalidFlatbuffer { error_trace: ErrorTrace, }, // Dos detecting errors. These do not get error traces since it will probably be very large. - #[error("Too many tables.")] + #[cfg_attr(feature = "std", error("Too many tables."))] TooManyTables, - #[error("Apparent size too large.")] + #[cfg_attr(feature = "std", error("Apparent size too large."))] ApparentSizeTooLarge, - #[error("Nested table depth limit reached.")] + #[cfg_attr(feature = "std", error("Nested table depth limit reached."))] DepthLimitReached, } -impl std::fmt::Display for ErrorTrace { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { +impl core::fmt::Display for ErrorTrace { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { use ErrorTraceDetail::*; for e in self.0.iter() { match e { @@ -125,7 +144,7 @@ impl std::fmt::Display for ErrorTrace { } } -pub type Result = std::prelude::v1::Result; +pub type Result = core::prelude::v1::Result; impl InvalidFlatbuffer { fn new_range_oob(start: usize, end: usize) -> Result { @@ -245,11 +264,11 @@ impl<'opts, 'buf> Verifier<'opts, 'buf> { /// `buffer[0]`. TODO(caspern). #[inline] fn is_aligned(&self, pos: usize) -> Result<()> { - if pos % std::mem::align_of::() == 0 { + if pos % core::mem::align_of::() == 0 { Ok(()) } else { Err(InvalidFlatbuffer::Unaligned { - unaligned_type: std::any::type_name::(), + unaligned_type: core::any::type_name::(), position: pos, error_trace: Default::default(), }) @@ -271,7 +290,7 @@ impl<'opts, 'buf> Verifier<'opts, 'buf> { #[inline] pub fn in_buffer(&mut self, pos: usize) -> Result<()> { self.is_aligned::(pos)?; - self.range_in_buffer(pos, std::mem::size_of::()) + self.range_in_buffer(pos, core::mem::size_of::()) } #[inline] fn get_u16(&mut self, pos: usize) -> Result { @@ -416,7 +435,7 @@ impl<'ver, 'opts, 'buf> TableVerifier<'ver, 'opts, 'buf> { where Key: Follow<'buf> + Verifiable, UnionVerifier: - (std::ops::FnOnce(>::Inner, &mut Verifier, usize) -> Result<()>), + (core::ops::FnOnce(>::Inner, &mut Verifier, usize) -> Result<()>), // NOTE: >::Inner == Key { // TODO(caspern): how to trace vtable errors? @@ -468,14 +487,14 @@ impl Verifiable for ForwardsUOffset { } /// Checks and returns the range containing the flatbuffers vector. -fn verify_vector_range(v: &mut Verifier, pos: usize) -> Result> { +fn verify_vector_range(v: &mut Verifier, pos: usize) -> Result> { let len = v.get_uoffset(pos)? as usize; let start = pos.saturating_add(SIZE_UOFFSET); v.is_aligned::(start)?; - let size = len.saturating_mul(std::mem::size_of::()); + let size = len.saturating_mul(core::mem::size_of::()); let end = start.saturating_add(size); v.range_in_buffer(start, size)?; - Ok(std::ops::Range { start, end }) + Ok(core::ops::Range { start, end }) } pub trait SimpleToVerifyInSlice {} @@ -509,7 +528,7 @@ impl Verifiable for Vector<'_, ForwardsUOffset> { #[inline] fn run_verifier(v: &mut Verifier, pos: usize) -> Result<()> { let range = verify_vector_range::>(v, pos)?; - let size = std::mem::size_of::>(); + let size = core::mem::size_of::>(); for (i, element_pos) in range.step_by(size).enumerate() { trace_elem( >::run_verifier(v, element_pos), @@ -526,7 +545,7 @@ impl<'a> Verifiable for &'a str { fn run_verifier(v: &mut Verifier, pos: usize) -> Result<()> { let range = verify_vector_range::(v, pos)?; let has_null_terminator = v.buffer.get(range.end).map(|&b| b == 0).unwrap_or(false); - let s = std::str::from_utf8(&v.buffer[range.clone()]); + let s = core::str::from_utf8(&v.buffer[range.clone()]); if let Err(error) = s { return Err(InvalidFlatbuffer::Utf8Error { error, diff --git a/tests/RustTest.bat b/tests/RustTest.bat index 1473ffbed25..d2bcca7a64e 100644 --- a/tests/RustTest.bat +++ b/tests/RustTest.bat @@ -18,6 +18,7 @@ rem Compile then run the Rust test. rem TODO(rw): how do we make this script abort the calling script in appveyor? cd rust_usage_test +cargo test --no-default-features -- --quiet || exit /b 1 cargo test -- --quiet || exit /b 1 cargo run --bin=flatbuffers_alloc_check || exit /b 1 cargo run --bin=flexbuffers_alloc_check || exit /b 1 diff --git a/tests/RustTest.sh b/tests/RustTest.sh index 7a7894ad64d..ec4c196fdf6 100755 --- a/tests/RustTest.sh +++ b/tests/RustTest.sh @@ -32,10 +32,13 @@ function check_test_result() { } cd ./rust_usage_test + +cargo test $TARGET_FLAG --no-default-features -- --quiet +check_test_result "Rust tests without default features" + cargo test $TARGET_FLAG -- --quiet check_test_result "Rust tests" - cargo run $TARGET_FLAG --bin=flatbuffers_alloc_check check_test_result "Rust flatbuffers heap alloc test" diff --git a/tests/rust_usage_test/Cargo.toml b/tests/rust_usage_test/Cargo.toml index 22b259084eb..9a09ab94bb4 100644 --- a/tests/rust_usage_test/Cargo.toml +++ b/tests/rust_usage_test/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Robert Winslow ", "FlatBuffers Maintainers"] [dependencies] -flatbuffers = { path = "../../rust/flatbuffers" } +flatbuffers = { path = "../../rust/flatbuffers", default_features = false } flexbuffers = { path = "../../rust/flexbuffers" } serde_derive = "1.0" serde = "1.0" @@ -49,3 +49,7 @@ array-init = "2.0" # setup for bencher name = "benchmarks" harness = false + +[features] +default = ["std"] +std = ["flatbuffers/std"] diff --git a/tests/rust_usage_test/tests/no_std_test.rs b/tests/rust_usage_test/tests/no_std_test.rs index d1a270434d5..fc15663c9da 100644 --- a/tests/rust_usage_test/tests/no_std_test.rs +++ b/tests/rust_usage_test/tests/no_std_test.rs @@ -57,4 +57,4 @@ fn vector_of_struct_store_with_type_inference() { my_game::example::Test::new(100, 101) ][..] ); -} \ No newline at end of file +} From 3f83fccfbfc0a496ca1d821ca16f58b77270276c Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Tue, 19 Oct 2021 08:37:56 -0400 Subject: [PATCH 5/6] rust/flatbuffers: Clean up imports --- .../my_game/sample/color_generated.rs | 17 ++-- .../my_game/sample/equipment_generated.rs | 19 ++-- .../my_game/sample/monster_generated.rs | 17 ++-- .../my_game/sample/vec_3_generated.rs | 63 ++++++------- .../my_game/sample/weapon_generated.rs | 17 ++-- src/idl_gen_rust.cpp | 68 ++++++-------- .../my_game/example/array_struct_generated.rs | 65 +++++++------ .../my_game/example/array_table_generated.rs | 17 ++-- .../example/nested_struct_generated.rs | 37 ++++---- .../my_game/example/test_enum_generated.rs | 17 ++-- .../from_include_generated.rs | 17 ++-- .../other_name_space/table_b_generated.rs | 17 ++-- .../other_name_space/unused_generated.rs | 35 ++++--- tests/include_test1/table_a_generated.rs | 17 ++-- .../from_include_generated.rs | 17 ++-- .../other_name_space/table_b_generated.rs | 17 ++-- .../other_name_space/unused_generated.rs | 35 ++++--- tests/include_test2/table_a_generated.rs | 17 ++-- .../keyword_test/abc_generated.rs | 17 ++-- .../keywords_in_table_generated.rs | 17 ++-- .../keywords_in_union_generated.rs | 21 ++--- .../keyword_test/public_generated.rs | 17 ++-- .../my_game/example/ability_generated.rs | 51 +++++------ .../any_ambiguous_aliases_generated.rs | 23 ++--- .../my_game/example/any_generated.rs | 23 ++--- .../example/any_unique_aliases_generated.rs | 23 ++--- .../my_game/example/color_generated.rs | 13 +-- .../my_game/example/monster_generated.rs | 21 ++--- .../my_game/example/race_generated.rs | 17 ++-- .../my_game/example/referrable_generated.rs | 19 ++-- .../my_game/example/stat_generated.rs | 19 ++-- .../example/struct_of_structs_generated.rs | 21 ++--- .../my_game/example/test_generated.rs | 49 +++++----- .../test_simple_table_with_enum_generated.rs | 17 ++-- .../my_game/example/type_aliases_generated.rs | 17 ++-- .../my_game/example/vec_3_generated.rs | 91 +++++++++---------- .../my_game/example_2/monster_generated.rs | 17 ++-- .../my_game/in_parent_namespace_generated.rs | 17 ++-- .../from_include_generated.rs | 17 ++-- .../other_name_space/table_b_generated.rs | 17 ++-- .../other_name_space/unused_generated.rs | 35 ++++--- tests/monster_test/table_a_generated.rs | 17 ++-- tests/more_defaults/abc_generated.rs | 17 ++-- .../more_defaults/more_defaults_generated.rs | 17 ++-- .../enum_in_nested_ns_generated.rs | 17 ++-- .../struct_in_nested_ns_generated.rs | 49 +++++----- .../table_in_nested_ns_generated.rs | 17 ++-- .../union_in_nested_ns_generated.rs | 19 ++-- .../second_table_in_a_generated.rs | 17 ++-- .../table_in_first_ns_generated.rs | 17 ++-- .../namespace_c/table_in_c_generated.rs | 17 ++-- .../optional_byte_generated.rs | 17 ++-- .../scalar_stuff_generated.rs | 17 ++-- 53 files changed, 578 insertions(+), 748 deletions(-) diff --git a/samples/rust_generated/my_game/sample/color_generated.rs b/samples/rust_generated/my_game/sample/color_generated.rs index 595eb297b7a..18a050834d2 100644 --- a/samples/rust_generated/my_game/sample/color_generated.rs +++ b/samples/rust_generated/my_game/sample/color_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[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; @@ -47,8 +45,8 @@ impl Color { } } } -impl self::core::fmt::Debug for Color { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Color { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for Color { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/samples/rust_generated/my_game/sample/equipment_generated.rs b/samples/rust_generated/my_game/sample/equipment_generated.rs index 8ef42ce2f95..3d1176e469a 100644 --- a/samples/rust_generated/my_game/sample/equipment_generated.rs +++ b/samples/rust_generated/my_game/sample/equipment_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[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; @@ -43,8 +41,8 @@ impl Equipment { } } } -impl self::core::fmt::Debug for Equipment { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Equipment { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -90,7 +88,6 @@ impl<'a> flatbuffers::Verifiable for Equipment { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -126,7 +123,7 @@ impl EquipmentT { /// If the union variant matches, return the owned WeaponT, setting the union to NONE. pub fn take_weapon(&mut self) -> Option> { if let Self::Weapon(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Weapon(w) = v { Some(w) } else { diff --git a/samples/rust_generated/my_game/sample/monster_generated.rs b/samples/rust_generated/my_game/sample/monster_generated.rs index 4a197a3c38d..2cbc1678bcf 100644 --- a/samples/rust_generated/my_game/sample/monster_generated.rs +++ b/samples/rust_generated/my_game/sample/monster_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -161,7 +159,6 @@ impl flatbuffers::Verifiable for Monster<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("pos", Self::VT_POS, false)? .visit_field::("mana", Self::VT_MANA, false)? @@ -270,8 +267,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Monster"); ds.field("pos", &self.pos()); ds.field("mana", &self.mana()); diff --git a/samples/rust_generated/my_game/sample/vec_3_generated.rs b/samples/rust_generated/my_game/sample/vec_3_generated.rs index 0957ff3931f..22e40cbae88 100644 --- a/samples/rust_generated/my_game/sample/vec_3_generated.rs +++ b/samples/rust_generated/my_game/sample/vec_3_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Vec3, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Vec3 { Self([0; 12]) } } -impl self::core::fmt::Debug for Vec3 { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Vec3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Vec3") .field("x", &self.x()) .field("y", &self.y()) @@ -49,7 +47,7 @@ impl<'b> flatbuffers::Push for Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -60,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -71,7 +69,6 @@ impl<'a> flatbuffers::Verifiable for Vec3 { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -94,70 +91,70 @@ impl<'a> Vec3 { } pub fn x(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_x(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn y(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_y(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn z(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[8..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_z(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/samples/rust_generated/my_game/sample/weapon_generated.rs b/samples/rust_generated/my_game/sample/weapon_generated.rs index aaf56a8d559..7fb946cf328 100644 --- a/samples/rust_generated/my_game/sample/weapon_generated.rs +++ b/samples/rust_generated/my_game/sample/weapon_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum WeaponOffset {} #[derive(Copy, Clone, PartialEq)] @@ -73,7 +71,6 @@ impl flatbuffers::Verifiable for Weapon<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("name", Self::VT_NAME, false)? .visit_field::("damage", Self::VT_DAMAGE, false)? @@ -122,8 +119,8 @@ impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for Weapon<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for Weapon<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Weapon"); ds.field("name", &self.name()); ds.field("damage", &self.damage()); diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index 6c8e43b3aee..2e5d6f722c7 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -382,15 +382,13 @@ class RustGenerator : public BaseGenerator { if (symbol.generated) continue; code_.Clear(); code_ += "// " + std::string(FlatBuffersGeneratedWarning()); - code_ += "extern crate flatbuffers;"; - code_ += "extern crate core;"; code_ += "extern crate alloc;"; - code_ += "use self::alloc::vec::Vec;"; - code_ += "use self::alloc::boxed::Box;"; + code_ += "extern crate core;"; + code_ += "extern crate flatbuffers;"; + code_ += "use self::alloc::{boxed::Box, vec::Vec};"; code_ += "use self::alloc::string::{String, ToString as _};"; - code_ += "use self::core::mem;"; - code_ += "use self::core::cmp::Ordering;"; - code_ += "use self::flatbuffers::{EndianScalar, Follow};"; + code_ += "use self::core::{cmp::Ordering, fmt, mem, ptr, slice};"; + code_ += "use self::flatbuffers::{EndianScalar, Follow, Verifiable};"; code_ += "use super::*;"; cur_name_space_ = symbol.defined_namespace; gen_symbol(symbol); @@ -832,10 +830,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; // Generate Debug. Unknown variants are printed like "". - code_ += "impl self::core::fmt::Debug for {{ENUM_NAME}} {"; + code_ += "impl fmt::Debug for {{ENUM_NAME}} {"; code_ += - " fn fmt(&self, f: &mut self::core::fmt::Formatter) ->" - " self::core::fmt::Result {"; + " fn fmt(&self, f: &mut fmt::Formatter) ->" + " fmt::Result {"; code_ += " if let Some(name) = self.variant_name() {"; code_ += " f.write_str(name)"; code_ += " } else {"; @@ -891,7 +889,6 @@ class RustGenerator : public BaseGenerator { 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)"; code_ += " }"; code_ += "}"; @@ -987,7 +984,7 @@ class RustGenerator : public BaseGenerator { "pub fn take_{{U_ELEMENT_NAME}}(&mut self) -> " "Option> {"; code_ += " if let Self::{{NATIVE_VARIANT}}(_) = self {"; - code_ += " let v = self::core::mem::replace(self, Self::NONE);"; + code_ += " let v = mem::replace(self, Self::NONE);"; code_ += " if let Self::{{NATIVE_VARIANT}}(w) = v {"; code_ += " Some(w)"; code_ += " } else {"; @@ -1875,14 +1872,12 @@ class RustGenerator : public BaseGenerator { if (field.IsRequired()) { code_ += "{{NESTED}}<'a> {"; code_ += " let data = self.{{FIELD_NAME}}();"; - code_ += " use flatbuffers::Follow;"; code_ += " >>" "::follow(data, 0)"; } else { code_ += "Option<{{NESTED}}<'a>> {"; code_ += " self.{{FIELD_NAME}}().map(|data| {"; - code_ += " use flatbuffers::Follow;"; code_ += " >>" "::follow(data, 0)"; @@ -1943,7 +1938,6 @@ class RustGenerator : public BaseGenerator { 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)?\\"; // Escape newline and insert it onthe next line so we can end the builder // with a nice semicolon. @@ -2084,10 +2078,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; code_ += ""; - code_ += "impl self::core::fmt::Debug for {{STRUCT_NAME}}<'_> {"; + code_ += "impl fmt::Debug for {{STRUCT_NAME}}<'_> {"; code_ += - " fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>" - ") -> self::core::fmt::Result {"; + " fn fmt(&self, f: &mut fmt::Formatter<'_>" + ") -> fmt::Result {"; code_ += " let mut ds = f.debug_struct(\"{{STRUCT_NAME}}\");"; ForAllTableFields(struct_def, [&](const FieldDef &field) { if (GetFullType(field.value.type) == ftUnionValue) { @@ -2308,7 +2302,7 @@ class RustGenerator : public BaseGenerator { code_ += "#[inline]"; code_ += "pub fn key_compare_with_value(&self, val: {{KEY_TYPE}}) -> " - " self::core::cmp::Ordering {"; + " Ordering {"; code_ += " let key = self.{{FIELD_NAME}}();"; code_ += " key.cmp({{REF}}val)"; code_ += "}"; @@ -2571,10 +2565,10 @@ class RustGenerator : public BaseGenerator { code_ += "}"; // Debug for structs. - code_ += "impl self::core::fmt::Debug for {{STRUCT_NAME}} {"; + code_ += "impl fmt::Debug for {{STRUCT_NAME}} {"; code_ += - " fn fmt(&self, f: &mut self::core::fmt::Formatter" - ") -> self::core::fmt::Result {"; + " fn fmt(&self, f: &mut fmt::Formatter" + ") -> fmt::Result {"; code_ += " f.debug_struct(\"{{STRUCT_NAME}}\")"; ForAllStructFields(struct_def, [&](const FieldDef &unused) { (void)unused; @@ -2610,7 +2604,7 @@ class RustGenerator : public BaseGenerator { code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {"; code_ += " let src = unsafe {"; code_ += - " self::core::slice::from_raw_parts(" + " slice::from_raw_parts(" "self as *const {{STRUCT_NAME}} as *const u8, Self::size())"; code_ += " };"; code_ += " dst.copy_from_slice(src);"; @@ -2623,7 +2617,7 @@ class RustGenerator : public BaseGenerator { code_ += " fn push(&self, dst: &mut [u8], _rest: &[u8]) {"; code_ += " let src = unsafe {"; code_ += - " self::core::slice::from_raw_parts(" + " slice::from_raw_parts(" "*self as *const {{STRUCT_NAME}} as *const u8, Self::size())"; code_ += " };"; code_ += " dst.copy_from_slice(src);"; @@ -2638,7 +2632,6 @@ class RustGenerator : public BaseGenerator { code_ += " fn run_verifier("; code_ += " v: &mut flatbuffers::Verifier, pos: usize"; code_ += " ) -> Result<(), flatbuffers::InvalidFlatbuffer> {"; - code_ += " use self::flatbuffers::Verifiable;"; code_ += " v.in_buffer::(pos)"; code_ += " }"; code_ += "}"; @@ -2686,15 +2679,15 @@ class RustGenerator : public BaseGenerator { } else { code_ += "pub fn {{FIELD_NAME}}(&self) -> {{FIELD_TYPE}} {"; code_ += - " let mut mem = core::mem::MaybeUninit::" + " let mut uninit = mem::MaybeUninit::" "<{{FIELD_TYPE}}>::uninit();"; code_ += " unsafe {"; - code_ += " core::ptr::copy_nonoverlapping("; + code_ += " ptr::copy_nonoverlapping("; code_ += " self.0[{{FIELD_OFFSET}}..].as_ptr(),"; - code_ += " mem.as_mut_ptr() as *mut u8,"; - code_ += " core::mem::size_of::<{{FIELD_TYPE}}>(),"; + code_ += " uninit.as_mut_ptr() as *mut u8,"; + code_ += " mem::size_of::<{{FIELD_TYPE}}>(),"; code_ += " );"; - code_ += " mem.assume_init()"; + code_ += " uninit.assume_init()"; code_ += " }.from_little_endian()"; } code_ += "}\n"; @@ -2724,7 +2717,7 @@ class RustGenerator : public BaseGenerator { NumToString(InlineSize(field.value.type))); code_ += "pub fn set_{{FIELD_NAME}}(&mut self, x: &{{FIELD_TYPE}}) {"; code_ += " unsafe {"; - code_ += " self::core::ptr::copy("; + code_ += " ptr::copy("; code_ += " x.as_ptr() as *const u8,"; code_ += " self.0.as_mut_ptr().add({{FIELD_OFFSET}}),"; code_ += " {{FIELD_SIZE}},"; @@ -2735,10 +2728,10 @@ class RustGenerator : public BaseGenerator { code_ += "pub fn set_{{FIELD_NAME}}(&mut self, x: {{FIELD_TYPE}}) {"; code_ += " let x_le = x.to_little_endian();"; code_ += " unsafe {"; - code_ += " core::ptr::copy_nonoverlapping("; + code_ += " ptr::copy_nonoverlapping("; code_ += " &x_le as *const {{FIELD_TYPE}} as *const u8,"; code_ += " self.0[{{FIELD_OFFSET}}..].as_mut_ptr(),"; - code_ += " core::mem::size_of::<{{FIELD_TYPE}}>(),"; + code_ += " mem::size_of::<{{FIELD_TYPE}}>(),"; code_ += " );"; code_ += " }"; } @@ -2837,13 +2830,8 @@ class RustGenerator : public BaseGenerator { } } } - code_ += indent + "extern crate core;"; - code_ += ""; - code_ += indent + "use self::core::mem;"; - code_ += indent + "use self::core::cmp::Ordering;"; - code_ += ""; - code_ += indent + "extern crate flatbuffers;"; - code_ += indent + "use self::flatbuffers::{EndianScalar, Follow};"; + code_ += indent + "use core::{cmp::Ordering, mem};"; + code_ += indent + "use flatbuffers::{EndianScalar, Follow};"; } // Set up the correct namespace. This opens a namespace if the current diff --git a/tests/arrays_test/my_game/example/array_struct_generated.rs b/tests/arrays_test/my_game/example/array_struct_generated.rs index a98cf25b48f..868a4913b91 100644 --- a/tests/arrays_test/my_game/example/array_struct_generated.rs +++ b/tests/arrays_test/my_game/example/array_struct_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct ArrayStruct, aligned to 8 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for ArrayStruct { Self([0; 160]) } } -impl self::core::fmt::Debug for ArrayStruct { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for ArrayStruct { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("ArrayStruct") .field("a", &self.a()) .field("b", &self.b()) @@ -52,7 +50,7 @@ impl<'b> flatbuffers::Push for ArrayStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size()) + slice::from_raw_parts(self as *const ArrayStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -63,7 +61,7 @@ impl<'b> flatbuffers::Push for &'b ArrayStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size()) + slice::from_raw_parts(*self as *const ArrayStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -74,7 +72,6 @@ impl<'a> flatbuffers::Verifiable for ArrayStruct { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -103,24 +100,24 @@ impl<'a> ArrayStruct { } pub fn a(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -134,24 +131,24 @@ impl<'a> ArrayStruct { } pub fn c(&self) -> i8 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[64..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_c(&mut self, x: i8) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i8 as *const u8, self.0[64..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -162,7 +159,7 @@ impl<'a> ArrayStruct { pub fn set_d(&mut self, x: &[NestedStruct; 2]) { unsafe { - self::core::ptr::copy( + ptr::copy( x.as_ptr() as *const u8, self.0.as_mut_ptr().add(72), 64, @@ -171,24 +168,24 @@ impl<'a> ArrayStruct { } pub fn e(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[136..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_e(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[136..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/arrays_test/my_game/example/array_table_generated.rs b/tests/arrays_test/my_game/example/array_table_generated.rs index ab96443625a..79e3d89b32f 100644 --- a/tests/arrays_test/my_game/example/array_table_generated.rs +++ b/tests/arrays_test/my_game/example/array_table_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum ArrayTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for ArrayTable<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("a", Self::VT_A, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> ArrayTableBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for ArrayTable<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for ArrayTable<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("ArrayTable"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/arrays_test/my_game/example/nested_struct_generated.rs b/tests/arrays_test/my_game/example/nested_struct_generated.rs index a422fcf9242..507abb4d814 100644 --- a/tests/arrays_test/my_game/example/nested_struct_generated.rs +++ b/tests/arrays_test/my_game/example/nested_struct_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct NestedStruct, aligned to 8 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for NestedStruct { Self([0; 32]) } } -impl self::core::fmt::Debug for NestedStruct { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for NestedStruct { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("NestedStruct") .field("a", &self.a()) .field("b", &self.b()) @@ -50,7 +48,7 @@ impl<'b> flatbuffers::Push for NestedStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size()) + slice::from_raw_parts(self as *const NestedStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -61,7 +59,7 @@ impl<'b> flatbuffers::Push for &'b NestedStruct { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size()) + slice::from_raw_parts(*self as *const NestedStruct as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -72,7 +70,6 @@ impl<'a> flatbuffers::Verifiable for NestedStruct { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -105,24 +102,24 @@ impl<'a> NestedStruct { } pub fn b(&self) -> TestEnum { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[8..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_b(&mut self, x: TestEnum) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const TestEnum as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -133,7 +130,7 @@ impl<'a> NestedStruct { pub fn set_c(&mut self, x: &[TestEnum; 2]) { unsafe { - self::core::ptr::copy( + ptr::copy( x.as_ptr() as *const u8, self.0.as_mut_ptr().add(9), 2, diff --git a/tests/arrays_test/my_game/example/test_enum_generated.rs b/tests/arrays_test/my_game/example/test_enum_generated.rs index 2523b35d191..1b7cc66e87c 100644 --- a/tests/arrays_test/my_game/example/test_enum_generated.rs +++ b/tests/arrays_test/my_game/example/test_enum_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_TEST_ENUM: i8 = 0; @@ -47,8 +45,8 @@ impl TestEnum { } } } -impl self::core::fmt::Debug for TestEnum { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for TestEnum { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for TestEnum { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/include_test1/my_game/other_name_space/from_include_generated.rs b/tests/include_test1/my_game/other_name_space/from_include_generated.rs index 79d6bbf0aa0..9112c751e13 100644 --- a/tests/include_test1/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test1/my_game/other_name_space/from_include_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[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; @@ -39,8 +37,8 @@ impl FromInclude { } } } -impl self::core::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for FromInclude { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -86,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for FromInclude { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i64::run_verifier(v, pos) } } diff --git a/tests/include_test1/my_game/other_name_space/table_b_generated.rs b/tests/include_test1/my_game/other_name_space/table_b_generated.rs index 4c17a745ec4..7c9a8fdbdee 100644 --- a/tests/include_test1/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test1/my_game/other_name_space/table_b_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for TableB<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("a", Self::VT_A, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/include_test1/my_game/other_name_space/unused_generated.rs b/tests/include_test1/my_game/other_name_space/unused_generated.rs index 10aab3250c4..cd9a96d4c97 100644 --- a/tests/include_test1/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test1/my_game/other_name_space/unused_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Unused { Self([0; 4]) } } -impl self::core::fmt::Debug for Unused { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Unused { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -47,7 +45,7 @@ impl<'b> flatbuffers::Push for Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) + slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +56,7 @@ impl<'b> flatbuffers::Push for &'b Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -69,7 +67,6 @@ impl<'a> flatbuffers::Verifiable for Unused { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -88,24 +85,24 @@ impl<'a> Unused { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/include_test1/table_a_generated.rs b/tests/include_test1/table_a_generated.rs index f128cc7104c..91274b1efdf 100644 --- a/tests/include_test1/table_a_generated.rs +++ b/tests/include_test1/table_a_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for TableA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("b", Self::VT_B, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableA<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/include_test2/my_game/other_name_space/from_include_generated.rs b/tests/include_test2/my_game/other_name_space/from_include_generated.rs index 79d6bbf0aa0..9112c751e13 100644 --- a/tests/include_test2/my_game/other_name_space/from_include_generated.rs +++ b/tests/include_test2/my_game/other_name_space/from_include_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[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; @@ -39,8 +37,8 @@ impl FromInclude { } } } -impl self::core::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for FromInclude { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -86,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for FromInclude { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i64::run_verifier(v, pos) } } diff --git a/tests/include_test2/my_game/other_name_space/table_b_generated.rs b/tests/include_test2/my_game/other_name_space/table_b_generated.rs index 4c17a745ec4..7c9a8fdbdee 100644 --- a/tests/include_test2/my_game/other_name_space/table_b_generated.rs +++ b/tests/include_test2/my_game/other_name_space/table_b_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for TableB<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("a", Self::VT_A, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/include_test2/my_game/other_name_space/unused_generated.rs b/tests/include_test2/my_game/other_name_space/unused_generated.rs index 10aab3250c4..cd9a96d4c97 100644 --- a/tests/include_test2/my_game/other_name_space/unused_generated.rs +++ b/tests/include_test2/my_game/other_name_space/unused_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Unused { Self([0; 4]) } } -impl self::core::fmt::Debug for Unused { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Unused { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -47,7 +45,7 @@ impl<'b> flatbuffers::Push for Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) + slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +56,7 @@ impl<'b> flatbuffers::Push for &'b Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -69,7 +67,6 @@ impl<'a> flatbuffers::Verifiable for Unused { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -88,24 +85,24 @@ impl<'a> Unused { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/include_test2/table_a_generated.rs b/tests/include_test2/table_a_generated.rs index f128cc7104c..91274b1efdf 100644 --- a/tests/include_test2/table_a_generated.rs +++ b/tests/include_test2/table_a_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for TableA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("b", Self::VT_B, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableA<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/keyword_test/keyword_test/abc_generated.rs b/tests/keyword_test/keyword_test/abc_generated.rs index 2ee30bed367..9a8ece71681 100644 --- a/tests/keyword_test/keyword_test/abc_generated.rs +++ b/tests/keyword_test/keyword_test/abc_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ABC: i32 = 0; @@ -47,8 +45,8 @@ impl ABC { } } } -impl self::core::fmt::Debug for ABC { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for ABC { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for ABC { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i32::run_verifier(v, pos) } } diff --git a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs index 54ac9dfaabf..0e976ea5172 100644 --- a/tests/keyword_test/keyword_test/keywords_in_table_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_table_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum KeywordsInTableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -79,7 +77,6 @@ impl flatbuffers::Verifiable for KeywordsInTable<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("is", Self::VT_IS, false)? .visit_field::("private", Self::VT_PRIVATE, false)? @@ -135,8 +132,8 @@ impl<'a: 'b, 'b> KeywordsInTableBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for KeywordsInTable<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for KeywordsInTable<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("KeywordsInTable"); ds.field("is", &self.is()); ds.field("private", &self.private()); diff --git a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs index eee85d005fa..35f7533c884 100644 --- a/tests/keyword_test/keyword_test/keywords_in_union_generated.rs +++ b/tests/keyword_test/keyword_test/keywords_in_union_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_KEYWORDS_IN_UNION: u8 = 0; @@ -47,8 +45,8 @@ impl KeywordsInUnion { } } } -impl self::core::fmt::Debug for KeywordsInUnion { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for KeywordsInUnion { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for KeywordsInUnion { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -133,7 +130,7 @@ impl KeywordsInUnionT { /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_static_(&mut self) -> Option> { if let Self::Static_(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Static_(w) = v { Some(w) } else { @@ -154,7 +151,7 @@ impl KeywordsInUnionT { /// If the union variant matches, return the owned KeywordsInTableT, setting the union to NONE. pub fn take_internal(&mut self) -> Option> { if let Self::Internal(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Internal(w) = v { Some(w) } else { diff --git a/tests/keyword_test/keyword_test/public_generated.rs b/tests/keyword_test/keyword_test/public_generated.rs index 70dc3c88d8f..62dbe4f20c6 100644 --- a/tests/keyword_test/keyword_test/public_generated.rs +++ b/tests/keyword_test/keyword_test/public_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_PUBLIC: i32 = 0; @@ -39,8 +37,8 @@ impl public { } } } -impl self::core::fmt::Debug for public { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for public { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -86,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for public { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i32::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/example/ability_generated.rs b/tests/monster_test/my_game/example/ability_generated.rs index b8c5057d7ab..63e097bb770 100644 --- a/tests/monster_test/my_game/example/ability_generated.rs +++ b/tests/monster_test/my_game/example/ability_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Ability, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Ability { Self([0; 8]) } } -impl self::core::fmt::Debug for Ability { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Ability { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Ability") .field("id", &self.id()) .field("distance", &self.distance()) @@ -48,7 +46,7 @@ impl<'b> flatbuffers::Push for Ability { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Ability as *const u8, Self::size()) + slice::from_raw_parts(self as *const Ability as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -59,7 +57,7 @@ impl<'b> flatbuffers::Push for &'b Ability { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Ability as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Ability as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -70,7 +68,6 @@ impl<'a> flatbuffers::Verifiable for Ability { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -91,24 +88,24 @@ impl<'a> Ability { } pub fn id(&self) -> u32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_id(&mut self, x: u32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const u32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } @@ -119,29 +116,29 @@ impl<'a> Ability { } #[inline] - pub fn key_compare_with_value(&self, val: u32) -> self::core::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u32) -> Ordering { let key = self.id(); key.cmp(&val) } pub fn distance(&self) -> u32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_distance(&mut self, x: u32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const u32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs index 77145fc1d5f..42723b4a523 100644 --- a/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_ambiguous_aliases_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY_AMBIGUOUS_ALIASES: u8 = 0; @@ -51,8 +49,8 @@ impl AnyAmbiguousAliases { } } } -impl self::core::fmt::Debug for AnyAmbiguousAliases { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for AnyAmbiguousAliases { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -98,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for AnyAmbiguousAliases { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -140,7 +137,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m1(&mut self) -> Option> { if let Self::M1(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M1(w) = v { Some(w) } else { @@ -161,7 +158,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M2(w) = v { Some(w) } else { @@ -182,7 +179,7 @@ impl AnyAmbiguousAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m3(&mut self) -> Option> { if let Self::M3(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M3(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/any_generated.rs b/tests/monster_test/my_game/example/any_generated.rs index a437cfe372f..cfaa517a19e 100644 --- a/tests/monster_test/my_game/example/any_generated.rs +++ b/tests/monster_test/my_game/example/any_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY: u8 = 0; @@ -51,8 +49,8 @@ impl Any { } } } -impl self::core::fmt::Debug for Any { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Any { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -98,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for Any { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -140,7 +137,7 @@ impl AnyT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_monster(&mut self) -> Option> { if let Self::Monster(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::Monster(w) = v { Some(w) } else { @@ -161,7 +158,7 @@ impl AnyT { /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. pub fn take_test_simple_table_with_enum(&mut self) -> Option> { if let Self::TestSimpleTableWithEnum(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::TestSimpleTableWithEnum(w) = v { Some(w) } else { @@ -182,7 +179,7 @@ impl AnyT { /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. pub fn take_my_game_example_2_monster(&mut self) -> Option> { if let Self::MyGameExample2Monster(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::MyGameExample2Monster(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs index 14ba17bff94..3158c0bd9e9 100644 --- a/tests/monster_test/my_game/example/any_unique_aliases_generated.rs +++ b/tests/monster_test/my_game/example/any_unique_aliases_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ANY_UNIQUE_ALIASES: u8 = 0; @@ -51,8 +49,8 @@ impl AnyUniqueAliases { } } } -impl self::core::fmt::Debug for AnyUniqueAliases { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for AnyUniqueAliases { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -98,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for AnyUniqueAliases { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -140,7 +137,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned MonsterT, setting the union to NONE. pub fn take_m(&mut self) -> Option> { if let Self::M(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M(w) = v { Some(w) } else { @@ -161,7 +158,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned TestSimpleTableWithEnumT, setting the union to NONE. pub fn take_ts(&mut self) -> Option> { if let Self::TS(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::TS(w) = v { Some(w) } else { @@ -182,7 +179,7 @@ impl AnyUniqueAliasesT { /// If the union variant matches, return the owned super::example_2::MonsterT, setting the union to NONE. pub fn take_m2(&mut self) -> Option> { if let Self::M2(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::M2(w) = v { Some(w) } else { diff --git a/tests/monster_test/my_game/example/color_generated.rs b/tests/monster_test/my_game/example/color_generated.rs index c4635b37c89..dc39ab70a3c 100644 --- a/tests/monster_test/my_game/example/color_generated.rs +++ b/tests/monster_test/my_game/example/color_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[allow(non_upper_case_globals)] mod bitflags_color { @@ -64,7 +62,6 @@ impl<'a> flatbuffers::Verifiable for Color { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/example/monster_generated.rs b/tests/monster_test/my_game/example/monster_generated.rs index 7951f4c035d..6e133adfad2 100644 --- a/tests/monster_test/my_game/example/monster_generated.rs +++ b/tests/monster_test/my_game/example/monster_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -370,7 +368,7 @@ impl<'a> Monster<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: & str) -> self::core::cmp::Ordering { + pub fn key_compare_with_value(&self, val: & str) -> Ordering { let key = self.name(); key.cmp(val) } @@ -414,7 +412,6 @@ impl<'a> Monster<'a> { } pub fn testnestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testnestedflatbuffer().map(|data| { - use flatbuffers::Follow; >>::follow(data, 0) }) } @@ -564,7 +561,6 @@ impl<'a> Monster<'a> { } pub fn testrequirednestedflatbuffer_nested_flatbuffer(&'a self) -> Option> { self.testrequirednestedflatbuffer().map(|data| { - use flatbuffers::Follow; >>::follow(data, 0) }) } @@ -669,7 +665,6 @@ impl flatbuffers::Verifiable for Monster<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("pos", Self::VT_POS, false)? .visit_field::("mana", Self::VT_MANA, false)? @@ -1073,8 +1068,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Monster"); ds.field("pos", &self.pos()); ds.field("mana", &self.mana()); diff --git a/tests/monster_test/my_game/example/race_generated.rs b/tests/monster_test/my_game/example/race_generated.rs index ced60232503..25c3cff86f9 100644 --- a/tests/monster_test/my_game/example/race_generated.rs +++ b/tests/monster_test/my_game/example/race_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_RACE: i8 = -1; @@ -51,8 +49,8 @@ impl Race { } } } -impl self::core::fmt::Debug for Race { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Race { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -98,7 +96,6 @@ impl<'a> flatbuffers::Verifiable for Race { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/example/referrable_generated.rs b/tests/monster_test/my_game/example/referrable_generated.rs index 4ff479a4121..237ac5c493d 100644 --- a/tests/monster_test/my_game/example/referrable_generated.rs +++ b/tests/monster_test/my_game/example/referrable_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum ReferrableOffset {} #[derive(Copy, Clone, PartialEq)] @@ -62,7 +60,7 @@ impl<'a> Referrable<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: u64) -> self::core::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u64) -> Ordering { let key = self.id(); key.cmp(&val) } @@ -73,7 +71,6 @@ impl flatbuffers::Verifiable for Referrable<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("id", Self::VT_ID, false)? .finish(); @@ -115,8 +112,8 @@ impl<'a: 'b, 'b> ReferrableBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for Referrable<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for Referrable<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Referrable"); ds.field("id", &self.id()); ds.finish() diff --git a/tests/monster_test/my_game/example/stat_generated.rs b/tests/monster_test/my_game/example/stat_generated.rs index ef6c7355aae..6403494b8fb 100644 --- a/tests/monster_test/my_game/example/stat_generated.rs +++ b/tests/monster_test/my_game/example/stat_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum StatOffset {} #[derive(Copy, Clone, PartialEq)] @@ -80,7 +78,7 @@ impl<'a> Stat<'a> { } #[inline] - pub fn key_compare_with_value(&self, val: u16) -> self::core::cmp::Ordering { + pub fn key_compare_with_value(&self, val: u16) -> Ordering { let key = self.count(); key.cmp(&val) } @@ -91,7 +89,6 @@ impl flatbuffers::Verifiable for Stat<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("id", Self::VT_ID, false)? .visit_field::("val", Self::VT_VAL, false)? @@ -147,8 +144,8 @@ impl<'a: 'b, 'b> StatBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for Stat<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for Stat<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Stat"); ds.field("id", &self.id()); ds.field("val", &self.val()); diff --git a/tests/monster_test/my_game/example/struct_of_structs_generated.rs b/tests/monster_test/my_game/example/struct_of_structs_generated.rs index b1b0ea630fe..a5ae899247c 100644 --- a/tests/monster_test/my_game/example/struct_of_structs_generated.rs +++ b/tests/monster_test/my_game/example/struct_of_structs_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct StructOfStructs, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for StructOfStructs { Self([0; 20]) } } -impl self::core::fmt::Debug for StructOfStructs { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for StructOfStructs { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("StructOfStructs") .field("a", &self.a()) .field("b", &self.b()) @@ -49,7 +47,7 @@ impl<'b> flatbuffers::Push for StructOfStructs { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size()) + slice::from_raw_parts(self as *const StructOfStructs as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -60,7 +58,7 @@ impl<'b> flatbuffers::Push for &'b StructOfStructs { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size()) + slice::from_raw_parts(*self as *const StructOfStructs as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -71,7 +69,6 @@ impl<'a> flatbuffers::Verifiable for StructOfStructs { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } diff --git a/tests/monster_test/my_game/example/test_generated.rs b/tests/monster_test/my_game/example/test_generated.rs index edfb70ab8d9..b7ee0967aae 100644 --- a/tests/monster_test/my_game/example/test_generated.rs +++ b/tests/monster_test/my_game/example/test_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Test, aligned to 2 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Test { Self([0; 4]) } } -impl self::core::fmt::Debug for Test { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Test { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Test") .field("a", &self.a()) .field("b", &self.b()) @@ -48,7 +46,7 @@ impl<'b> flatbuffers::Push for Test { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Test as *const u8, Self::size()) + slice::from_raw_parts(self as *const Test as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -59,7 +57,7 @@ impl<'b> flatbuffers::Push for &'b Test { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Test as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -70,7 +68,6 @@ impl<'a> flatbuffers::Verifiable for Test { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -91,47 +88,47 @@ impl<'a> Test { } pub fn a(&self) -> i16 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i16) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i16 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn b(&self) -> i8 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[2..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_b(&mut self, x: i8) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i8 as *const u8, self.0[2..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs index 9188f7fc306..0f83417967c 100644 --- a/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs +++ b/tests/monster_test/my_game/example/test_simple_table_with_enum_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TestSimpleTableWithEnumOffset {} #[derive(Copy, Clone, PartialEq)] @@ -63,7 +61,6 @@ impl flatbuffers::Verifiable for TestSimpleTableWithEnum<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("color", Self::VT_COLOR, false)? .finish(); @@ -105,8 +102,8 @@ impl<'a: 'b, 'b> TestSimpleTableWithEnumBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TestSimpleTableWithEnum<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TestSimpleTableWithEnum<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TestSimpleTableWithEnum"); ds.field("color", &self.color()); ds.finish() diff --git a/tests/monster_test/my_game/example/type_aliases_generated.rs b/tests/monster_test/my_game/example/type_aliases_generated.rs index a5dce0c5cb3..da4fdb1fdc5 100644 --- a/tests/monster_test/my_game/example/type_aliases_generated.rs +++ b/tests/monster_test/my_game/example/type_aliases_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TypeAliasesOffset {} #[derive(Copy, Clone, PartialEq)] @@ -155,7 +153,6 @@ impl flatbuffers::Verifiable for TypeAliases<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("i8_", Self::VT_I8_, false)? .visit_field::("u8_", Self::VT_U8_, false)? @@ -274,8 +271,8 @@ impl<'a: 'b, 'b> TypeAliasesBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TypeAliases<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TypeAliases<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TypeAliases"); ds.field("i8_", &self.i8_()); ds.field("u8_", &self.u8_()); diff --git a/tests/monster_test/my_game/example/vec_3_generated.rs b/tests/monster_test/my_game/example/vec_3_generated.rs index d6a08b2b0c5..8d27660592a 100644 --- a/tests/monster_test/my_game/example/vec_3_generated.rs +++ b/tests/monster_test/my_game/example/vec_3_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Vec3, aligned to 8 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Vec3 { Self([0; 32]) } } -impl self::core::fmt::Debug for Vec3 { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Vec3 { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Vec3") .field("x", &self.x()) .field("y", &self.y()) @@ -52,7 +50,7 @@ impl<'b> flatbuffers::Push for Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -63,7 +61,7 @@ impl<'b> flatbuffers::Push for &'b Vec3 { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -74,7 +72,6 @@ impl<'a> flatbuffers::Verifiable for Vec3 { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -103,116 +100,116 @@ impl<'a> Vec3 { } pub fn x(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_x(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn y(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_y(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn z(&self) -> f32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[8..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_z(&mut self, x: f32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f32 as *const u8, self.0[8..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn test1(&self) -> f64 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[16..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_test1(&mut self, x: f64) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const f64 as *const u8, self.0[16..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn test2(&self) -> Color { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[24..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_test2(&mut self, x: Color) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const Color as *const u8, self.0[24..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/my_game/example_2/monster_generated.rs b/tests/monster_test/my_game/example_2/monster_generated.rs index 6133241d260..1b9817cf5cd 100644 --- a/tests/monster_test/my_game/example_2/monster_generated.rs +++ b/tests/monster_test/my_game/example_2/monster_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MonsterOffset {} #[derive(Copy, Clone, PartialEq)] @@ -54,7 +52,6 @@ impl flatbuffers::Verifiable for Monster<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .finish(); Ok(()) @@ -89,8 +86,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for Monster<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for Monster<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("Monster"); ds.finish() } diff --git a/tests/monster_test/my_game/in_parent_namespace_generated.rs b/tests/monster_test/my_game/in_parent_namespace_generated.rs index 7d0f9c34242..40da52fccc6 100644 --- a/tests/monster_test/my_game/in_parent_namespace_generated.rs +++ b/tests/monster_test/my_game/in_parent_namespace_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum InParentNamespaceOffset {} #[derive(Copy, Clone, PartialEq)] @@ -54,7 +52,6 @@ impl flatbuffers::Verifiable for InParentNamespace<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .finish(); Ok(()) @@ -89,8 +86,8 @@ impl<'a: 'b, 'b> InParentNamespaceBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for InParentNamespace<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for InParentNamespace<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("InParentNamespace"); ds.finish() } diff --git a/tests/monster_test/my_game/other_name_space/from_include_generated.rs b/tests/monster_test/my_game/other_name_space/from_include_generated.rs index 79d6bbf0aa0..9112c751e13 100644 --- a/tests/monster_test/my_game/other_name_space/from_include_generated.rs +++ b/tests/monster_test/my_game/other_name_space/from_include_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[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; @@ -39,8 +37,8 @@ impl FromInclude { } } } -impl self::core::fmt::Debug for FromInclude { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for FromInclude { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -86,7 +84,6 @@ impl<'a> flatbuffers::Verifiable for FromInclude { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i64::run_verifier(v, pos) } } diff --git a/tests/monster_test/my_game/other_name_space/table_b_generated.rs b/tests/monster_test/my_game/other_name_space/table_b_generated.rs index 4c17a745ec4..7c9a8fdbdee 100644 --- a/tests/monster_test/my_game/other_name_space/table_b_generated.rs +++ b/tests/monster_test/my_game/other_name_space/table_b_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableBOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for TableB<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("a", Self::VT_A, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> TableBBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableB<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableB<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableB"); ds.field("a", &self.a()); ds.finish() diff --git a/tests/monster_test/my_game/other_name_space/unused_generated.rs b/tests/monster_test/my_game/other_name_space/unused_generated.rs index 10aab3250c4..cd9a96d4c97 100644 --- a/tests/monster_test/my_game/other_name_space/unused_generated.rs +++ b/tests/monster_test/my_game/other_name_space/unused_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct Unused, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for Unused { Self([0; 4]) } } -impl self::core::fmt::Debug for Unused { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for Unused { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Unused") .field("a", &self.a()) .finish() @@ -47,7 +45,7 @@ impl<'b> flatbuffers::Push for Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) + slice::from_raw_parts(self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -58,7 +56,7 @@ impl<'b> flatbuffers::Push for &'b Unused { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) + slice::from_raw_parts(*self as *const Unused as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -69,7 +67,6 @@ impl<'a> flatbuffers::Verifiable for Unused { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -88,24 +85,24 @@ impl<'a> Unused { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/monster_test/table_a_generated.rs b/tests/monster_test/table_a_generated.rs index f128cc7104c..91274b1efdf 100644 --- a/tests/monster_test/table_a_generated.rs +++ b/tests/monster_test/table_a_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for TableA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("b", Self::VT_B, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> TableABuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableA<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableA"); ds.field("b", &self.b()); ds.finish() diff --git a/tests/more_defaults/abc_generated.rs b/tests/more_defaults/abc_generated.rs index 1520220c2bb..cb4e19f7098 100644 --- a/tests/more_defaults/abc_generated.rs +++ b/tests/more_defaults/abc_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ABC: i32 = 0; @@ -47,8 +45,8 @@ impl ABC { } } } -impl self::core::fmt::Debug for ABC { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for ABC { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for ABC { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i32::run_verifier(v, pos) } } diff --git a/tests/more_defaults/more_defaults_generated.rs b/tests/more_defaults/more_defaults_generated.rs index d820465b19b..69612aa2b5e 100644 --- a/tests/more_defaults/more_defaults_generated.rs +++ b/tests/more_defaults/more_defaults_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum MoreDefaultsOffset {} #[derive(Copy, Clone, PartialEq)] @@ -121,7 +119,6 @@ impl flatbuffers::Verifiable for MoreDefaults<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>>("ints", Self::VT_INTS, false)? .visit_field::>>("floats", Self::VT_FLOATS, false)? @@ -198,8 +195,8 @@ impl<'a: 'b, 'b> MoreDefaultsBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for MoreDefaults<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for MoreDefaults<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("MoreDefaults"); ds.field("ints", &self.ints()); ds.field("floats", &self.floats()); diff --git a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs index 8a815e82e8d..7b6f3ded12b 100644 --- a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ENUM_IN_NESTED_NS: i8 = 0; @@ -47,8 +45,8 @@ impl EnumInNestedNS { } } } -impl self::core::fmt::Debug for EnumInNestedNS { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for EnumInNestedNS { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for EnumInNestedNS { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs index 39306136d62..73850aad3c4 100644 --- a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; // struct StructInNestedNS, aligned to 4 #[repr(transparent)] @@ -18,8 +16,8 @@ impl Default for StructInNestedNS { Self([0; 8]) } } -impl self::core::fmt::Debug for StructInNestedNS { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for StructInNestedNS { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("StructInNestedNS") .field("a", &self.a()) .field("b", &self.b()) @@ -48,7 +46,7 @@ impl<'b> flatbuffers::Push for StructInNestedNS { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size()) + slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -59,7 +57,7 @@ impl<'b> flatbuffers::Push for &'b StructInNestedNS { #[inline] fn push(&self, dst: &mut [u8], _rest: &[u8]) { let src = unsafe { - self::core::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size()) + slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size()) }; dst.copy_from_slice(src); } @@ -70,7 +68,6 @@ impl<'a> flatbuffers::Verifiable for StructInNestedNS { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.in_buffer::(pos) } } @@ -91,47 +88,47 @@ impl<'a> StructInNestedNS { } pub fn a(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[0..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_a(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[0..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } pub fn b(&self) -> i32 { - let mut mem = core::mem::MaybeUninit::::uninit(); + let mut uninit = mem::MaybeUninit::::uninit(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( self.0[4..].as_ptr(), - mem.as_mut_ptr() as *mut u8, - core::mem::size_of::(), + uninit.as_mut_ptr() as *mut u8, + mem::size_of::(), ); - mem.assume_init() + uninit.assume_init() }.from_little_endian() } pub fn set_b(&mut self, x: i32) { let x_le = x.to_little_endian(); unsafe { - core::ptr::copy_nonoverlapping( + ptr::copy_nonoverlapping( &x_le as *const i32 as *const u8, self.0[4..].as_mut_ptr(), - core::mem::size_of::(), + mem::size_of::(), ); } } diff --git a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs index 1c1991a5e81..588bba8c545 100644 --- a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableInNestedNSOffset {} #[derive(Copy, Clone, PartialEq)] @@ -63,7 +61,6 @@ impl flatbuffers::Verifiable for TableInNestedNS<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("foo", Self::VT_FOO, false)? .finish(); @@ -105,8 +102,8 @@ impl<'a: 'b, 'b> TableInNestedNSBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableInNestedNS<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableInNestedNS<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableInNestedNS"); ds.field("foo", &self.foo()); ds.finish() diff --git a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs index 923812b8617..4e2ab0600b1 100644 --- a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs +++ b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_UNION_IN_NESTED_NS: u8 = 0; @@ -43,8 +41,8 @@ impl UnionInNestedNS { } } } -impl self::core::fmt::Debug for UnionInNestedNS { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for UnionInNestedNS { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -90,7 +88,6 @@ impl<'a> flatbuffers::Verifiable for UnionInNestedNS { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) } } @@ -126,7 +123,7 @@ impl UnionInNestedNST { /// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE. pub fn take_table_in_nested_ns(&mut self) -> Option> { if let Self::TableInNestedNS(_) = self { - let v = self::core::mem::replace(self, Self::NONE); + let v = mem::replace(self, Self::NONE); if let Self::TableInNestedNS(w) = v { Some(w) } else { diff --git a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs index 9de56d6928a..c6b84c9de49 100644 --- a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs +++ b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum SecondTableInAOffset {} #[derive(Copy, Clone, PartialEq)] @@ -65,7 +63,6 @@ impl flatbuffers::Verifiable for SecondTableInA<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("refer_to_c", Self::VT_REFER_TO_C, false)? .finish(); @@ -107,8 +104,8 @@ impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> { } } -impl self::core::fmt::Debug for SecondTableInA<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for SecondTableInA<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("SecondTableInA"); ds.field("refer_to_c", &self.refer_to_c()); ds.finish() diff --git a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs index 256d88595eb..a2a7c8de7ce 100644 --- a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs +++ b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableInFirstNSOffset {} #[derive(Copy, Clone, PartialEq)] @@ -115,7 +113,6 @@ impl flatbuffers::Verifiable for TableInFirstNS<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("foo_table", Self::VT_FOO_TABLE, false)? .visit_field::("foo_enum", Self::VT_FOO_ENUM, false)? @@ -189,8 +186,8 @@ impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableInFirstNS<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableInFirstNS<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableInFirstNS"); ds.field("foo_table", &self.foo_table()); ds.field("foo_enum", &self.foo_enum()); diff --git a/tests/namespace_test/namespace_c/table_in_c_generated.rs b/tests/namespace_test/namespace_c/table_in_c_generated.rs index 0221bbf9e57..2c11f730659 100644 --- a/tests/namespace_test/namespace_c/table_in_c_generated.rs +++ b/tests/namespace_test/namespace_c/table_in_c_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum TableInCOffset {} #[derive(Copy, Clone, PartialEq)] @@ -75,7 +73,6 @@ impl flatbuffers::Verifiable for TableInC<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::>("refer_to_a1", Self::VT_REFER_TO_A1, false)? .visit_field::>("refer_to_a2", Self::VT_REFER_TO_A2, false)? @@ -124,8 +121,8 @@ impl<'a: 'b, 'b> TableInCBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for TableInC<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for TableInC<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("TableInC"); ds.field("refer_to_a1", &self.refer_to_a1()); ds.field("refer_to_a2", &self.refer_to_a2()); diff --git a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs index 9c1c45b36fb..62c4e4d64b8 100644 --- a/tests/optional_scalars/optional_scalars/optional_byte_generated.rs +++ b/tests/optional_scalars/optional_scalars/optional_byte_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_OPTIONAL_BYTE: i8 = 0; @@ -47,8 +45,8 @@ impl OptionalByte { } } } -impl self::core::fmt::Debug for OptionalByte { - fn fmt(&self, f: &mut self::core::fmt::Formatter) -> self::core::fmt::Result { +impl fmt::Debug for OptionalByte { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(name) = self.variant_name() { f.write_str(name) } else { @@ -94,7 +92,6 @@ impl<'a> flatbuffers::Verifiable for OptionalByte { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) } } diff --git a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs index 65a01847228..37186f577f1 100644 --- a/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs +++ b/tests/optional_scalars/optional_scalars/scalar_stuff_generated.rs @@ -1,13 +1,11 @@ // automatically generated by the FlatBuffers compiler, do not modify -extern crate flatbuffers; -extern crate core; extern crate alloc; -use self::alloc::vec::Vec; -use self::alloc::boxed::Box; +extern crate core; +extern crate flatbuffers; +use self::alloc::{boxed::Box, vec::Vec}; use self::alloc::string::{String, ToString as _}; -use self::core::mem; -use self::core::cmp::Ordering; -use self::flatbuffers::{EndianScalar, Follow}; +use self::core::{cmp::Ordering, fmt, mem, ptr, slice}; +use self::flatbuffers::{EndianScalar, Follow, Verifiable}; use super::*; pub enum ScalarStuffOffset {} #[derive(Copy, Clone, PartialEq)] @@ -343,7 +341,6 @@ impl flatbuffers::Verifiable for ScalarStuff<'_> { fn run_verifier( v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; v.visit_table(pos)? .visit_field::("just_i8", Self::VT_JUST_I8, false)? .visit_field::("maybe_i8", Self::VT_MAYBE_I8, false)? @@ -630,8 +627,8 @@ impl<'a: 'b, 'b> ScalarStuffBuilder<'a, 'b> { } } -impl self::core::fmt::Debug for ScalarStuff<'_> { - fn fmt(&self, f: &mut self::core::fmt::Formatter<'_>) -> self::core::fmt::Result { +impl fmt::Debug for ScalarStuff<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut ds = f.debug_struct("ScalarStuff"); ds.field("just_i8", &self.just_i8()); ds.field("maybe_i8", &self.maybe_i8()); From fcb744ff251e4c169e50370358b748352fa39b4d Mon Sep 17 00:00:00 2001 From: Josh Robson Chase Date: Tue, 19 Oct 2021 08:38:27 -0400 Subject: [PATCH 6/6] rust/no_std_test: Stop using deprecated get_ functions --- tests/rust_usage_test/tests/no_std_test.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rust_usage_test/tests/no_std_test.rs b/tests/rust_usage_test/tests/no_std_test.rs index fc15663c9da..ca91314ad5f 100644 --- a/tests/rust_usage_test/tests/no_std_test.rs +++ b/tests/rust_usage_test/tests/no_std_test.rs @@ -12,7 +12,7 @@ static MONSTER_DATA: &[u8] = include_bytes!("../../monsterdata_test.mon"); // Note: Copied from `bin/monster_example.rs` #[test] fn no_std_example_data() { - let monster = my_game::example::get_root_as_monster(MONSTER_DATA); + let monster = my_game::example::root_as_monster(MONSTER_DATA).unwrap(); assert_eq!(monster.hp(), 80); assert_eq!(monster.mana(), 150); @@ -29,7 +29,7 @@ fn build_mon<'a, 'b>( ) -> my_game::example::Monster<'a> { let mon = my_game::example::Monster::create(builder, &args); my_game::example::finish_monster_buffer(builder, mon); - my_game::example::get_root_as_monster(builder.finished_data()) + my_game::example::root_as_monster(builder.finished_data()).unwrap() } #[test]