Skip to content

Commit

Permalink
Tune up lints for 1.81 Rust
Browse files Browse the repository at this point in the history
- bump up MSRV to 1.81
  • Loading branch information
tyranron committed Sep 6, 2024
1 parent cfc3b5d commit a1192b5
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <developer@instrumentisto.com>"]
license = "MIT OR Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 14 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
Expand All @@ -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()
}
2 changes: 1 addition & 1 deletion src/recorder/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct Identity;
impl<R> Layer<R> 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
}
Expand Down
8 changes: 5 additions & 3 deletions src/recorder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,11 @@ impl<S, L> Builder<S, L> {
/// );
/// # 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>,
Expand Down
15 changes: 9 additions & 6 deletions src/storage/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 29 additions & 29 deletions src/storage/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<M>(&self, name: &str, description: String)
where
M: metric::Bundled,
<M as metric::Bundled>::Bundle: Clone,
Self: super::Get<Collection<<M as metric::Bundled>::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();
Expand Down Expand Up @@ -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,
Expand All @@ -171,16 +178,6 @@ impl Storage {
+ 'static,
Self: super::Get<Collection<<M as metric::Bundled>::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 _;

Expand Down Expand Up @@ -241,23 +238,26 @@ 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<M>(&self, metric: M) -> prometheus::Result<()>
where
M: metric::Bundled + prometheus::core::Collector,
<M as metric::Bundled>::Bundle:
prometheus::core::Collector + Clone + 'static,
Self: super::Get<Collection<<M as metric::Bundled>::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
Expand Down

0 comments on commit a1192b5

Please sign in to comment.