Skip to content

Commit

Permalink
fix: address check-cfg warnings + chores
Browse files Browse the repository at this point in the history
Signed-off-by: 0x009922 <43530070+0x009922@users.noreply.github.com>
  • Loading branch information
0x009922 committed Oct 8, 2024
1 parent 0059c39 commit b009890
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 30 deletions.
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion crates/iroha_crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
1 change: 0 additions & 1 deletion crates/iroha_data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
1 change: 0 additions & 1 deletion crates/iroha_derive/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg(not(coverage))]
use trybuild::TestCases;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_primitives/src/const_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a, T> IntoIterator for &'a ConstVec<T> {
type IntoIter = <&'a [T] as IntoIterator>::IntoIter;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
self.0.iter()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 4 additions & 0 deletions crates/iroha_telemetry_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
44 changes: 26 additions & 18 deletions crates/iroha_telemetry_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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!(
Expand All @@ -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();
Expand All @@ -256,34 +264,34 @@ 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,
specs: MetricSpecs,
) -> (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
Expand Down
1 change: 0 additions & 1 deletion wasm_samples/default_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![no_std]

extern crate alloc;
#[cfg(not(test))]
extern crate panic_halt;

Expand Down
1 change: 0 additions & 1 deletion wasm_samples/executor_with_migration_fail/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![no_std]

extern crate alloc;
#[cfg(not(test))]
extern crate panic_halt;

Expand Down
2 changes: 0 additions & 2 deletions wasm_samples/query_assets_and_save_cursor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#[cfg(not(test))]
extern crate panic_halt;

extern crate alloc;

use dlmalloc::GlobalDlmalloc;
use iroha_smart_contract::{
data_model::query::{
Expand Down

0 comments on commit b009890

Please sign in to comment.