From b0098903d47f62219d87b32893065924272d1d8d Mon Sep 17 00:00:00 2001 From: 0x009922 <43530070+0x009922@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:39:20 +0900 Subject: [PATCH] fix: address `check-cfg` warnings + chores Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com> --- Cargo.toml | 12 +++-- crates/iroha_crypto/src/lib.rs | 1 - crates/iroha_data_model/src/lib.rs | 1 - crates/iroha_derive/tests/ui.rs | 1 - crates/iroha_primitives/src/const_vec.rs | 2 +- crates/iroha_telemetry/Cargo.toml | 2 +- crates/iroha_telemetry_derive/Cargo.toml | 4 ++ crates/iroha_telemetry_derive/src/lib.rs | 44 +++++++++++-------- wasm_samples/default_executor/src/lib.rs | 1 - .../executor_with_migration_fail/src/lib.rs | 1 - .../query_assets_and_save_cursor/src/lib.rs | 2 - 11 files changed, 41 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f1e82af249e..9b1e540201c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -128,9 +128,9 @@ mv = { version = "0.1.0" } [workspace.lints] rustdoc.private_doc_tests = "deny" -rust.future_incompatible = {level = "deny", priority = -1 } -rust.nonstandard_style = {level = "deny", priority = -1 } -rust.rust_2018_idioms = {level = "deny", priority = -1 } +rust.future_incompatible = { level = "deny", priority = -1 } +rust.nonstandard_style = { level = "deny", priority = -1 } +rust.rust_2018_idioms = { level = "deny", priority = -1 } rust.unused = { level = "deny", priority = -1 } rust.anonymous_parameters = "deny" @@ -149,6 +149,12 @@ rust.single_use_lifetimes = "warn" rust.unused_lifetimes = "warn" # TODO: reenable # rust.unsafe_op_in_unsafe_fn = "deny" +rust.unexpected_cfgs = { level = "warn", check-cfg = [ + # FIXME: https://github.com/hyperledger/iroha/issues/3102 + 'cfg(feature, values("ffi_import"))', + # FIXME: was never supported + 'cfg(coverage)' +] } # pedantic clippy.pedantic = { level = "warn", priority = -1 } diff --git a/crates/iroha_crypto/src/lib.rs b/crates/iroha_crypto/src/lib.rs index 6c15aa8ad2e..939c707d3a4 100755 --- a/crates/iroha_crypto/src/lib.rs +++ b/crates/iroha_crypto/src/lib.rs @@ -995,7 +995,6 @@ mod ffi { } // NOTE: Makes sure that only one `dealloc` is exported per generated dynamic library - #[cfg(any(crate_type = "dylib", crate_type = "cdylib"))] #[cfg(all(feature = "ffi_export", not(feature = "ffi_import")))] mod dylib { #[cfg(not(feature = "std"))] diff --git a/crates/iroha_data_model/src/lib.rs b/crates/iroha_data_model/src/lib.rs index b0f296f2845..a74a339f478 100644 --- a/crates/iroha_data_model/src/lib.rs +++ b/crates/iroha_data_model/src/lib.rs @@ -468,7 +468,6 @@ mod ffi { } // NOTE: Makes sure that only one `dealloc` is exported per generated dynamic library - #[cfg(any(crate_type = "dylib", crate_type = "cdylib"))] #[cfg(all(feature = "ffi_export", not(feature = "ffi_import")))] mod dylib { #[cfg(not(feature = "std"))] diff --git a/crates/iroha_derive/tests/ui.rs b/crates/iroha_derive/tests/ui.rs index f85c931983c..f15eb517c30 100644 --- a/crates/iroha_derive/tests/ui.rs +++ b/crates/iroha_derive/tests/ui.rs @@ -1,4 +1,3 @@ -#![cfg(not(coverage))] use trybuild::TestCases; #[test] diff --git a/crates/iroha_primitives/src/const_vec.rs b/crates/iroha_primitives/src/const_vec.rs index 54f7c628b28..3cf7287cd5c 100644 --- a/crates/iroha_primitives/src/const_vec.rs +++ b/crates/iroha_primitives/src/const_vec.rs @@ -98,7 +98,7 @@ impl<'a, T> IntoIterator for &'a ConstVec { type IntoIter = <&'a [T] as IntoIterator>::IntoIter; fn into_iter(self) -> Self::IntoIter { - self.0.into_iter() + self.0.iter() } } diff --git a/crates/iroha_telemetry/Cargo.toml b/crates/iroha_telemetry/Cargo.toml index 0688b839cf7..99dea48ec01 100644 --- a/crates/iroha_telemetry/Cargo.toml +++ b/crates/iroha_telemetry/Cargo.toml @@ -15,7 +15,7 @@ workspace = true # Should not be enabled on production builds. dev-telemetry = [] # Export Prometheus metrics. See https://prometheus.io/. -metric-instrumentation = [] +metric-instrumentation = ["iroha_telemetry_derive/metric-instrumentation"] [dependencies] iroha_telemetry_derive = { path = "../iroha_telemetry_derive" } diff --git a/crates/iroha_telemetry_derive/Cargo.toml b/crates/iroha_telemetry_derive/Cargo.toml index 3a4f7e9fe21..be453c38274 100644 --- a/crates/iroha_telemetry_derive/Cargo.toml +++ b/crates/iroha_telemetry_derive/Cargo.toml @@ -18,6 +18,10 @@ is-it-maintained-issue-resolution = { repository = "https://github.com/hyperledg is-it-maintained-open-issues = { repository = "https://github.com/hyperledger/iroha" } maintenance = { status = "actively-developed" } +[features] +# FIXME: it doesn't work https://github.com/hyperledger/iroha/issues/5134 +metric-instrumentation = [] + [dependencies] syn = { workspace = true } quote = { workspace = true } diff --git a/crates/iroha_telemetry_derive/src/lib.rs b/crates/iroha_telemetry_derive/src/lib.rs index 15c434f4598..d982766f733 100644 --- a/crates/iroha_telemetry_derive/src/lib.rs +++ b/crates/iroha_telemetry_derive/src/lib.rs @@ -1,6 +1,9 @@ //! Attribute-like macro for instrumenting `isi` for `prometheus` //! metrics. See [`macro@metrics`] for more details. +// FIXME +#![allow(unused)] + use iroha_macro_utils::Emitter; use manyhow::{emit, manyhow, Result}; use proc_macro2::TokenStream; @@ -181,12 +184,16 @@ pub fn metrics(attr: TokenStream, item: TokenStream) -> TokenStream { return emitter.finish_token_stream(); }; - let result = impl_metrics(&mut emitter, &metric_specs, &func); + let result = impl_metrics(&mut emitter, metric_specs, &func); emitter.finish_token_stream_with(result) } -fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) -> TokenStream { +fn impl_metrics( + emitter: &mut Emitter, + #[cfg_attr(not(feature = "metric-instrumentation"), allow(unused))] specs: MetricSpecs, + func: &syn::ItemFn, +) -> TokenStream { let syn::ItemFn { attrs, vis, @@ -224,7 +231,8 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) // Again this may seem fragile, but if we move the metrics from // the `WorldStateView`, we'd need to refactor many things anyway - let _metric_arg_ident = match arg_metrics(&sig.inputs) { + #[cfg_attr(not(feature = "metric-instrumentation"), allow(unused_variables))] + let metric_arg_ident = match arg_metrics(&sig.inputs) { Ok(ident) => ident, Err(args) => { emit!( @@ -237,9 +245,9 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) }; #[cfg(feature = "metric-instrumentation")] - let res = { - let (totals, successes, times) = write_metrics(_metric_arg_ident, _specs); - quote!( + { + let (totals, successes, times) = write_metrics(metric_arg_ident, specs); + return quote!( #(#attrs)* #vis #sig { let _closure = || #block; let started_at = std::time::Instant::now(); @@ -256,14 +264,14 @@ fn impl_metrics(emitter: &mut Emitter, _specs: &MetricSpecs, func: &syn::ItemFn) }; #[cfg(not(feature = "metric-instrumentation"))] - let res = quote!( + quote!( #(#attrs)* #vis #sig { #block } - ); - res + ) } +// FIXME: metrics were removed https://github.com/hyperledger/iroha/issues/5134 #[cfg(feature = "metric-instrumentation")] fn write_metrics( metric_arg_ident: proc_macro2::Ident, @@ -271,19 +279,19 @@ fn write_metrics( ) -> (TokenStream, TokenStream, TokenStream) { let inc_metric = |spec: &MetricSpec, kind: &str| { quote!( - #metric_arg_ident - .metrics - .isi - .with_label_values( &[#spec, #kind ]).inc(); + // #metric_arg_ident + // .metrics + // .isi + // .with_label_values( &[#spec, #kind ]).inc(); ) }; let track_time = |spec: &MetricSpec| { quote!( - #metric_arg_ident - .metrics - .isi_times - .with_label_values( &[#spec]) - .observe(started_at.elapsed().as_millis() as f64); + // #metric_arg_ident + // .metrics + // .isi_times + // .with_label_values( &[#spec]) + // .observe(started_at.elapsed().as_millis() as f64); ) }; let totals: TokenStream = specs diff --git a/wasm_samples/default_executor/src/lib.rs b/wasm_samples/default_executor/src/lib.rs index 9fc90729682..a02e9aa3061 100644 --- a/wasm_samples/default_executor/src/lib.rs +++ b/wasm_samples/default_executor/src/lib.rs @@ -2,7 +2,6 @@ #![no_std] -extern crate alloc; #[cfg(not(test))] extern crate panic_halt; diff --git a/wasm_samples/executor_with_migration_fail/src/lib.rs b/wasm_samples/executor_with_migration_fail/src/lib.rs index 169a91e7882..9e269c6b56f 100644 --- a/wasm_samples/executor_with_migration_fail/src/lib.rs +++ b/wasm_samples/executor_with_migration_fail/src/lib.rs @@ -2,7 +2,6 @@ #![no_std] -extern crate alloc; #[cfg(not(test))] extern crate panic_halt; diff --git a/wasm_samples/query_assets_and_save_cursor/src/lib.rs b/wasm_samples/query_assets_and_save_cursor/src/lib.rs index e4a03191a6e..83e483d4ede 100644 --- a/wasm_samples/query_assets_and_save_cursor/src/lib.rs +++ b/wasm_samples/query_assets_and_save_cursor/src/lib.rs @@ -5,8 +5,6 @@ #[cfg(not(test))] extern crate panic_halt; -extern crate alloc; - use dlmalloc::GlobalDlmalloc; use iroha_smart_contract::{ data_model::query::{