From a1192b5d1d7d6069b82d10f71d7fc4e0583897c0 Mon Sep 17 00:00:00 2001 From: tyranron Date: Fri, 6 Sep 2024 18:01:08 +0300 Subject: [PATCH] Tune up lints for 1.81 Rust - bump up MSRV to 1.81 --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 14 ++++++++++ Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 20 +++++++++----- src/recorder/layer.rs | 2 +- src/recorder/mod.rs | 8 +++--- src/storage/immutable.rs | 15 ++++++----- src/storage/mutable.rs | 58 ++++++++++++++++++++-------------------- 9 files changed, 75 insertions(+), 48 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8f2439..e46711e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: strategy: fail-fast: false matrix: - msrv: ["1.72.0"] + msrv: ["1.81.0"] os: ["ubuntu", "macOS", "windows"] runs-on: ${{ matrix.os }}-latest steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e7de5..bd445f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ All user visible changes to this project will be documented in this file. This p +## [0.8.0] · 2024-??-?? (unreleased) +[0.8.0]: /../../tree/v0.8.0 + +[Diff](/../../compare/v0.7.0...v0.8.0) + +### BC Breaks + +- Bumped up [MSRV] to 1.81 because for `#[expect]` attribute usage. ([todo]) + +[todo]: /../../commit/todo + + + + ## [0.7.0] · 2024-05-30 [0.7.0]: /../../tree/v0.7.0 diff --git a/Cargo.toml b/Cargo.toml index a443297..e70da45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "metrics-prometheus" version = "0.7.0" edition = "2021" -rust-version = "1.72" +rust-version = "1.81" description = "`prometheus` backend for `metrics` crate." authors = ["Instrumentisto Team "] license = "MIT OR Apache-2.0" diff --git a/README.md b/README.md index 56c5e5d..d1fde04 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ ================================= [![crates.io](https://img.shields.io/crates/v/metrics-prometheus.svg "crates.io")](https://crates.io/crates/metrics-prometheus) -[![Rust 1.72+](https://img.shields.io/badge/rustc-1.72+-lightgray.svg "Rust 1.72+")](https://blog.rust-lang.org/2023/08/24/Rust-1.72.0.html) +[![Rust 1.81+](https://img.shields.io/badge/rustc-1.81+-lightgray.svg "Rust 1.81+")](https://blog.rust-lang.org/2024/09/05/Rust-1.81.0.html) [![Unsafe Forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg "Unsafe forbidden")](https://github.com/rust-secure-code/safety-dance) [![CI](https://github.com/instrumentisto/metrics-prometheus-rs/workflows/CI/badge.svg?branch=main "CI")](https://github.com/instrumentisto/metrics-prometheus-rs/actions?query=workflow%3ACI+branch%3Amain) [![Rust docs](https://docs.rs/metrics-prometheus/badge.svg "Rust docs")](https://docs.rs/metrics-prometheus) diff --git a/src/lib.rs b/src/lib.rs index 86be351..fe195a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,10 +51,13 @@ #![forbid(non_ascii_idents, unsafe_code)] #![warn( clippy::absolute_paths, + clippy::allow_attributes, + clippy::allow_attributes_without_reason, clippy::as_conversions, clippy::as_ptr_cast_mut, clippy::assertions_on_result_states, clippy::branches_sharing_code, + clippy::cfg_not_test, clippy::clear_with_drain, clippy::clone_on_ref_ptr, clippy::collection_is_never_read, @@ -125,6 +128,7 @@ clippy::rest_pat_in_fully_bound_structs, clippy::same_name_method, clippy::semicolon_inside_block, + clippy::set_contains_or_insert, clippy::shadow_unrelated, clippy::significant_drop_in_scrutinee, clippy::significant_drop_tightening, @@ -236,9 +240,11 @@ pub fn try_install_freezable( /// /// If the [`Recorder`] fails to be installed with the /// [`metrics::set_global_recorder()`]. -// We do intentionally omit `#[must_use]` here, as we don't want to force -// library users using the returned `Recorder` directly. -#[allow(clippy::must_use_candidate)] // intentional +#[expect( // intentional + clippy::must_use_candidate, + reason = "`#[must_use]` is omitted here, to avoid forcing library users \ + using the returned `Recorder` directly" +)] pub fn install() -> Recorder { Recorder::builder().build_and_install() } @@ -251,9 +257,11 @@ pub fn install() -> Recorder { /// /// If the [`FreezableRecorder`] fails to be installed with the /// [`metrics::set_global_recorder()`]. -// We do intentionally omit `#[must_use]` here, as we don't want to force -// library users using the returned `FreezableRecorder` directly. -#[allow(clippy::must_use_candidate)] // intentional +#[expect( // intentional + clippy::must_use_candidate, + reason = "`#[must_use]` is omitted here, to avoid forcing library users \ + using the returned `Recorder` directly" +)] pub fn install_freezable() -> FreezableRecorder { Recorder::builder().build_freezable_and_install() } diff --git a/src/recorder/layer.rs b/src/recorder/layer.rs index bc3cbd1..a1b560a 100644 --- a/src/recorder/layer.rs +++ b/src/recorder/layer.rs @@ -14,7 +14,7 @@ pub struct Identity; impl Layer for Identity { type Output = R; - #[allow(clippy::renamed_function_params)] // impl related + #[expect(clippy::renamed_function_params, reason = "impl related")] fn layer(&self, itself: R) -> R { itself } diff --git a/src/recorder/mod.rs b/src/recorder/mod.rs index 13b1e81..0ef6d15 100644 --- a/src/recorder/mod.rs +++ b/src/recorder/mod.rs @@ -557,9 +557,11 @@ impl Builder { /// ); /// # Ok::<_, prometheus::Error>(()) /// ``` - // TODO: Anonymous lifetimes in `impl Trait` are unstable. - // Try remove on Rust 1.81 upgrade. - #[allow(single_use_lifetimes)] + // TODO: Try remove on Rust 1.82 upgrade. + #[expect( // anonymous lifetimes in `impl Trait` are unstable + single_use_lifetimes, + reason = "anonymous lifetimes in `impl Trait` are unstable" + )] pub fn with_registry<'r>( mut self, registry: impl IntoCow<'r, prometheus::Registry>, diff --git a/src/storage/immutable.rs b/src/storage/immutable.rs index 694feb0..d4c59d8 100644 --- a/src/storage/immutable.rs +++ b/src/storage/immutable.rs @@ -125,19 +125,22 @@ impl Storage { } } -// PANIC: `RwLock` usage is fully panic-safe inside, so the `impl` is -// infallible, in fact. -#[allow(clippy::fallible_impl_from)] // intentional +#[expect( // intentional + clippy::fallible_impl_from, + reason = "`RwLock` usage is fully panic-safe inside, so the `impl` is \ + infallible, in fact" +)] impl From<&super::mutable::Storage> for Storage { /// Creates a new immutable [`Storage`] by [draining] the referred /// [`mutable::Storage`] and leaving it empty. /// /// [`mutable::Storage`]: super::mutable::Storage /// [draining]: HashMap::drain + #[expect( // intentional + clippy::unwrap_used, + reason = "`RwLock` usage is fully panic-safe here" + )] fn from(mutable: &super::mutable::Storage) -> Self { - // PANIC: `RwLock` usage is fully panic-safe here. - #![allow(clippy::unwrap_used)] // intentional - Self { counters: mutable .counters diff --git a/src/storage/mutable.rs b/src/storage/mutable.rs index 1bb4d49..5e96c6c 100644 --- a/src/storage/mutable.rs +++ b/src/storage/mutable.rs @@ -107,21 +107,17 @@ impl Storage { /// [`metrics::Recorder::describe_histogram()`] implementations. /// /// [`help` description]: prometheus::proto::MetricFamily::get_help + #[expect( // intentional + clippy::missing_panics_doc, + clippy::unwrap_used, + reason = "`RwLock` usage is fully panic-safe here" + )] pub fn describe(&self, name: &str, description: String) where M: metric::Bundled, ::Bundle: Clone, Self: super::Get::Bundle>>, { - // PANIC: `RwLock` usage is fully panic-safe here. - #![allow( // intentional - clippy::missing_panics_doc, - clippy::unwrap_in_result, - clippy::unwrap_used - )] - // Intentionally, see the comment below on a `write_storage`. - #![allow(clippy::significant_drop_tightening)] // intentional - use super::Get as _; let read_storage = self.collection().read().unwrap(); @@ -158,6 +154,17 @@ impl Storage { /// /// [`metrics::Registry`]: metrics_util::registry::Registry /// [`metrics::registry::Storage`]: metrics_util::registry::Storage + #[expect( // intentional + clippy::unwrap_in_result, + clippy::unwrap_used, + reason = "`RwLock` usage is fully panic-safe here (considering the \ + `prometheus::Registry::register()` does not)" + )] + #[expect( // intentional + clippy::significant_drop_tightening, + reason = "write lock on `storage` is intentionally held till the end \ + of the scope, to perform all the operations atomically" + )] fn register<'k, M>( &self, key: &'k metrics::Key, @@ -171,16 +178,6 @@ impl Storage { + 'static, Self: super::Get::Bundle>>, { - // PANIC: `RwLock` usage is panic-safe here (considering the - // `prometheus::Registry::register()` does not). - #![allow( // intentional - clippy::missing_panics_doc, - clippy::unwrap_in_result, - clippy::unwrap_used - )] - // Intentionally, see the comment below on a `storage`. - #![allow(clippy::significant_drop_tightening)] // intentional - use super::Get as _; use metric::Bundle as _; @@ -241,6 +238,19 @@ impl Storage { /// provided `metric`. /// /// [`metrics::registry::Storage`]: metrics_util::registry::Storage + #[expect( // intentional + clippy::missing_panics_doc, + clippy::unwrap_in_result, + clippy::unwrap_used, + reason = "`RwLock` usage is fully panic-safe here (considering the \ + `prometheus::Registry::register()` does not)" + )] + #[expect( // intentional + clippy::significant_drop_tightening, + reason = "write lock on `storage` is intentionally held till the end \ + of the scope, to perform the registration in \ + `prometheus::Registry` exclusively" + )] pub fn register_external(&self, metric: M) -> prometheus::Result<()> where M: metric::Bundled + prometheus::core::Collector, @@ -248,16 +258,6 @@ impl Storage { prometheus::core::Collector + Clone + 'static, Self: super::Get::Bundle>>, { - // PANIC: `RwLock` usage is panic-safe here (considering the - // `prometheus::Registry::register()` does not). - #![allow( // intentional - clippy::missing_panics_doc, - clippy::unwrap_in_result, - clippy::unwrap_used - )] - // Intentionally, see the comment below on a `storage`. - #![allow(clippy::significant_drop_tightening)] // intentional - use super::Get as _; let name = metric