Skip to content

Commit

Permalink
Replace allow attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann committed Oct 15, 2024
1 parent 62acd14 commit c1e033d
Show file tree
Hide file tree
Showing 29 changed files with 51 additions and 66 deletions.
2 changes: 1 addition & 1 deletion libs/error-stack/src/compat/anyhow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<T> IntoReportCompat for core::result::Result<T, AnyhowError> {
.map(ToString::to_string)
.collect::<alloc::vec::Vec<_>>();

#[cfg_attr(not(feature = "std"), allow(unused_mut))]
#[cfg_attr(not(feature = "std"), expect(unused_mut))]
let mut report: Report<AnyhowError> =
Report::from_frame(Frame::from_anyhow(anyhow, alloc::boxed::Box::new([])));

Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::Report;
pub trait Context: fmt::Display + fmt::Debug + Send + Sync + 'static {
/// Provide values which can then be requested by [`Report`].
#[cfg(nightly)]
#[allow(unused_variables)]
#[expect(unused_variables)]
fn provide<'a>(&'a self, request: &mut Request<'a>) {}

/// Returns the source of the error, if any.
Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/src/ext/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ macro_rules! impl_ext {
{
type Output = ($($output),*, T);

#[allow(non_snake_case, clippy::min_ident_chars)]
#[expect(non_snake_case, clippy::min_ident_chars)]
fn try_collect(self) -> Result<Self::Output, [Context]> {
let ($($type),*, result) = self;
let prefix = ($($type,)*).try_collect();
Expand Down
4 changes: 1 addition & 3 deletions libs/error-stack/src/fmt/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// implementation: `pub(crate)` and `pub`.
#![cfg_attr(not(feature = "std"), allow(unreachable_pub))]

#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::{boxed::Box, string::String, vec::Vec};
use core::{any::TypeId, mem};

Expand Down Expand Up @@ -421,7 +420,7 @@ fn into_boxed_hook<T: Send + Sync + 'static>(
/// [`Display`]: core::fmt::Display
/// [`Debug`]: core::fmt::Debug
/// [`.insert()`]: Hooks::insert
#[allow(clippy::field_scoped_visibility_modifiers)]
#[expect(clippy::field_scoped_visibility_modifiers)]
pub(crate) struct Hooks {
// We use `Vec`, instead of `HashMap` or `BTreeMap`, so that ordering is consistent with the
// insertion order of types.
Expand Down Expand Up @@ -455,7 +454,6 @@ impl Hooks {
mod default {
#[cfg(any(feature = "backtrace", feature = "spantrace"))]
use alloc::format;
#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::string::ToString;
use core::{
panic::Location,
Expand Down
17 changes: 12 additions & 5 deletions libs/error-stack/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,9 @@ mod hook;
mod location;
mod r#override;

use alloc::collections::VecDeque;
#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::{
borrow::ToOwned,
collections::VecDeque,
format,
string::{String, ToString},
vec,
Expand Down Expand Up @@ -586,7 +585,12 @@ enum PreparedInstruction<'a> {
impl Instruction {
// Reason: the match arms are the same intentionally, this makes it more clean which variant
// emits which and also keeps it nicely formatted.
#[allow(clippy::match_same_arms)]
#[expect(
clippy::match_same_arms,
reason = "the match arms are the same intentionally, this makes it more clean which \
variant
// emits which and also keeps it nicely formatted."
)]
fn prepare(&self) -> PreparedInstruction {
match self {
Self::Value { value, style } => PreparedInstruction::Content(value, style),
Expand Down Expand Up @@ -825,7 +829,10 @@ impl Opaque {
}
}

#[allow(clippy::needless_pass_by_ref_mut)]
#[cfg_attr(
not(any(feature = "std", feature = "hooks")),
expect(clippy::needless_pass_by_ref_mut)
)]
fn debug_attachments_invoke<'a>(
frames: impl IntoIterator<Item = &'a Frame>,
config: &mut Config,
Expand Down Expand Up @@ -1090,7 +1097,7 @@ impl<C: ?Sized> Debug for Report<C> {
let color = config.color_mode();
let charset = config.charset();

#[cfg_attr(not(any(feature = "std", feature = "hooks")), allow(unused_mut))]
#[cfg_attr(not(any(feature = "std", feature = "hooks")), expect(unused_mut))]
let mut lines = self
.current_frames_unchecked()
.iter()
Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/src/frame/frame_impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::boxed::Box;
#[cfg(nightly)]
use core::error::{Error, Request};
Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/src/frame/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod frame_impl;
mod kind;

#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::boxed::Box;
#[cfg(nightly)]
use core::error::{self, Error};
Expand Down
4 changes: 1 addition & 3 deletions libs/error-stack/src/hook/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::boxed::Box;
use alloc::collections::BTreeMap;
use alloc::{boxed::Box, collections::BTreeMap};
use core::any::{Any, TypeId};

pub(crate) type Storage = BTreeMap<TypeId, BTreeMap<TypeId, Box<dyn Any>>>;
Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/src/hook/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub(crate) mod context;

#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::vec::Vec;

use crate::{
Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/src/iter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Iterators over [`Frame`]s.

#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::{vec, vec::Vec};
#[cfg(nightly)]
use core::marker::PhantomData;
Expand Down
2 changes: 1 addition & 1 deletion libs/error-stack/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ pub use self::{
pub use self::{future::FutureExt, result::ResultExt};

#[cfg(test)]
#[allow(dead_code)]
#[expect(dead_code)]
mod tests {

use core::mem;
Expand Down
9 changes: 3 additions & 6 deletions libs/error-stack/src/report.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::{boxed::Box, vec, vec::Vec};
use core::{error::Error, fmt, marker::PhantomData, mem, panic::Location};
#[cfg(feature = "backtrace")]
Expand Down Expand Up @@ -241,14 +240,14 @@ use crate::{
/// # }
/// ```
#[must_use]
#[allow(clippy::field_scoped_visibility_modifiers)]
#[expect(clippy::field_scoped_visibility_modifiers)]
pub struct Report<C: ?Sized> {
// The vector is boxed as this implies a memory footprint equal to a single pointer size
// instead of three pointer sizes. Even for small `Result::Ok` variants, the `Result` would
// still have at least the size of `Report`, even at the happy path. It's unexpected, that
// creating or traversing a report will happen in the hot path, so a double indirection is
// a good trade-off.
#[allow(clippy::box_collection)]
#[expect(clippy::box_collection)]
pub(super) frames: Box<Vec<Frame>>,
_context: PhantomData<fn() -> *const C>,
}
Expand All @@ -263,7 +262,7 @@ impl<C> Report<C> {
/// [`Backtrace` and `SpanTrace` section]: #backtrace-and-spantrace
#[inline]
#[track_caller]
#[allow(clippy::missing_panics_doc)] // Reason: No panic possible
#[expect(clippy::missing_panics_doc)] // Reason: No panic possible
pub fn new(context: C) -> Self
where
C: Context,
Expand Down Expand Up @@ -321,7 +320,6 @@ impl<C> Report<C> {
#[cfg(all(not(nightly), feature = "spantrace"))]
let span_trace = Some(SpanTrace::capture());

#[allow(unused_mut)]
let mut report = Self {
frames: Box::new(vec![frame]),
_context: PhantomData,
Expand Down Expand Up @@ -736,7 +734,6 @@ impl<C> Report<[C]> {
/// error1.push(error2);
/// error1.push(error3);
/// ```
#[allow(clippy::same_name_method)]
pub fn push(&mut self, mut report: Report<C>) {
self.frames.append(&mut report.frames);
}
Expand Down
2 changes: 0 additions & 2 deletions libs/error-stack/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! }
//! ```

#[cfg_attr(feature = "std", allow(unused_imports))]
use alloc::{format, vec, vec::Vec};

use serde::{Serialize, Serializer, ser::SerializeMap};
Expand All @@ -29,7 +28,6 @@ impl Serialize for SerializeAttachment<'_> {
{
let Self(frame) = self;

#[allow(clippy::match_same_arms)]
match frame.kind() {
FrameKind::Context(_) => {
// TODO: for now `Context` is unsupported, upcoming PR will fix via hooks
Expand Down
5 changes: 2 additions & 3 deletions libs/error-stack/src/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Drop for Bomb {

match self.0 {
BombState::Panic => panic!("ReportSink was dropped without being consumed"),
#[allow(clippy::print_stderr)]
#[cfg_attr(not(feature = "tracing"), expect(clippy::print_stderr))]
#[cfg(any(all(not(target_arch = "wasm32"), feature = "std"), feature = "tracing"))]
BombState::Warn(location) => {
#[cfg(feature = "tracing")]
Expand Down Expand Up @@ -548,7 +548,7 @@ mod test {
#[test]
#[should_panic(expected = "without being consumed")]
fn panic_on_unused() {
#[allow(clippy::unnecessary_wraps)]
#[expect(clippy::unnecessary_wraps)]
fn sink() -> Result<(), Report<[TestError]>> {
let mut sink = ReportSink::new_armed();

Expand All @@ -562,7 +562,6 @@ mod test {

#[test]
fn panic_on_unused_with_defuse() {
#[allow(clippy::unnecessary_wraps)]
fn sink() -> Result<(), Report<[TestError]>> {
let mut sink = ReportSink::new_armed();

Expand Down
25 changes: 16 additions & 9 deletions libs/error-stack/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn create_report() -> Report<RootError> {
extern crate alloc;

use core::{any::TypeId, panic::Location};
#[allow(unused_imports)]
#[expect(unused_imports)]
use core::{
fmt,
future::Future,
Expand All @@ -21,13 +21,14 @@ use core::{
};
#[cfg(feature = "backtrace")]
use std::backtrace::Backtrace;
#[allow(unused_imports)]
#[cfg(all(rust_1_80, feature = "std"))]
#[cfg(all(feature = "std", any(feature = "backtrace", feature = "spantrace")))]
use std::sync::LazyLock;

use error_stack::{AttachmentKind, Context, Frame, FrameKind, Report, Result};
#[allow(unused_imports)]
#[cfg(not(all(rust_1_80, feature = "std")))]
#[cfg(all(
not(feature = "std"),
any(feature = "backtrace", feature = "spantrace")
))]
use once_cell::sync::Lazy as LazyLock;
#[cfg(feature = "spantrace")]
use tracing_error::SpanTrace;
Expand Down Expand Up @@ -241,7 +242,7 @@ pub fn remove_builtin_messages<S: AsRef<str>>(
.filter_map(|message| {
let message = message.as_ref();
// Reason: complexity + readability
#[allow(clippy::if_then_some_else_none)]
#[expect(clippy::if_then_some_else_none)]
if message != "Location" && message != "Backtrace" && message != "SpanTrace" {
Some(message.to_owned())
} else {
Expand All @@ -267,8 +268,10 @@ pub fn remove_builtin_frames<E>(report: &Report<E>) -> impl Iterator<Item = &Fra
}

/// Conditionally add two new frames to the count, as these are backtrace and spantrace.
#[allow(unused_mut)]
#[allow(clippy::missing_const_for_fn)]
#[cfg_attr(
not(any(feature = "backtrace", feature = "spantrace")),
expect(clippy::missing_const_for_fn, unused_mut)
)]
pub fn expect_count(mut count: usize) -> usize {
#[cfg(feature = "backtrace")]
if supports_backtrace() {
Expand Down Expand Up @@ -335,7 +338,11 @@ pub fn expect_count(mut count: usize) -> usize {
/// ```
///
/// This is simplified pseudo-code to illustrate how the macro works.
#[allow(unused_macros)]
#[expect(
clippy::allow_attributes,
reason = "It's not possible to avoid this warning"
)]
#[allow(unused_macros, reason = "Only used in some tests")]
macro_rules! assert_kinds {
($report:ident, [
$($pattern:pat_param),*
Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/tests/test_attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[macro_use]
mod common;

#[allow(clippy::wildcard_imports)]
use common::*;
use error_stack::{AttachmentKind, FrameKind, FutureExt, Report, ResultExt};

Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/tests/test_attach_printable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[macro_use]
mod common;

#[allow(clippy::wildcard_imports)]
use common::*;
use error_stack::{AttachmentKind, FrameKind, FutureExt, Report, ResultExt};

Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/tests/test_backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ mod common;

use std::backtrace::Backtrace;

#[allow(clippy::wildcard_imports)]
use common::*;
#[cfg(nightly)]
use error_stack::Report;
Expand Down
1 change: 0 additions & 1 deletion libs/error-stack/tests/test_change_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#[macro_use]
mod common;

#[allow(clippy::wildcard_imports)]
use common::*;
use error_stack::{AttachmentKind, FrameKind, FutureExt, Report, ResultExt};

Expand Down
13 changes: 4 additions & 9 deletions libs/error-stack/tests/test_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod common;
#[cfg(nightly)]
use core::error;

#[allow(clippy::wildcard_imports)]
use common::*;
use error_stack::IntoReportCompat;
#[cfg(all(nightly, feature = "backtrace"))]
Expand Down Expand Up @@ -46,14 +45,13 @@ fn anyhow() {
.attach_printable(PrintableA(0))
.attach_printable(PrintableB(0));

#[allow(unused_mut)]
#[expect(unused_mut)]
let mut report_messages = messages(&report);

let anyhow_report = anyhow
.into_report()
.expect_err("should have returned error");
#[allow(unused_mut)]
let mut anyhow_messages = messages(&anyhow_report);
let anyhow_messages = messages(&anyhow_report);

assert_eq!(
remove_builtin_messages(anyhow_messages.into_iter().rev()),
Expand Down Expand Up @@ -157,13 +155,10 @@ fn eyre() {
let report = create_report()
.attach_printable(PrintableA(0))
.attach_printable(PrintableB(0));

#[allow(unused_mut)]
let mut report_messages = messages(&report);
let report_messages = messages(&report);

let eyre_report = eyre.into_report().expect_err("should have returned error");
#[allow(unused_mut)]
let mut eyre_messages = messages(&eyre_report);
let eyre_messages = messages(&eyre_report);

assert_eq!(
remove_builtin_messages(eyre_messages.into_iter().rev()),
Expand Down
Loading

0 comments on commit c1e033d

Please sign in to comment.