Skip to content

Commit 614a327

Browse files
committed
chore: fix clippy's awful new "inconsistent struct constructor" lint (#1401)
This branch fixes some annoying new clippy lints no one cares about. Signed-off-by: Eliza Weisman <eliza@buoyant.io> # Conflicts: # tracing-subscriber/src/layer.rs
1 parent dd49b99 commit 614a327

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

tracing-attributes/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl Parse for Field {
983983
} else {
984984
None
985985
};
986-
Ok(Self { name, kind, value })
986+
Ok(Self { name, value, kind })
987987
}
988988
}
989989

tracing-core/src/event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl<'a> Event<'a> {
4141
#[inline]
4242
pub fn new(metadata: &'static Metadata<'static>, fields: &'a field::ValueSet<'a>) -> Self {
4343
Event {
44-
metadata,
4544
fields,
45+
metadata,
4646
parent: Parent::Current,
4747
}
4848
}
@@ -60,8 +60,8 @@ impl<'a> Event<'a> {
6060
None => Parent::Root,
6161
};
6262
Event {
63-
metadata,
6463
fields,
64+
metadata,
6565
parent,
6666
}
6767
}

tracing-subscriber/src/fmt/format/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ where
827827
span: Option<&'a span::Id>,
828828
ansi: bool,
829829
) -> Self {
830-
Self { ctx, ansi, span }
830+
Self { ctx, span, ansi }
831831
}
832832

833833
#[cfg(not(feature = "ansi"))]

tracing-subscriber/src/layer.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,11 +1135,7 @@ impl<'a, S> Context<'a, S> {
11351135
impl<'a, S> Clone for Context<'a, S> {
11361136
#[inline]
11371137
fn clone(&self) -> Self {
1138-
let subscriber = if let Some(ref subscriber) = self.subscriber {
1139-
Some(*subscriber)
1140-
} else {
1141-
None
1142-
};
1138+
let subscriber = self.subscriber.as_ref().copied();
11431139
Context { subscriber }
11441140
}
11451141
}
@@ -1271,8 +1267,8 @@ pub(crate) mod tests {
12711267
.and_then(NopLayer)
12721268
.and_then(NopLayer)
12731269
.with_subscriber(StringSubscriber("subscriber".into()));
1274-
let subscriber =
1275-
Subscriber::downcast_ref::<StringSubscriber>(&s).expect("subscriber should downcast");
1270+
let subscriber = <dyn Subscriber>::downcast_ref::<StringSubscriber>(&s)
1271+
.expect("subscriber should downcast");
12761272
assert_eq!(&subscriber.0, "subscriber");
12771273
}
12781274

@@ -1282,11 +1278,14 @@ pub(crate) mod tests {
12821278
.and_then(StringLayer2("layer_2".into()))
12831279
.and_then(StringLayer3("layer_3".into()))
12841280
.with_subscriber(NopSubscriber);
1285-
let layer = Subscriber::downcast_ref::<StringLayer>(&s).expect("layer 1 should downcast");
1281+
let layer =
1282+
<dyn Subscriber>::downcast_ref::<StringLayer>(&s).expect("layer 1 should downcast");
12861283
assert_eq!(&layer.0, "layer_1");
1287-
let layer = Subscriber::downcast_ref::<StringLayer2>(&s).expect("layer 2 should downcast");
1284+
let layer =
1285+
<dyn Subscriber>::downcast_ref::<StringLayer2>(&s).expect("layer 2 should downcast");
12881286
assert_eq!(&layer.0, "layer_2");
1289-
let layer = Subscriber::downcast_ref::<StringLayer3>(&s).expect("layer 3 should downcast");
1287+
let layer =
1288+
<dyn Subscriber>::downcast_ref::<StringLayer3>(&s).expect("layer 3 should downcast");
12901289
assert_eq!(&layer.0, "layer_3");
12911290
}
12921291
}

tracing-tower/src/service_span.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ mod layer {
5757

5858
fn layer(&self, inner: S) -> Self::Service {
5959
let span = self.get_span.span_for(&inner);
60-
Service { span, inner }
60+
Service { inner, span }
6161
}
6262
}
6363

@@ -221,7 +221,7 @@ pub mod make {
221221

222222
impl<S> Service<S> {
223223
pub fn new(inner: S, span: tracing::Span) -> Self {
224-
Self { span, inner }
224+
Self { inner, span }
225225
}
226226
}
227227

0 commit comments

Comments
 (0)