Skip to content

Commit ccca0df

Browse files
gruebelcijothomas
andauthored
chore: enable Rust 2024 edition lints (#200)
Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
1 parent 4142e94 commit ccca0df

File tree

7 files changed

+70
-65
lines changed

7 files changed

+70
-65
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ opentelemetry-semantic-conventions = { version = "0.28", features = [
2424
] }
2525
criterion = "0.5"
2626

27+
[workspace.lints.rust]
28+
rust_2024_compatibility = { level = "warn", priority = -1 }
29+
# No need to enable those, because it is either unnecessary or results in ugly syntax
30+
if_let_rescope = "allow"
31+
tail_expr_drop_order = "allow"
32+
2733
[workspace.lints.clippy]
2834
all = { level = "warn", priority = 1 }

opentelemetry-aws/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ opentelemetry-http = { workspace = true }
3636
opentelemetry-stdout = { workspace = true, features = ["trace"] }
3737
hyper = { version = "1.4.1" }
3838
tokio = { version = "1.0", features = ["macros", "rt"] }
39-
sealed_test = "1.1.0"
39+
sealed_test = "1.1"
40+
temp-env = "0.3"
4041

4142
[package.metadata.cargo-machete]
4243
ignored = ["tracing"]

opentelemetry-aws/src/detector/lambda.rs

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -59,54 +59,51 @@ impl ResourceDetector for LambdaResourceDetector {
5959
mod tests {
6060
use super::*;
6161
use sealed_test::prelude::*;
62-
use std::env::{remove_var, set_var};
6362

6463
#[sealed_test]
6564
fn test_aws_lambda_detector() {
66-
set_var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR, "my-lambda-function");
67-
set_var(AWS_REGION_ENV_VAR, "eu-west-3");
68-
set_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR, "$LATEST");
69-
set_var(
70-
AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR,
71-
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
72-
);
73-
set_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR, "128");
74-
set_var(
75-
AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR,
76-
"/aws/lambda/my-lambda-function",
77-
);
78-
79-
let expected = Resource::builder_empty()
80-
.with_attributes([
81-
KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"),
82-
KeyValue::new(semconv::resource::CLOUD_REGION, "eu-west-3"),
83-
KeyValue::new(
84-
semconv::resource::FAAS_INSTANCE,
85-
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
65+
temp_env::with_vars(
66+
[
67+
(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR, Some("my-lambda-function")),
68+
(AWS_REGION_ENV_VAR, Some("eu-west-3")),
69+
(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR, Some("$LATEST")),
70+
(
71+
AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR,
72+
Some("2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc"),
8673
),
87-
KeyValue::new(semconv::resource::FAAS_NAME, "my-lambda-function"),
88-
KeyValue::new(semconv::resource::FAAS_VERSION, "$LATEST"),
89-
KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, 128 * 1024 * 1024),
90-
KeyValue::new(
91-
semconv::resource::AWS_LOG_GROUP_NAMES,
92-
Value::Array(Array::from(vec![StringValue::from(
93-
"/aws/lambda/my-lambda-function".to_string(),
94-
)])),
74+
(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR, Some("128")),
75+
(
76+
AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR,
77+
Some("/aws/lambda/my-lambda-function"),
9578
),
96-
])
97-
.build();
79+
],
80+
|| {
81+
let expected = Resource::builder_empty()
82+
.with_attributes([
83+
KeyValue::new(semconv::resource::CLOUD_PROVIDER, "aws"),
84+
KeyValue::new(semconv::resource::CLOUD_REGION, "eu-west-3"),
85+
KeyValue::new(
86+
semconv::resource::FAAS_INSTANCE,
87+
"2023/01/01/[$LATEST]5d1edb9e525d486696cf01a3503487bc",
88+
),
89+
KeyValue::new(semconv::resource::FAAS_NAME, "my-lambda-function"),
90+
KeyValue::new(semconv::resource::FAAS_VERSION, "$LATEST"),
91+
KeyValue::new(semconv::resource::FAAS_MAX_MEMORY, 128 * 1024 * 1024),
92+
KeyValue::new(
93+
semconv::resource::AWS_LOG_GROUP_NAMES,
94+
Value::Array(Array::from(vec![StringValue::from(
95+
"/aws/lambda/my-lambda-function".to_string(),
96+
)])),
97+
),
98+
])
99+
.build();
98100

99-
let detector = LambdaResourceDetector {};
100-
let got = detector.detect();
101-
102-
assert_eq!(expected, got);
101+
let detector = LambdaResourceDetector {};
102+
let got = detector.detect();
103103

104-
remove_var(AWS_LAMBDA_FUNCTION_NAME_ENV_VAR);
105-
remove_var(AWS_REGION_ENV_VAR);
106-
remove_var(AWS_LAMBDA_FUNCTION_VERSION_ENV_VAR);
107-
remove_var(AWS_LAMBDA_LOG_STREAM_NAME_ENV_VAR);
108-
remove_var(AWS_LAMBDA_MEMORY_LIMIT_ENV_VAR);
109-
remove_var(AWS_LAMBDA_LOG_GROUP_NAME_ENV_VAR);
104+
assert_eq!(expected, got);
105+
},
106+
);
110107
}
111108

112109
#[sealed_test]

opentelemetry-datadog/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ hyper = "1"
5353
hyper-util = { version = "0.1.6", features = ["client", "full"] }
5454
hyperlocal = "0.9.1"
5555
http-body-util = "0.1.2"
56+
temp-env = "0.3"
5657

5758
[[bench]]
5859
name = "datadog_exporter"

opentelemetry-datadog/src/exporter/model/unified_tags.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,34 +89,34 @@ mod tests {
8989

9090
#[test]
9191
fn test_service() {
92-
std::env::set_var("DD_SERVICE", "test-SERVICE");
93-
let mut unified_tags = UnifiedTags::new();
94-
assert_eq!("test-service", unified_tags.service.value.clone().unwrap());
95-
unified_tags.set_service(Some(String::from("new_service")));
96-
assert_eq!("new_service", unified_tags.service().unwrap());
97-
std::env::remove_var("DD_SERVICE");
92+
temp_env::with_var("DD_SERVICE", Some("test-SERVICE"), || {
93+
let mut unified_tags = UnifiedTags::new();
94+
assert_eq!("test-service", unified_tags.service.value.clone().unwrap());
95+
unified_tags.set_service(Some(String::from("new_service")));
96+
assert_eq!("new_service", unified_tags.service().unwrap());
97+
});
9898
}
9999

100100
#[test]
101101
fn test_env() {
102-
std::env::set_var("DD_ENV", "test-env");
103-
let mut unified_tags = UnifiedTags::new();
104-
assert_eq!("test-env", unified_tags.env.value.clone().unwrap());
105-
unified_tags.set_env(Some(String::from("new_env")));
106-
assert_eq!("new_env", unified_tags.env.value.unwrap());
107-
std::env::remove_var("DD_ENV");
102+
temp_env::with_var("DD_ENV", Some("test-env"), || {
103+
let mut unified_tags = UnifiedTags::new();
104+
assert_eq!("test-env", unified_tags.env.value.clone().unwrap());
105+
unified_tags.set_env(Some(String::from("new_env")));
106+
assert_eq!("new_env", unified_tags.env.value.unwrap());
107+
});
108108
}
109109

110110
#[test]
111111
fn test_version() {
112-
std::env::set_var("DD_VERSION", "test-version-1.2.3");
113-
let mut unified_tags = UnifiedTags::new();
114-
assert_eq!(
115-
"test-version-1.2.3",
116-
unified_tags.version.value.clone().unwrap()
117-
);
118-
unified_tags.set_version(Some(String::from("new_version")));
119-
assert_eq!("new_version", unified_tags.version.value.unwrap());
120-
std::env::remove_var("DD_VERSION");
112+
temp_env::with_var("DD_VERSION", Some("test-version-1.2.3"), || {
113+
let mut unified_tags = UnifiedTags::new();
114+
assert_eq!(
115+
"test-version-1.2.3",
116+
unified_tags.version.value.clone().unwrap()
117+
);
118+
unified_tags.set_version(Some(String::from("new_version")));
119+
assert_eq!("new_version", unified_tags.version.value.unwrap());
120+
});
121121
}
122122
}

opentelemetry-user-events-metrics/src/tracepoint/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub unsafe fn register(trace_point: Pin<&ehi::TracepointState>) -> i32 {
8585
// If tracepoint doesn't exist, it will create one automatically
8686
let result = panic::catch_unwind(|| {
8787
// CStr::from_bytes_with_nul_unchecked is ok because METRICS_EVENT_DEF ends with "\0".
88-
trace_point.register(ffi::CStr::from_bytes_with_nul_unchecked(METRICS_EVENT_DEF))
88+
unsafe { trace_point.register(ffi::CStr::from_bytes_with_nul_unchecked(METRICS_EVENT_DEF)) }
8989
});
9090

9191
match result {

stress/src/throughput.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ impl<'a> UnsafeSlice<'a> {
155155
#[inline(always)]
156156
unsafe fn increment(&self, i: usize) {
157157
let value = self.slice[i].get();
158-
(*value).count += 1;
158+
unsafe { (*value).count += 1 };
159159
}
160160

161161
#[inline(always)]

0 commit comments

Comments
 (0)