Skip to content

Commit 006f475

Browse files
authored
Fix new nightly clippy lints (#400)
1 parent c12f097 commit 006f475

File tree

3 files changed

+65
-43
lines changed

3 files changed

+65
-43
lines changed

opentelemetry-jaeger/src/exporter/collector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ mod collector_client {
3333

3434
impl CollectorAsyncClientHttp {
3535
/// Create a new HTTP collector client
36-
pub(crate) fn new(endpoint: Uri, client: Box<dyn HttpClient>) -> thrift::Result<Self> {
36+
pub(crate) fn new(endpoint: Uri, client: Box<dyn HttpClient>) -> Self {
3737
let payload_size_estimate = AtomicUsize::new(512);
3838

39-
Ok(CollectorAsyncClientHttp {
39+
CollectorAsyncClientHttp {
4040
endpoint,
4141
client,
4242
payload_size_estimate,
43-
})
43+
}
4444
}
4545

4646
/// Submit list of Jaeger batches

opentelemetry-jaeger/src/exporter/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ impl PipelineBuilder {
390390
Box::new(client)
391391
});
392392

393-
let collector = CollectorAsyncClientHttp::new(collector_endpoint, client)
394-
.map_err::<Error, _>(Into::into)?;
393+
let collector = CollectorAsyncClientHttp::new(collector_endpoint, client);
395394
Ok((self.process, uploader::BatchUploader::Collector(collector)))
396395
} else {
397396
let endpoint = self.agent_endpoint.as_slice();
@@ -568,7 +567,7 @@ fn convert_otel_span_into_jaeger_span(
568567
.duration_since(span.start_time)
569568
.unwrap_or_else(|_| Duration::from_secs(0))
570569
.as_micros() as i64,
571-
tags: build_span_tags(
570+
tags: Some(build_span_tags(
572571
span.attributes,
573572
if export_instrument_lib {
574573
Some(span.instrumentation_lib)
@@ -578,7 +577,7 @@ fn convert_otel_span_into_jaeger_span(
578577
span.status_code,
579578
span.status_message,
580579
span.span_kind,
581-
),
580+
)),
582581
logs: events_to_logs(span.message_events),
583582
}
584583
}
@@ -604,7 +603,7 @@ fn build_span_tags(
604603
status_code: StatusCode,
605604
status_message: String,
606605
kind: SpanKind,
607-
) -> Option<Vec<jaeger::Tag>> {
606+
) -> Vec<jaeger::Tag> {
608607
let mut user_overrides = UserOverrides::default();
609608
// TODO determine if namespacing is required to avoid collisions with set attributes
610609
let mut tags = attrs
@@ -658,7 +657,7 @@ fn build_span_tags(
658657
}
659658
}
660659

661-
Some(tags)
660+
tags
662661
}
663662

664663
const ERROR: &str = "error";
@@ -838,8 +837,7 @@ mod tests {
838837
status_code,
839838
error_msg,
840839
SpanKind::Client,
841-
)
842-
.unwrap_or_default();
840+
);
843841
if let Some(val) = status_tag_val {
844842
assert_tag_contains(tags.clone(), OTEL_STATUS_CODE, val);
845843
} else {

opentelemetry/src/api/metrics/number.rs

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,36 @@ impl AtomicNumber {
9292
/// `inf` for `f64`.
9393
pub fn fetch_add(&self, number_kind: &NumberKind, val: &Number) {
9494
match number_kind {
95-
NumberKind::I64 => loop {
96-
let current = self.0.load(Ordering::Acquire);
97-
let new = (current as i64).wrapping_add(val.0 as i64) as u64;
98-
let swapped = self.0.compare_and_swap(current, new, Ordering::Release);
99-
if swapped == current {
100-
return;
95+
NumberKind::I64 => {
96+
let mut old = self.0.load(Ordering::Acquire);
97+
loop {
98+
let new = (old as i64).wrapping_add(val.0 as i64) as u64;
99+
match self.0.compare_exchange_weak(
100+
old,
101+
new,
102+
Ordering::AcqRel,
103+
Ordering::Acquire,
104+
) {
105+
Ok(_) => break,
106+
Err(x) => old = x,
107+
};
101108
}
102-
},
103-
NumberKind::F64 => loop {
104-
let current = self.0.load(Ordering::Acquire);
105-
let new = u64_to_f64(current) + u64_to_f64(val.0);
106-
let swapped = self
107-
.0
108-
.compare_and_swap(current, f64_to_u64(new), Ordering::Release);
109-
if swapped == current {
110-
return;
109+
}
110+
NumberKind::F64 => {
111+
let mut old = self.0.load(Ordering::Acquire);
112+
loop {
113+
let new = u64_to_f64(old) + u64_to_f64(val.0);
114+
match self.0.compare_exchange_weak(
115+
old,
116+
f64_to_u64(new),
117+
Ordering::AcqRel,
118+
Ordering::Acquire,
119+
) {
120+
Ok(_) => break,
121+
Err(x) => old = x,
122+
};
111123
}
112-
},
124+
}
113125
NumberKind::U64 => {
114126
self.0.fetch_add(val.0, Ordering::AcqRel);
115127
}
@@ -122,24 +134,36 @@ impl AtomicNumber {
122134
/// `-inf` for `f64`.
123135
pub fn fetch_sub(&self, number_kind: &NumberKind, val: &Number) {
124136
match number_kind {
125-
NumberKind::I64 => loop {
126-
let current = self.0.load(Ordering::Acquire);
127-
let new = (current as i64).wrapping_sub(val.0 as i64) as u64;
128-
let swapped = self.0.compare_and_swap(current, new, Ordering::Release);
129-
if swapped == current {
130-
return;
137+
NumberKind::I64 => {
138+
let mut old = self.0.load(Ordering::Acquire);
139+
loop {
140+
let new = (old as i64).wrapping_sub(val.0 as i64) as u64;
141+
match self.0.compare_exchange_weak(
142+
old,
143+
new,
144+
Ordering::AcqRel,
145+
Ordering::Relaxed,
146+
) {
147+
Ok(_) => break,
148+
Err(x) => old = x,
149+
};
131150
}
132-
},
133-
NumberKind::F64 => loop {
134-
let current = self.0.load(Ordering::Acquire);
135-
let new = u64_to_f64(current) - u64_to_f64(val.0);
136-
let swapped = self
137-
.0
138-
.compare_and_swap(current, f64_to_u64(new), Ordering::Release);
139-
if swapped == current {
140-
return;
151+
}
152+
NumberKind::F64 => {
153+
let mut old = self.0.load(Ordering::Acquire);
154+
loop {
155+
let new = u64_to_f64(old) - u64_to_f64(val.0);
156+
match self.0.compare_exchange_weak(
157+
old,
158+
f64_to_u64(new),
159+
Ordering::AcqRel,
160+
Ordering::Acquire,
161+
) {
162+
Ok(_) => break,
163+
Err(x) => old = x,
164+
};
141165
}
142-
},
166+
}
143167
NumberKind::U64 => {
144168
self.0.fetch_sub(val.0, Ordering::AcqRel);
145169
}

0 commit comments

Comments
 (0)