Skip to content

Commit 975384f

Browse files
committed
Fix clippy lints
1 parent fc3ab4c commit 975384f

File tree

32 files changed

+79
-67
lines changed

32 files changed

+79
-67
lines changed

clippy.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
blacklisted-names = []
2+
cognitive-complexity-threshold = 100
3+
too-many-arguments-threshold = 8
4+
type-complexity-threshold = 375

examples/examples/attrs-basic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use tracing_attributes::instrument;
77
#[inline]
88
fn suggest_band() -> String {
99
debug!("Suggesting a band.");
10-
format!("Wild Pink")
10+
String::from("Wild Pink")
1111
}
1212

1313
fn main() {

examples/examples/counters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'a> Visit for Count<'a> {
3434
if value > 0 {
3535
counter.fetch_add(value as usize, Ordering::Release);
3636
} else {
37-
counter.fetch_sub((value * -1) as usize, Ordering::Release);
37+
counter.fetch_sub(-value as usize, Ordering::Release);
3838
}
3939
};
4040
}

examples/examples/fmt/yak_shave.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn shave(yak: usize) -> Result<(), Box<dyn Error + 'static>> {
1111
);
1212
if yak == 3 {
1313
warn!(target: "yak_events", "could not locate yak!");
14-
Err(ShaveError::new(yak, YakError::new("could not locate yak")))?;
14+
return Err(ShaveError::new(yak, YakError::new("could not locate yak")).into());
1515
} else {
1616
trace!(target: "yak_events", "yak shaved successfully");
1717
}

examples/examples/hyper-echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn echo(req: Request<Body>) -> Instrumented<BoxFut> {
2828
let (rsp_span, fut): (_, BoxFut) = match (req.method(), req.uri().path()) {
2929
// Serve some instructions at /
3030
(&Method::GET, "/") => {
31-
const BODY: &'static str = "Try POSTing data to /echo";
31+
const BODY: &str = "Try POSTing data to /echo";
3232
*response.body_mut() = Body::from(BODY);
3333
(
3434
span!(Level::INFO, "response", body = %(&BODY)),

examples/examples/sloggish/sloggish_subscriber.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ struct ColorLevel<'a>(&'a Level);
9191

9292
impl<'a> fmt::Display for ColorLevel<'a> {
9393
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94-
match self.0 {
95-
&Level::TRACE => Color::Purple.paint("TRACE"),
96-
&Level::DEBUG => Color::Blue.paint("DEBUG"),
97-
&Level::INFO => Color::Green.paint("INFO "),
98-
&Level::WARN => Color::Yellow.paint("WARN "),
99-
&Level::ERROR => Color::Red.paint("ERROR"),
94+
match *self.0 {
95+
Level::TRACE => Color::Purple.paint("TRACE"),
96+
Level::DEBUG => Color::Blue.paint("DEBUG"),
97+
Level::INFO => Color::Green.paint("INFO "),
98+
Level::WARN => Color::Yellow.paint("WARN "),
99+
Level::ERROR => Color::Red.paint("ERROR"),
100100
}
101101
.fmt(f)
102102
}
@@ -228,10 +228,7 @@ impl Subscriber for SloggishSubscriber {
228228
let spans = self.spans.lock().unwrap();
229229
let data = spans.get(span_id);
230230
let parent = data.and_then(|span| span.parent.as_ref());
231-
if stack.iter().any(|id| id == span_id) {
232-
// We are already in this span, do nothing.
233-
return;
234-
} else {
231+
if !stack.iter().any(|id| id == span_id) {
235232
let indent = if let Some(idx) = stack
236233
.iter()
237234
.position(|id| parent.map(|p| id == p).unwrap_or(false))
@@ -249,7 +246,7 @@ impl Subscriber for SloggishSubscriber {
249246
self.print_kvs(&mut stderr, data.kvs.iter().map(|(k, v)| (k, v)), "")
250247
.unwrap();
251248
}
252-
write!(&mut stderr, "\n").unwrap();
249+
writeln!(&mut stderr).unwrap();
253250
}
254251
}
255252

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

276273
#[inline]

examples/examples/tower-load.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ where
275275
.map(move |chunk| match handle.set_from(chunk) {
276276
Err(error) => {
277277
tracing::warn!(message = "setting filter failed!", %error);
278-
rsp(StatusCode::INTERNAL_SERVER_ERROR, format!("{}", error))
278+
rsp(StatusCode::INTERNAL_SERVER_ERROR, error.to_string())
279279
}
280280
Ok(()) => rsp(StatusCode::NO_CONTENT, Body::empty()),
281281
});
@@ -345,7 +345,7 @@ fn load_gen(addr: &SocketAddr) -> Box<dyn Future<Item = (), Error = ()> + Send +
345345
use tower_http_util::body::BodyExt;
346346
use tower_hyper::client::Client;
347347

348-
static ALPHABET: &'static str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
348+
static ALPHABET: &str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
349349
let authority = format!("{}", addr);
350350
let f = future::lazy(move || {
351351
let hyper = Client::new();
@@ -363,7 +363,7 @@ fn load_gen(addr: &SocketAddr) -> Box<dyn Future<Item = (), Error = ()> + Send +
363363
let mut rng = rand::thread_rng();
364364
let idx = rng.gen_range(0, ALPHABET.len()+1);
365365
let len = rng.gen_range(0, 26);
366-
let letter = ALPHABET.get(idx..idx+1).unwrap_or("");
366+
let letter = ALPHABET.get(idx..=idx).unwrap_or("");
367367
let uri = format!("http://{}/{}", authority, letter);
368368
let req = Request::get(&uri[..])
369369
.header("Content-Length", len)

tracing-attributes/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn param_names(pat: Pat) -> Box<dyn Iterator<Item = Ident>> {
269269
}
270270
}
271271

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

302-
fn level(args: &AttributeArgs) -> impl ToTokens {
302+
fn level(args: &[NestedMeta]) -> impl ToTokens {
303303
let mut levels = args.iter().filter_map(|arg| match arg {
304304
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
305305
ref path, ref lit, ..
@@ -353,7 +353,7 @@ fn level(args: &AttributeArgs) -> impl ToTokens {
353353
}
354354
}
355355

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

383-
fn name(args: &AttributeArgs, default_name: String) -> impl ToTokens {
383+
fn name(args: &[NestedMeta], default_name: String) -> impl ToTokens {
384384
let mut names = args.iter().filter_map(|arg| match arg {
385385
NestedMeta::Meta(Meta::NameValue(MetaNameValue {
386386
ref path, ref lit, ..

tracing-attributes/tests/support.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#[path = "../../tracing/tests/support/mod.rs"]
2+
#[allow(clippy::module_inception)]
23
mod support;
34
pub use self::support::*;

tracing-core/src/dispatcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ mod test {
805805
fn exit(&self, _: &span::Id) {}
806806
}
807807

808-
with_default(&Dispatch::new(TestSubscriber), || mk_span())
808+
with_default(&Dispatch::new(TestSubscriber), mk_span)
809809
}
810810

811811
#[test]

tracing-core/src/span.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ impl Id {
6868
Id(NonZeroU64::new(u).expect("span IDs must be > 0"))
6969
}
7070

71+
// Allow `into` by-ref since we don't want to impl Copy for Id
72+
#[allow(clippy::wrong_self_convention)]
7173
/// Returns the span's ID as a `u64`.
7274
pub fn into_u64(&self) -> u64 {
7375
self.0.get()

tracing-core/src/subscriber.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub trait Subscriber: 'static {
369369
/// [`drop_span`]: trait.Subscriber.html#method.drop_span
370370
fn try_close(&self, id: span::Id) -> bool {
371371
#[allow(deprecated)]
372-
let _ = self.drop_span(id);
372+
self.drop_span(id);
373373
false
374374
}
375375

tracing-log/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ struct Fields {
216216
line: field::Field,
217217
}
218218

219-
static FIELD_NAMES: &'static [&'static str] = &[
219+
static FIELD_NAMES: &[&str] = &[
220220
"message",
221221
"log.target",
222222
"log.module_path",

tracing-macros/examples/factorial.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ fn factorial(n: u32) -> u32 {
1818

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

2324
tracing::subscriber::with_default(subscriber, || dbg!(factorial(4)));

tracing-subscriber/benches/filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct EnabledSubscriber;
1313
impl tracing::Subscriber for EnabledSubscriber {
1414
fn new_span(&self, span: &span::Attributes<'_>) -> Id {
1515
let _ = span;
16-
Id::from_u64(0xDEADFACE)
16+
Id::from_u64(0xDEAD_FACE)
1717
}
1818

1919
fn event(&self, event: &Event<'_>) {

tracing-subscriber/benches/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn bench_new_span(c: &mut Criterion) {
7676

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

8181
let mut group = c.benchmark_group(name);
8282
for spans in N_SPANS {

tracing-subscriber/src/filter/env/directive.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<T> DirectiveSet<T> {
391391
self.directives.is_empty()
392392
}
393393

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

418418
pub(crate) fn add(&mut self, directive: T) {
419419
let level = directive.level();
420-
if level > &self.max_level {
420+
if *level > self.max_level {
421421
self.max_level = level.clone();
422422
}
423423
let _ = self.directives.replace(directive);
@@ -437,7 +437,7 @@ impl<T: Match + Ord> Extend<T> for DirectiveSet<T> {
437437
let max_level = &mut self.max_level;
438438
let ds = iter.into_iter().inspect(|d| {
439439
let level = d.level();
440-
if level > &*max_level {
440+
if *level > *max_level {
441441
*max_level = level.clone();
442442
}
443443
});
@@ -457,7 +457,7 @@ impl Dynamics {
457457
return Some(f);
458458
}
459459
match base_level {
460-
Some(ref b) if &d.level > b => base_level = Some(d.level.clone()),
460+
Some(ref b) if d.level > *b => base_level = Some(d.level.clone()),
461461
None => base_level = Some(d.level.clone()),
462462
_ => {}
463463
}
@@ -556,7 +556,7 @@ impl Match for StaticDirective {
556556
if meta.is_event() && !self.field_names.is_empty() {
557557
let fields = meta.fields();
558558
for name in &self.field_names {
559-
if !fields.field(name).is_some() {
559+
if fields.field(name).is_none() {
560560
return false;
561561
}
562562
}

tracing-subscriber/src/filter/env/field.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub(crate) enum ValueMatch {
4141
Bool(bool),
4242
U64(u64),
4343
I64(i64),
44-
Pat(MatchPattern),
44+
Pat(Box<MatchPattern>),
4545
}
4646

4747
#[derive(Debug, Clone)]
@@ -130,7 +130,10 @@ impl FromStr for ValueMatch {
130130
.map(ValueMatch::Bool)
131131
.or_else(|_| s.parse::<u64>().map(ValueMatch::U64))
132132
.or_else(|_| s.parse::<i64>().map(ValueMatch::I64))
133-
.or_else(|_| s.parse::<MatchPattern>().map(ValueMatch::Pat))
133+
.or_else(|_| {
134+
s.parse::<MatchPattern>()
135+
.map(|p| ValueMatch::Pat(Box::new(p)))
136+
})
134137
}
135138
}
136139

@@ -233,7 +236,7 @@ impl CallsiteMatch {
233236
}
234237

235238
impl SpanMatch {
236-
pub(crate) fn visitor<'a>(&'a self) -> MatchVisitor<'a> {
239+
pub(crate) fn visitor(&self) -> MatchVisitor<'_> {
237240
MatchVisitor { inner: self }
238241
}
239242

tracing-subscriber/src/filter/env/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ mod tests {
406406
#[test]
407407
fn callsite_enabled_no_span_directive() {
408408
let filter = EnvFilter::new("app=debug").with_subscriber(NoSubscriber);
409-
static META: &'static Metadata<'static> = &Metadata::new(
409+
static META: &Metadata<'static> = &Metadata::new(
410410
"mySpan",
411411
"app",
412412
Level::TRACE,
@@ -424,7 +424,7 @@ mod tests {
424424
#[test]
425425
fn callsite_off() {
426426
let filter = EnvFilter::new("app=off").with_subscriber(NoSubscriber);
427-
static META: &'static Metadata<'static> = &Metadata::new(
427+
static META: &Metadata<'static> = &Metadata::new(
428428
"mySpan",
429429
"app",
430430
Level::ERROR,
@@ -442,7 +442,7 @@ mod tests {
442442
#[test]
443443
fn callsite_enabled_includes_span_directive() {
444444
let filter = EnvFilter::new("app[mySpan]=debug").with_subscriber(NoSubscriber);
445-
static META: &'static Metadata<'static> = &Metadata::new(
445+
static META: &Metadata<'static> = &Metadata::new(
446446
"mySpan",
447447
"app",
448448
Level::TRACE,
@@ -461,7 +461,7 @@ mod tests {
461461
fn callsite_enabled_includes_span_directive_field() {
462462
let filter =
463463
EnvFilter::new("app[mySpan{field=\"value\"}]=debug").with_subscriber(NoSubscriber);
464-
static META: &'static Metadata<'static> = &Metadata::new(
464+
static META: &Metadata<'static> = &Metadata::new(
465465
"mySpan",
466466
"app",
467467
Level::TRACE,
@@ -480,7 +480,7 @@ mod tests {
480480
fn callsite_enabled_includes_span_directive_multiple_fields() {
481481
let filter = EnvFilter::new("app[mySpan{field=\"value\",field2=2}]=debug")
482482
.with_subscriber(NoSubscriber);
483-
static META: &'static Metadata<'static> = &Metadata::new(
483+
static META: &Metadata<'static> = &Metadata::new(
484484
"mySpan",
485485
"app",
486486
Level::TRACE,

tracing-subscriber/src/layer.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub struct Layered<L, I, S = I> {
408408
}
409409

410410
/// A layer that does nothing.
411-
#[derive(Clone, Debug)]
411+
#[derive(Clone, Debug, Default)]
412412
pub struct Identity {
413413
_p: (),
414414
}
@@ -512,12 +512,16 @@ where
512512
#[cfg(feature = "registry")]
513513
let mut guard = subscriber
514514
.downcast_ref::<Registry>()
515-
.and_then(|registry| Some(registry.start_close(id.clone())));
515+
.map(|registry| registry.start_close(id.clone()));
516516
if self.inner.try_close(id.clone()) {
517517
// If we have a registry's close guard, indicate that the span is
518518
// closing.
519519
#[cfg(feature = "registry")]
520-
guard.as_mut().map(|g| g.is_closing());
520+
{
521+
if let Some(g) = guard.as_mut() {
522+
g.is_closing()
523+
};
524+
}
521525

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

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

tracing-subscriber/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ macro_rules! try_lock {
8787
($lock:expr, else $els:expr) => {
8888
match $lock {
8989
Ok(l) => l,
90-
Err(_) if std::thread::panicking() => $els,
91-
Err(_) => panic!("lock poisoned"),
90+
Err(_err) if std::thread::panicking() => $els,
91+
Err(_err) => panic!("lock poisoned"),
9292
}
9393
};
9494
}

0 commit comments

Comments
 (0)