Skip to content

Fix clippy lints #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
blacklisted-names = []
cognitive-complexity-threshold = 100
too-many-arguments-threshold = 8
type-complexity-threshold = 375
2 changes: 1 addition & 1 deletion examples/examples/attrs-basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing_attributes::instrument;
#[inline]
fn suggest_band() -> String {
debug!("Suggesting a band.");
format!("Wild Pink")
String::from("Wild Pink")
}

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> Visit for Count<'a> {
if value > 0 {
counter.fetch_add(value as usize, Ordering::Release);
} else {
counter.fetch_sub((value * -1) as usize, Ordering::Release);
counter.fetch_sub(-value as usize, Ordering::Release);
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/fmt/yak_shave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn shave(yak: usize) -> Result<(), Box<dyn Error + 'static>> {
);
if yak == 3 {
warn!(target: "yak_events", "could not locate yak!");
Err(ShaveError::new(yak, YakError::new("could not locate yak")))?;
return Err(ShaveError::new(yak, YakError::new("could not locate yak")).into());
} else {
trace!(target: "yak_events", "yak shaved successfully");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/hyper-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn echo(req: Request<Body>) -> Instrumented<BoxFut> {
let (rsp_span, fut): (_, BoxFut) = match (req.method(), req.uri().path()) {
// Serve some instructions at /
(&Method::GET, "/") => {
const BODY: &'static str = "Try POSTing data to /echo";
const BODY: &str = "Try POSTing data to /echo";
*response.body_mut() = Body::from(BODY);
(
span!(Level::INFO, "response", body = %(&BODY)),
Expand Down
21 changes: 9 additions & 12 deletions examples/examples/sloggish/sloggish_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ struct ColorLevel<'a>(&'a Level);

impl<'a> fmt::Display for ColorLevel<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
&Level::TRACE => Color::Purple.paint("TRACE"),
&Level::DEBUG => Color::Blue.paint("DEBUG"),
&Level::INFO => Color::Green.paint("INFO "),
&Level::WARN => Color::Yellow.paint("WARN "),
&Level::ERROR => Color::Red.paint("ERROR"),
match *self.0 {
Level::TRACE => Color::Purple.paint("TRACE"),
Level::DEBUG => Color::Blue.paint("DEBUG"),
Level::INFO => Color::Green.paint("INFO "),
Level::WARN => Color::Yellow.paint("WARN "),
Level::ERROR => Color::Red.paint("ERROR"),
}
.fmt(f)
}
Expand Down Expand Up @@ -228,10 +228,7 @@ impl Subscriber for SloggishSubscriber {
let spans = self.spans.lock().unwrap();
let data = spans.get(span_id);
let parent = data.and_then(|span| span.parent.as_ref());
if stack.iter().any(|id| id == span_id) {
// We are already in this span, do nothing.
return;
} else {
if !stack.iter().any(|id| id == span_id) {
let indent = if let Some(idx) = stack
.iter()
.position(|id| parent.map(|p| id == p).unwrap_or(false))
Expand All @@ -249,7 +246,7 @@ impl Subscriber for SloggishSubscriber {
self.print_kvs(&mut stderr, data.kvs.iter().map(|(k, v)| (k, v)), "")
.unwrap();
}
write!(&mut stderr, "\n").unwrap();
writeln!(&mut stderr).unwrap();
}
}

Expand All @@ -270,7 +267,7 @@ impl Subscriber for SloggishSubscriber {
comma: false,
};
event.record(&mut visitor);
write!(&mut visitor.stderr, "\n").unwrap();
writeln!(&mut visitor.stderr).unwrap();
}

#[inline]
Expand Down
8 changes: 4 additions & 4 deletions tracing-attributes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ fn param_names(pat: Pat) -> Box<dyn Iterator<Item = Ident>> {
}
}

fn skips(args: &AttributeArgs) -> Result<HashSet<Ident>, impl ToTokens> {
fn skips(args: &[NestedMeta]) -> Result<HashSet<Ident>, impl ToTokens> {
let mut skips = args.iter().filter_map(|arg| match arg {
NestedMeta::Meta(Meta::List(MetaList {
ref path,
Expand Down Expand Up @@ -299,7 +299,7 @@ fn skips(args: &AttributeArgs) -> Result<HashSet<Ident>, impl ToTokens> {
.collect())
}

fn level(args: &AttributeArgs) -> impl ToTokens {
fn level(args: &[NestedMeta]) -> impl ToTokens {
let mut levels = args.iter().filter_map(|arg| match arg {
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
ref path, ref lit, ..
Expand Down Expand Up @@ -353,7 +353,7 @@ fn level(args: &AttributeArgs) -> impl ToTokens {
}
}

fn target(args: &AttributeArgs) -> impl ToTokens {
fn target(args: &[NestedMeta]) -> impl ToTokens {
let mut levels = args.iter().filter_map(|arg| match arg {
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
ref path, ref lit, ..
Expand All @@ -380,7 +380,7 @@ fn target(args: &AttributeArgs) -> impl ToTokens {
}
}

fn name(args: &AttributeArgs, default_name: String) -> impl ToTokens {
fn name(args: &[NestedMeta], default_name: String) -> impl ToTokens {
let mut names = args.iter().filter_map(|arg| match arg {
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
ref path, ref lit, ..
Expand Down
2 changes: 2 additions & 0 deletions tracing-attributes/tests/support.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[path = "../../tracing/tests/support/mod.rs"]
// path attribute requires referenced module to have same name so allow module inception here
#[allow(clippy::module_inception)]
mod support;
pub use self::support::*;
2 changes: 1 addition & 1 deletion tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ mod test {
fn exit(&self, _: &span::Id) {}
}

with_default(&Dispatch::new(TestSubscriber), || mk_span())
with_default(&Dispatch::new(TestSubscriber), mk_span)
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions tracing-core/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ impl Id {
Id(NonZeroU64::new(u).expect("span IDs must be > 0"))
}

// Allow `into` by-ref since we don't want to impl Copy for Id
#[allow(clippy::wrong_self_convention)]
/// Returns the span's ID as a `u64`.
pub fn into_u64(&self) -> u64 {
self.0.get()
Expand Down
2 changes: 1 addition & 1 deletion tracing-core/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ pub trait Subscriber: 'static {
/// [`drop_span`]: trait.Subscriber.html#method.drop_span
fn try_close(&self, id: span::Id) -> bool {
#[allow(deprecated)]
let _ = self.drop_span(id);
self.drop_span(id);
false
}

Expand Down
2 changes: 1 addition & 1 deletion tracing-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct Fields {
line: field::Field,
}

static FIELD_NAMES: &'static [&'static str] = &[
static FIELD_NAMES: &[&str] = &[
"message",
"log.target",
"log.module_path",
Expand Down
1 change: 1 addition & 0 deletions tracing-macros/examples/factorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn factorial(n: u32) -> u32 {

fn main() {
env_logger::Builder::new().parse("trace").init();
#[allow(deprecated)]
let subscriber = tracing_log::TraceLogger::new();

tracing::subscriber::with_default(subscriber, || dbg!(factorial(4)));
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/benches/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct EnabledSubscriber;
impl tracing::Subscriber for EnabledSubscriber {
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
let _ = span;
Id::from_u64(0xDEADFACE)
Id::from_u64(0xDEAD_FACE)
}

fn event(&self, event: &Event<'_>) {
Expand Down
2 changes: 1 addition & 1 deletion tracing-subscriber/benches/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn bench_new_span(c: &mut Criterion) {

type Group<'a> = criterion::BenchmarkGroup<'a, criterion::measurement::WallTime>;
fn bench_thrpt(c: &mut Criterion, name: &'static str, mut f: impl FnMut(&mut Group<'_>, &usize)) {
const N_SPANS: &'static [usize] = &[1, 10, 50];
const N_SPANS: &[usize] = &[1, 10, 50];

let mut group = c.benchmark_group(name);
for spans in N_SPANS {
Expand Down
10 changes: 5 additions & 5 deletions tracing-subscriber/src/filter/env/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<T> DirectiveSet<T> {
self.directives.is_empty()
}

pub(crate) fn iter<'a>(&'a self) -> btree_set::Iter<'a, T> {
pub(crate) fn iter(&self) -> btree_set::Iter<'_, T> {
self.directives.iter()
}
}
Expand All @@ -417,7 +417,7 @@ impl<T: Match + Ord> DirectiveSet<T> {

pub(crate) fn add(&mut self, directive: T) {
let level = directive.level();
if level > &self.max_level {
if *level > self.max_level {
self.max_level = level.clone();
}
let _ = self.directives.replace(directive);
Expand All @@ -437,7 +437,7 @@ impl<T: Match + Ord> Extend<T> for DirectiveSet<T> {
let max_level = &mut self.max_level;
let ds = iter.into_iter().inspect(|d| {
let level = d.level();
if level > &*max_level {
if *level > *max_level {
*max_level = level.clone();
}
});
Expand All @@ -457,7 +457,7 @@ impl Dynamics {
return Some(f);
}
match base_level {
Some(ref b) if &d.level > b => base_level = Some(d.level.clone()),
Some(ref b) if d.level > *b => base_level = Some(d.level.clone()),
None => base_level = Some(d.level.clone()),
_ => {}
}
Expand Down Expand Up @@ -556,7 +556,7 @@ impl Match for StaticDirective {
if meta.is_event() && !self.field_names.is_empty() {
let fields = meta.fields();
for name in &self.field_names {
if !fields.field(name).is_some() {
if fields.field(name).is_none() {
return false;
}
}
Expand Down
9 changes: 6 additions & 3 deletions tracing-subscriber/src/filter/env/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) enum ValueMatch {
Bool(bool),
U64(u64),
I64(i64),
Pat(MatchPattern),
Pat(Box<MatchPattern>),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -130,7 +130,10 @@ impl FromStr for ValueMatch {
.map(ValueMatch::Bool)
.or_else(|_| s.parse::<u64>().map(ValueMatch::U64))
.or_else(|_| s.parse::<i64>().map(ValueMatch::I64))
.or_else(|_| s.parse::<MatchPattern>().map(ValueMatch::Pat))
.or_else(|_| {
s.parse::<MatchPattern>()
.map(|p| ValueMatch::Pat(Box::new(p)))
})
}
}

Expand Down Expand Up @@ -233,7 +236,7 @@ impl CallsiteMatch {
}

impl SpanMatch {
pub(crate) fn visitor<'a>(&'a self) -> MatchVisitor<'a> {
pub(crate) fn visitor(&self) -> MatchVisitor<'_> {
MatchVisitor { inner: self }
}

Expand Down
10 changes: 5 additions & 5 deletions tracing-subscriber/src/filter/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ mod tests {
#[test]
fn callsite_enabled_no_span_directive() {
let filter = EnvFilter::new("app=debug").with_subscriber(NoSubscriber);
static META: &'static Metadata<'static> = &Metadata::new(
static META: &Metadata<'static> = &Metadata::new(
"mySpan",
"app",
Level::TRACE,
Expand All @@ -424,7 +424,7 @@ mod tests {
#[test]
fn callsite_off() {
let filter = EnvFilter::new("app=off").with_subscriber(NoSubscriber);
static META: &'static Metadata<'static> = &Metadata::new(
static META: &Metadata<'static> = &Metadata::new(
"mySpan",
"app",
Level::ERROR,
Expand All @@ -442,7 +442,7 @@ mod tests {
#[test]
fn callsite_enabled_includes_span_directive() {
let filter = EnvFilter::new("app[mySpan]=debug").with_subscriber(NoSubscriber);
static META: &'static Metadata<'static> = &Metadata::new(
static META: &Metadata<'static> = &Metadata::new(
"mySpan",
"app",
Level::TRACE,
Expand All @@ -461,7 +461,7 @@ mod tests {
fn callsite_enabled_includes_span_directive_field() {
let filter =
EnvFilter::new("app[mySpan{field=\"value\"}]=debug").with_subscriber(NoSubscriber);
static META: &'static Metadata<'static> = &Metadata::new(
static META: &Metadata<'static> = &Metadata::new(
"mySpan",
"app",
Level::TRACE,
Expand All @@ -480,7 +480,7 @@ mod tests {
fn callsite_enabled_includes_span_directive_multiple_fields() {
let filter = EnvFilter::new("app[mySpan{field=\"value\",field2=2}]=debug")
.with_subscriber(NoSubscriber);
static META: &'static Metadata<'static> = &Metadata::new(
static META: &Metadata<'static> = &Metadata::new(
"mySpan",
"app",
Level::TRACE,
Expand Down
11 changes: 8 additions & 3 deletions tracing-subscriber/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub struct Layered<L, I, S = I> {
}

/// A layer that does nothing.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct Identity {
_p: (),
}
Expand Down Expand Up @@ -512,12 +512,16 @@ where
#[cfg(feature = "registry")]
let mut guard = subscriber
.downcast_ref::<Registry>()
.and_then(|registry| Some(registry.start_close(id.clone())));
.map(|registry| registry.start_close(id.clone()));
if self.inner.try_close(id.clone()) {
// If we have a registry's close guard, indicate that the span is
// closing.
#[cfg(feature = "registry")]
guard.as_mut().map(|g| g.is_closing());
{
if let Some(g) = guard.as_mut() {
g.is_closing()
};
}

self.layer.on_close(id, self.ctx());
true
Expand Down Expand Up @@ -924,6 +928,7 @@ pub(crate) mod tests {
struct NopLayer;
impl<S: Subscriber> Layer<S> for NopLayer {}

#[allow(dead_code)]
struct NopLayer2;
impl<S: Subscriber> Layer<S> for NopLayer2 {}

Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ macro_rules! try_lock {
($lock:expr, else $els:expr) => {
match $lock {
Ok(l) => l,
Err(_) if std::thread::panicking() => $els,
Err(_) => panic!("lock poisoned"),
Err(_err) if std::thread::panicking() => $els,
Err(_err) => panic!("lock poisoned"),
}
};
}
Expand Down
10 changes: 5 additions & 5 deletions tracing-subscriber/src/registry/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ pub(crate) mod tests {
drop(span);
});

assert!(span1_removed2.load(Ordering::Acquire) == true);
assert!(span2_removed2.load(Ordering::Acquire) == true);
assert!(span1_removed2.load(Ordering::Acquire));
assert!(span2_removed2.load(Ordering::Acquire));

// Ensure the registry itself outlives the span.
drop(dispatch);
Expand Down Expand Up @@ -506,11 +506,11 @@ pub(crate) mod tests {
span2_clone
});

assert!(span1_removed2.load(Ordering::Acquire) == true);
assert!(span2_removed2.load(Ordering::Acquire) == false);
assert!(span1_removed2.load(Ordering::Acquire));
assert!(!span2_removed2.load(Ordering::Acquire));

drop(span2);
assert!(span2_removed2.load(Ordering::Acquire) == true);
assert!(span2_removed2.load(Ordering::Acquire));

// Ensure the registry itself outlives the span.
drop(dispatch);
Expand Down
Loading