Skip to content

Commit

Permalink
Remove (and fix) some clippy allows
Browse files Browse the repository at this point in the history
  • Loading branch information
emabee committed Oct 14, 2024
1 parent 2ba5383 commit 2c258ab
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 61 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unpublished]

Remove the RwLock around the color palette.

## [0.29.3] - 2024-10-12

Removed dependency to `glob` by implementing the necessary file searches explicitly,
Expand Down
2 changes: 1 addition & 1 deletion examples/write_writer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(dead_code)]
use flexi_logger::writers::LogWriter;
use std::{
io::{Error, ErrorKind},
Expand All @@ -7,6 +6,7 @@ use std::{

fn main() {}

#[allow(dead_code)]
struct MyWriter<F> {
file: Arc<Mutex<F>>,
}
Expand Down
4 changes: 2 additions & 2 deletions src/deferred_now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ impl<'a> DeferredNow {
Self(None)
}

#[allow(dead_code)]
#[cfg(test)]
#[must_use]
pub(crate) fn new_from_datetime(dt: DateTime<Local>) -> Self {
fn new_from_datetime(dt: DateTime<Local>) -> Self {
Self(Some(dt))
}

Expand Down
4 changes: 3 additions & 1 deletion src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::formats::AdaptiveFormat;
#[cfg(feature = "colors")]
use crate::set_palette;
use crate::{
filter::LogLineFilter,
flexi_logger::FlexiLogger,
Expand Down Expand Up @@ -672,7 +674,7 @@ impl Logger {
/// Several variants of [`FlexiLoggerError`] can occur.
pub fn build(mut self) -> Result<(Box<dyn log::Log>, LoggerHandle), FlexiLoggerError> {
#[cfg(feature = "colors")]
crate::formats::set_palette(self.o_palette.as_deref())?;
set_palette(self.o_palette.as_deref())?;

if self.use_utc {
self.flwb = self.flwb.use_utc();
Expand Down
3 changes: 1 addition & 2 deletions src/logger_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ impl LoggerHandle {
}

/// Replaces the active `LogSpecification`.
#[allow(clippy::missing_panics_doc)]
pub fn set_new_spec(&self, new_spec: LogSpecification) {
self.writers_handle
.set_new_spec(new_spec)
Expand All @@ -151,7 +150,7 @@ impl LoggerHandle {
Ok(())
}

/// Replaces the active `LogSpecification` and pushes the previous one to a Stack.
/// Replaces the active `LogSpecification` and pushes the previous one to a stack.
#[allow(clippy::missing_panics_doc)]
pub fn push_temp_spec(&mut self, new_spec: LogSpecification) {
self.writers_handle
Expand Down
2 changes: 1 addition & 1 deletion src/primary_writer/std_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl StdWriter {
EffectiveWriteMode::BufferDontFlushWith(capacity) => {
InnerStdWriter::Buffered(Mutex::new(BufWriter::with_capacity(capacity, stdstream)))
}
EffectiveWriteMode::BufferAndFlushWith(_, _) => {
EffectiveWriteMode::BufferAndFlushWith(_) => {
unreachable!("Sync InnerStdWriter with own flushing is not implemented")
}
#[cfg(feature = "async")]
Expand Down
3 changes: 1 addition & 2 deletions src/threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ use {
std::{sync::Mutex, thread::JoinHandle},
};

// no clue why we get a warning if this allow is omitted; if we omit the use, we get an error
#[allow(unused_imports)]
#[cfg(feature = "async")]
#[cfg(test)]
use std::io::Write;

#[cfg(feature = "async")]
Expand Down
33 changes: 18 additions & 15 deletions src/trc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ impl LogSpecSubscriber for TraceLogSpecSubscriber {
}
}

#[allow(dead_code)] // not really appropriate, seems to be a bug in clippy
/// Rereads the specfile if it was updated and forwards the update to `tracing`'s filter.
pub struct SpecFileNotifier(Option<Debouncer<RecommendedWatcher>>);
pub struct SpecFileNotifier {
_watcher: Option<Debouncer<RecommendedWatcher>>,
}

/// Set up tracing to write into the specified `FileLogWriter`,
/// and to use the (optionally) specified specfile.
Expand All @@ -166,19 +167,21 @@ pub fn setup_tracing(
.with_filter_reloading();

// Set up specfile watching
let spec_file_notifier = SpecFileNotifier(match o_specfile {
Some(specfile) => {
let reload_handle = Box::new(subscriber_builder.reload_handle());
subscribe_to_specfile(
specfile,
Box::new(move |logspec| {
{ reload_handle.reload(LogSpecAsFilter(logspec)) }.unwrap(/* OK */);
}),
initial_logspec,
)?
}
None => None,
});
let spec_file_notifier = SpecFileNotifier {
_watcher: match o_specfile {
Some(specfile) => {
let reload_handle = Box::new(subscriber_builder.reload_handle());
subscribe_to_specfile(
specfile,
Box::new(move |logspec| {
{ reload_handle.reload(LogSpecAsFilter(logspec)) }.unwrap(/* OK */);
}),
initial_logspec,
)?
}
None => None,
},
};

// Get ready to trace
tracing::subscriber::set_global_default(subscriber_builder.finish())?;
Expand Down
49 changes: 22 additions & 27 deletions src/write_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,6 @@ pub enum WriteMode {
flush_interval: Duration,
},
}

pub(crate) enum EffectiveWriteMode {
Direct,
#[allow(dead_code)] // introduced due to a bug in clippy, should be removed again
BufferAndFlushWith(usize, Duration),
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[cfg(feature = "async")]
AsyncWith {
/// Capacity of the pool for the message buffers.
pool_capa: usize,
/// Capacity of an individual message buffer.
message_capa: usize,
/// The interval for flushing the output.
///
/// With `Duration::ZERO` flushing is suppressed.
flush_interval: Duration,
},
BufferDontFlushWith(usize),
}

impl WriteMode {
pub(crate) fn inner(&self) -> EffectiveWriteMode {
match *self {
Expand All @@ -144,12 +124,9 @@ impl WriteMode {
Self::BufferDontFlushWith(duration) => {
EffectiveWriteMode::BufferDontFlushWith(duration)
}
Self::BufferAndFlush => EffectiveWriteMode::BufferAndFlushWith(
DEFAULT_BUFFER_CAPACITY,
DEFAULT_FLUSH_INTERVAL,
),
Self::BufferAndFlushWith(bufsize, duration) => {
EffectiveWriteMode::BufferAndFlushWith(bufsize, duration)
Self::BufferAndFlush => EffectiveWriteMode::BufferAndFlushWith(DEFAULT_BUFFER_CAPACITY),
Self::BufferAndFlushWith(bufsize, _duration) => {
EffectiveWriteMode::BufferAndFlushWith(bufsize)
}
#[cfg(feature = "async")]
Self::Async => EffectiveWriteMode::AsyncWith {
Expand Down Expand Up @@ -198,7 +175,7 @@ impl WriteMode {
pub(crate) fn buffersize(&self) -> Option<usize> {
match self.inner() {
EffectiveWriteMode::Direct => None,
EffectiveWriteMode::BufferAndFlushWith(bufsize, _)
EffectiveWriteMode::BufferAndFlushWith(bufsize)
| EffectiveWriteMode::BufferDontFlushWith(bufsize) => Some(bufsize),
#[cfg(feature = "async")]
EffectiveWriteMode::AsyncWith {
Expand Down Expand Up @@ -227,3 +204,21 @@ impl WriteMode {
}
}
}

pub(crate) enum EffectiveWriteMode {
Direct,
BufferAndFlushWith(usize),
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
#[cfg(feature = "async")]
AsyncWith {
/// Capacity of the pool for the message buffers.
pool_capa: usize,
/// Capacity of an individual message buffer.
message_capa: usize,
/// The interval for flushing the output.
///
/// With `Duration::ZERO` flushing is suppressed.
flush_interval: Duration,
},
BufferDontFlushWith(usize),
}
2 changes: 1 addition & 1 deletion src/writers/file_log_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl FileLogWriter {
) -> FileLogWriter {
let state_handle = match state.config().write_mode.inner() {
EffectiveWriteMode::Direct
| EffectiveWriteMode::BufferAndFlushWith(_, _)
| EffectiveWriteMode::BufferAndFlushWith(_)
| EffectiveWriteMode::BufferDontFlushWith(_) => {
StateHandle::new_sync(state, format_function)
}
Expand Down
4 changes: 1 addition & 3 deletions src/writers/file_log_writer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,8 @@ impl State {
} else {
let fmt = InfixFormat::custom(ts_fmt);
let ts = latest_timestamp_file(&self.config, !self.config.append, &fmt);
let naming_state = NamingState::Timestamps(ts, None, fmt.clone());
let infix = infix_from_timestamp(&ts, self.config.use_utc, &fmt);
(naming_state, infix)
(NamingState::Timestamps(ts, None, fmt), infix)
}
}
Naming::Numbers => (
Expand Down Expand Up @@ -591,7 +590,6 @@ fn validate_logs_in_file(
assert!(buf.is_empty(), "Found more log lines than expected: {buf} ");
}

#[allow(clippy::type_complexity)]
fn open_log_file(
config: &FileLogWriterConfig,
o_infix: Option<&str>,
Expand Down
2 changes: 1 addition & 1 deletion src/writers/file_log_writer/state_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl StateHandle {
}
}

#[allow(clippy::unnecessary_wraps)]
#[allow(clippy::unnecessary_wraps)] // necessary if not compiled with feature = "async"
#[inline]
pub(super) fn write(&self, now: &mut DeferredNow, record: &Record) -> std::io::Result<()> {
match &self {
Expand Down
10 changes: 8 additions & 2 deletions src/writers/syslog/formats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use log::Record;
/// Default way of writing the message to the syslog.
///
/// Just uses the `Display` implementation of `record.args()`.
#[allow(clippy::missing_errors_doc)]
///
/// # Errors
///
/// `std:io::Error` from writing to the given output stram.
pub fn syslog_default_format(
w: &mut dyn std::io::Write,
_now: &mut DeferredNow,
Expand All @@ -15,7 +18,10 @@ pub fn syslog_default_format(

/// Similar to `syslog_default_format`, but inserts the thread name in the beginning of the message,
/// encapsulated in square brackets.
#[allow(clippy::missing_errors_doc)]
///
/// # Errors
///
/// `std:io::Error` from writing to the given output stram.
pub fn syslog_format_with_thread(
w: &mut dyn std::io::Write,
_now: &mut DeferredNow,
Expand Down
1 change: 0 additions & 1 deletion tests/test_error_channel_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ fn controller() {
fn parent(panic: bool) {
let progpath = std::env::args().next().unwrap();
// spawn child and terminate directly, thus destroying the child's stderr
#[allow(clippy::zombie_processes)]
Command::new(progpath)
.env(CTRL_INDEX, if panic { "child_panic" } else { "child" })
.stdout(Stdio::null())
Expand Down
2 changes: 0 additions & 2 deletions tests/test_multi_threaded_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ fn multi_threaded() {
verify the log"
);

// clippy ignores the Drop implementation of the inner log handle :-(
#[allow(clippy::redundant_clone)]
let logger2 = logger.clone();

let cond_sync = CondSync::new(0_usize);
Expand Down

0 comments on commit 2c258ab

Please sign in to comment.