From 3968d0056865cb08c62b367470d18d633908565e Mon Sep 17 00:00:00 2001 From: bspeice Date: Sat, 9 Mar 2019 14:58:27 -0600 Subject: [PATCH] [Rust] Don't use inner attributes for `allow` (#5212) * Don't use inner attributes for `allow` Messes with being able to easily include elsewhere * Regenerate tests * No-op to retrigger CI * Add the rest of the `allow` attributes --- docs/source/RustUsage.md | 1 + docs/source/Tutorial.md | 2 ++ src/idl_gen_rust.cpp | 3 +-- tests/monster_test_generated.rs | 11 +++-------- tests/namespace_test/namespace_test1_generated.rs | 8 ++------ tests/namespace_test/namespace_test2_generated.rs | 8 ++------ .../rust_usage_test/benches/flatbuffers_benchmarks.rs | 1 + tests/rust_usage_test/bin/alloc_check.rs | 1 + tests/rust_usage_test/bin/monster_example.rs | 1 + tests/rust_usage_test/tests/integration_test.rs | 1 + 10 files changed, 15 insertions(+), 22 deletions(-) diff --git a/docs/source/RustUsage.md b/docs/source/RustUsage.md index 80434a470..68191179c 100644 --- a/docs/source/RustUsage.md +++ b/docs/source/RustUsage.md @@ -68,6 +68,7 @@ It can be run by `cd`ing to the `rust_usage_test` directory and executing: `carg ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.rs} extern crate flatbuffers; + #[allow(dead_code, unused_imports)] #[path = "../../monster_test_generated.rs"] mod monster_test_generated; pub use monster_test_generated::my_game; diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md index db3efa3d8..d9c23485c 100644 --- a/docs/source/Tutorial.md +++ b/docs/source/Tutorial.md @@ -495,6 +495,7 @@ The first step is to import/include the library, generated files, etc. extern crate flatbuffers; // import the generated code + #[allow(dead_code, unused_imports)] #[path = "./monster_generated.rs"] mod monster_generated; pub use monster_generated::my_game::sample::{get_root_as_monster, @@ -2042,6 +2043,7 @@ import './monster_my_game.sample_generated.dart' as myGame; extern crate flatbuffers; // import the generated code + #[allow(dead_code, unused_imports)] #[path = "./monster_generated.rs"] mod monster_generated; pub use monster_generated::my_game::sample::{get_root_as_monster, diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp index ccfb376bf..e8ecbbc4a 100644 --- a/src/idl_gen_rust.cpp +++ b/src/idl_gen_rust.cpp @@ -1749,8 +1749,6 @@ class RustGenerator : public BaseGenerator { void GenNamespaceImports(const int white_spaces) { std::string indent = std::string(white_spaces, ' '); - code_ += indent + "#![allow(dead_code)]"; - code_ += indent + "#![allow(unused_imports)]"; code_ += ""; code_ += indent + "use std::mem;"; code_ += indent + "use std::cmp::Ordering;"; @@ -1792,6 +1790,7 @@ class RustGenerator : public BaseGenerator { // open namespace parts to reach the ns namespace // in the previous example, E, then F, then G are opened for (auto j = common_prefix_size; j != new_size; ++j) { + code_ += "#[allow(unused_imports, dead_code)]"; code_ += "pub mod " + MakeSnakeCase(ns->components[j]) + " {"; // Generate local namespace imports. GenNamespaceImports(2); diff --git a/tests/monster_test_generated.rs b/tests/monster_test_generated.rs index 49db42d9a..558985ef9 100644 --- a/tests/monster_test_generated.rs +++ b/tests/monster_test_generated.rs @@ -1,8 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -#![allow(dead_code)] -#![allow(unused_imports)] use std::mem; use std::cmp::Ordering; @@ -10,9 +8,8 @@ use std::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] pub mod my_game { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; @@ -83,9 +80,8 @@ impl<'a: 'b, 'b> InParentNamespaceBuilder<'a, 'b> { } } +#[allow(unused_imports, dead_code)] pub mod example_2 { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; @@ -158,9 +154,8 @@ impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> { } // pub mod Example2 +#[allow(unused_imports, dead_code)] pub mod example { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; diff --git a/tests/namespace_test/namespace_test1_generated.rs b/tests/namespace_test/namespace_test1_generated.rs index 9df2fcc6d..3ffcde4cc 100644 --- a/tests/namespace_test/namespace_test1_generated.rs +++ b/tests/namespace_test/namespace_test1_generated.rs @@ -1,8 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -#![allow(dead_code)] -#![allow(unused_imports)] use std::mem; use std::cmp::Ordering; @@ -10,18 +8,16 @@ use std::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] pub mod namespace_a { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] pub mod namespace_b { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; diff --git a/tests/namespace_test/namespace_test2_generated.rs b/tests/namespace_test/namespace_test2_generated.rs index c2e70216a..3c04c0f03 100644 --- a/tests/namespace_test/namespace_test2_generated.rs +++ b/tests/namespace_test/namespace_test2_generated.rs @@ -1,8 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -#![allow(dead_code)] -#![allow(unused_imports)] use std::mem; use std::cmp::Ordering; @@ -10,9 +8,8 @@ use std::cmp::Ordering; extern crate flatbuffers; use self::flatbuffers::EndianScalar; +#[allow(unused_imports, dead_code)] pub mod namespace_a { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; @@ -198,9 +195,8 @@ impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> { } // pub mod NamespaceA +#[allow(unused_imports, dead_code)] pub mod namespace_c { - #![allow(dead_code)] - #![allow(unused_imports)] use std::mem; use std::cmp::Ordering; diff --git a/tests/rust_usage_test/benches/flatbuffers_benchmarks.rs b/tests/rust_usage_test/benches/flatbuffers_benchmarks.rs index 3ad45c287..2c6be1f30 100644 --- a/tests/rust_usage_test/benches/flatbuffers_benchmarks.rs +++ b/tests/rust_usage_test/benches/flatbuffers_benchmarks.rs @@ -20,6 +20,7 @@ use bencher::Bencher; extern crate flatbuffers; +#[allow(dead_code, unused_imports)] #[path = "../../monster_test_generated.rs"] mod monster_test_generated; pub use monster_test_generated::my_game; diff --git a/tests/rust_usage_test/bin/alloc_check.rs b/tests/rust_usage_test/bin/alloc_check.rs index 7fb3ef33f..ae1039cb1 100644 --- a/tests/rust_usage_test/bin/alloc_check.rs +++ b/tests/rust_usage_test/bin/alloc_check.rs @@ -28,6 +28,7 @@ static A: TrackingAllocator = TrackingAllocator; // import the flatbuffers generated code: extern crate flatbuffers; +#[allow(dead_code, unused_imports)] #[path = "../../monster_test_generated.rs"] mod monster_test_generated; pub use monster_test_generated::my_game; diff --git a/tests/rust_usage_test/bin/monster_example.rs b/tests/rust_usage_test/bin/monster_example.rs index e415a952b..3c9a0a0e6 100644 --- a/tests/rust_usage_test/bin/monster_example.rs +++ b/tests/rust_usage_test/bin/monster_example.rs @@ -1,5 +1,6 @@ extern crate flatbuffers; +#[allow(dead_code, unused_imports)] #[path = "../../monster_test_generated.rs"] mod monster_test_generated; pub use monster_test_generated::my_game; diff --git a/tests/rust_usage_test/tests/integration_test.rs b/tests/rust_usage_test/tests/integration_test.rs index 538df0349..0dace96db 100644 --- a/tests/rust_usage_test/tests/integration_test.rs +++ b/tests/rust_usage_test/tests/integration_test.rs @@ -19,6 +19,7 @@ extern crate quickcheck; extern crate flatbuffers; +#[allow(dead_code, unused_imports)] #[path = "../../monster_test_generated.rs"] mod monster_test_generated; pub use monster_test_generated::my_game;