Skip to content

Commit

Permalink
Updated lint configuration for Rust 1.81
Browse files Browse the repository at this point in the history
  - Added new lints for Rust 1.81.

  - Removed the "reasons" feature now that lint_reasons is stable, and
    converted all lint exceptions to the stable syntax. Also changed
    them to use expect in most places (except macros).

  - Added missing reasons to lint exceptions in tests.

  - Updated according to other lint warnings: imported Error from core
    instead of std, as it is now available there; and made
    UnpackedResponse::new_from_parts() into a const function.
  • Loading branch information
danwilliams committed Sep 5, 2024
1 parent 5c3e157 commit cfc037a
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 231 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ unwrap_used = "deny"
wildcard_enum_match_arm = "deny"
## Warn
absolute_paths = "warn"
allow_attributes = "warn"
arithmetic_side_effects = "warn"
as_underscore = "warn"
decimal_literal_representation = "warn"
default_numeric_fallback = "warn"
deref_by_slicing = "warn"
empty_drop = "warn"
field_scoped_visibility_modifiers = "warn"
filetype_is_file = "warn"
if_then_some_else_none = "warn"
indexing_slicing = "warn"
Expand Down
6 changes: 3 additions & 3 deletions crates/rubedo-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
// Global configuration

// Customisations of the standard linting configuration
#![allow(clippy::expect_used)] // Okay in a proc macro
#![allow(clippy::items_after_test_module)] // Not needed with separated tests
#![allow(clippy::panic)] // Okay in a proc macro
#![allow(clippy::expect_used, reason = "Okay in a proc macro")]
#![allow(clippy::items_after_test_module, reason = "Not needed with separated tests")]
#![allow(clippy::panic, reason = "Also okay in a proc macro")]



Expand Down
3 changes: 2 additions & 1 deletion crates/rubedo-macros/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unused_crate_dependencies)]
#![allow(unused_crate_dependencies, reason = "Creates a lot of noise")]

// Lints specifically disabled for integration tests
#![cfg_attr(test, allow(
Expand All @@ -21,6 +21,7 @@
clippy::tests_outside_test_module,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "Not useful in integration tests"
))]


Expand Down
3 changes: 0 additions & 3 deletions crates/rubedo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ readme = "README.md"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
reasons = []

#==============================[ DEPENDENCIES ]===============================

[dependencies]
Expand Down
76 changes: 24 additions & 52 deletions crates/rubedo/src/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,23 @@ pub trait DurationExt {
/// The [`Duration`] struct stores its value as a number of seconds and
/// nanoseconds, but artificially limits the number of seconds so that the
/// milliseconds will never overflow.
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MAX_SECONDS: i64 = i64::MAX / 1_000;

/// The maximum number of minutes that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MAX_MINUTES: i64 = i64::MAX / 1_000 / 60;

/// The maximum number of hours that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MAX_HOURS: i64 = i64::MAX / 1_000 / 60 / 60;

/// The maximum number of days that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MAX_DAYS: i64 = i64::MAX / 1_000 / 60 / 60 / 24;

/// The maximum number of weeks that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MAX_WEEKS: i64 = i64::MAX / 1_000 / 60 / 60 / 24 / 7;

/// The minimum number of nanoseconds that can be represented by a
Expand Down Expand Up @@ -160,28 +155,23 @@ pub trait DurationExt {
/// The [`Duration`] struct stores its value as a number of seconds and
/// nanoseconds, but artificially limits the number of seconds so that the
/// milliseconds will never overflow.
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MIN_SECONDS: i64 = i64::MIN / 1_000;

/// The minimum number of minutes that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MIN_MINUTES: i64 = i64::MIN / 1_000 / 60;

/// The minimum number of hours that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MIN_HOURS: i64 = i64::MIN / 1_000 / 60 / 60;

/// The minimum number of days that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MIN_DAYS: i64 = i64::MIN / 1_000 / 60 / 60 / 24;

/// The minimum number of weeks that can be represented by a [`Duration`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MIN_WEEKS: i64 = i64::MIN / 1_000 / 60 / 60 / 24 / 7;

/// The units used by [`humanize()`](DurationExt::humanize()). These
Expand Down Expand Up @@ -290,14 +280,8 @@ impl DurationExt for Duration {
let seconds = self.num_seconds();
for &(unit, name) in &Self::UNITS {
if seconds >= unit {
#[cfg_attr( feature = "reasons", allow(clippy::arithmetic_side_effects,
reason = "Precision is not needed here, and unit cannot be zero"
))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::arithmetic_side_effects))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division,
reason = "Precision is not needed here"
))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[expect(clippy::arithmetic_side_effects, reason = "Precision is not needed here, and unit cannot be zero")]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
let count = seconds / unit;
return format!("{} {}{}", count, name, if count == 1 { "" } else { "s" });
}
Expand All @@ -310,8 +294,7 @@ impl DurationExt for Duration {
if !(Self::MIN_NANOSECONDS_FULL..=Self::MAX_NANOSECONDS_FULL).contains(&nanoseconds) {
return None;
}
#[cfg_attr( feature = "reasons", allow(clippy::cast_possible_truncation, reason = "Range is controlled"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::cast_possible_truncation))]
#[expect(clippy::cast_possible_truncation, reason = "Range is controlled")]
if (i128::from(Self::MIN_NANOSECONDS)..=i128::from(Self::MAX_NANOSECONDS)).contains(&nanoseconds) {
Some(Self::nanoseconds(nanoseconds as i64))
} else if nanoseconds < 0 {
Expand All @@ -330,8 +313,7 @@ impl DurationExt for Duration {
if !(Self::MIN_MICROSECONDS_FULL..=Self::MAX_MICROSECONDS_FULL).contains(&microseconds) {
return None;
}
#[cfg_attr( feature = "reasons", allow(clippy::cast_possible_truncation, reason = "Range is controlled"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::cast_possible_truncation))]
#[expect(clippy::cast_possible_truncation, reason = "Range is controlled")]
if (i128::from(Self::MIN_MICROSECONDS)..=i128::from(Self::MAX_MICROSECONDS)).contains(&microseconds) {
Some(Self::microseconds(microseconds as i64))
} else if microseconds < 0 {
Expand Down Expand Up @@ -369,8 +351,7 @@ pub trait MonthsExt {
const MAX_MONTHS: u32 = u32::MAX;

/// The maximum number of years that can be represented by a [`Months`].
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
const MAX_YEARS: u32 = u32::MAX / 12;

// months
Expand Down Expand Up @@ -438,8 +419,7 @@ impl MonthsExt for Months {
}

// num_years
#[cfg_attr( feature = "reasons", allow(clippy::integer_division, reason = "Precision is not needed here"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::integer_division))]
#[expect(clippy::integer_division, reason = "Precision is not needed here")]
fn num_years(&self) -> u32 {
self.as_u32() / 12
}
Expand Down Expand Up @@ -689,8 +669,7 @@ impl NaiveDateExt for NaiveDate {

// days_in_month
fn days_in_month(&self) -> u32 {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::days_in_month_opt(self.year(), self.month()).unwrap()
}

Expand All @@ -701,8 +680,7 @@ impl NaiveDateExt for NaiveDate {

// days_in_year
fn days_in_year(&self) -> u32 {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::days_in_year_opt(self.year()).unwrap()
}

Expand All @@ -713,8 +691,7 @@ impl NaiveDateExt for NaiveDate {

// is_leap_year
fn is_leap_year(&self) -> bool {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::is_leap_year_opt(self.year()).unwrap()
}

Expand All @@ -725,8 +702,7 @@ impl NaiveDateExt for NaiveDate {

// start_of_month
fn start_of_month(&self) -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::start_of_month_opt(self.year(), self.month()).unwrap()
}

Expand All @@ -737,8 +713,7 @@ impl NaiveDateExt for NaiveDate {

// end_of_month
fn end_of_month(&self) -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::end_of_month_opt(self.year(), self.month()).unwrap()
}

Expand All @@ -748,8 +723,7 @@ impl NaiveDateExt for NaiveDate {
// The range of years is controlled by having already validated the date
// by attempting to create it above. This is well within the range of a u32.
// The same applies to the month.
#[cfg_attr( feature = "reasons", allow(clippy::arithmetic_side_effects, reason = "Range is controlled"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::arithmetic_side_effects))]
#[expect(clippy::arithmetic_side_effects, reason = "Range is controlled")]
Self::from_ymd_opt(
if month == 12 { year + 1 } else { year },
if month == 12 { month } else { month + 1 },
Expand All @@ -759,8 +733,7 @@ impl NaiveDateExt for NaiveDate {

// start_of_year
fn start_of_year(&self) -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::start_of_year_opt(self.year()).unwrap()
}

Expand All @@ -771,8 +744,7 @@ impl NaiveDateExt for NaiveDate {

// end_of_year
fn end_of_year(&self) -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::end_of_year_opt(self.year()).unwrap()
}

Expand Down
23 changes: 7 additions & 16 deletions crates/rubedo/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ impl ForceFrom<&[u8]> for $t {
fn force_from(b: &[u8]) -> Self {
let mut array = [0_u8; $s];
let len = b.len().min($s);
#[cfg_attr( feature = "reasons", allow(clippy::indexing_slicing, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::indexing_slicing))]
#[expect(clippy::indexing_slicing, reason = "Infallible")]
array[..len].copy_from_slice(&b[..len]);
Self::from(array)
}
Expand Down Expand Up @@ -995,10 +994,7 @@ impl ByteSized<32> for VerifyingKey {
/// [`VerifyingKey::from_bytes()`](RealVerifyingKey::from_bytes()) instead.
///
fn from_bytes(bytes: [u8; 32]) -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::option_if_let_else,
reason = "Using map_or_else() here would not be as clear, and no more concise"
))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::option_if_let_else))]
#[expect(clippy::option_if_let_else, reason = "Using map_or_else() here would not be as clear, and no more concise")]
match RealVerifyingKey::from_bytes(&bytes) {
Ok(key) => Self { key },
Err(_) => Self::default(),
Expand Down Expand Up @@ -1054,8 +1050,7 @@ impl Debug for VerifyingKey {
impl Default for VerifyingKey {
// default
fn default() -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self { key: RealVerifyingKey::from_bytes(&[0; 32]).unwrap() }
}
}
Expand Down Expand Up @@ -1455,8 +1450,7 @@ impl ForceFrom<&[u8]> for RealSigningKey {
fn force_from(value: &[u8]) -> Self {
let mut array = [0_u8; 32];
let len = value.len().min(32);
#[cfg_attr( feature = "reasons", allow(clippy::indexing_slicing, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::indexing_slicing))]
#[expect(clippy::indexing_slicing, reason = "Infallible")]
array[..len].copy_from_slice(&value[..len]);
Self::from(array)
}
Expand Down Expand Up @@ -1553,8 +1547,7 @@ impl ByteSized<32> for RealVerifyingKey {
/// (which will be default unless this method is specifically called).
///
fn from_bytes(bytes: [u8; 32]) -> Self {
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::from_bytes(&bytes).unwrap_or_else(|_| Self::from_bytes(&[0_u8; 32]).unwrap())
}

Expand Down Expand Up @@ -1604,11 +1597,9 @@ impl ForceFrom<&[u8]> for RealVerifyingKey {
fn force_from(value: &[u8]) -> Self {
let mut array = [0_u8; 32];
let len = value.len().min(32);
#[cfg_attr( feature = "reasons", allow(clippy::indexing_slicing, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::indexing_slicing))]
#[expect(clippy::indexing_slicing, reason = "Infallible")]
array[..len].copy_from_slice(&value[..len]);
#[cfg_attr( feature = "reasons", allow(clippy::unwrap_used, reason = "Infallible"))]
#[cfg_attr(not(feature = "reasons"), allow(clippy::unwrap_used))]
#[expect(clippy::unwrap_used, reason = "Infallible")]
Self::from_bytes(&array).unwrap_or_else(|_| Self::from_bytes(&[0_u8; 32]).unwrap())
}
}
Expand Down
Loading

0 comments on commit cfc037a

Please sign in to comment.