Skip to content

Commit fed44af

Browse files
authored
ref(relay): Enable str_to_string clippy lint (#4856)
Regex beats Cursor, Clippy beats Regex. Enables the [`str_to_string`](https://rust-lang.github.io/rust-clippy/master/#str_to_string) clippy lint on the workspace and one run of `clippy --fix`. #skip-changelog
1 parent 385bc56 commit fed44af

File tree

41 files changed

+125
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+125
-129
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ strip = true
3030
dbg_macro = "warn"
3131
print_stdout = "warn"
3232
print_stderr = "warn"
33+
str_to_string = "warn"
3334

3435
[workspace.lints.rust]
3536
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(sentry)'] }

relay-cabi/src/glob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn glob_match_bytes(value: &[u8], pat: &str, options: GlobOptions) -> bool {
9898
pat.replace('\\', "/"),
9999
)
100100
} else {
101-
(Cow::Borrowed(value), pat.to_string())
101+
(Cow::Borrowed(value), pat.to_owned())
102102
};
103103
let key = (options, pat);
104104
let mut cache = GLOB_CACHE.lock().unwrap_or_else(PoisonError::into_inner);

relay-cardinality/src/redis/limiter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl Limiter for RedisSetLimiter {
160160
continue;
161161
}
162162

163-
let id = &state.id().to_string();
163+
let id = &state.id().to_owned();
164164
let scopes = num_scopes_tag(&state);
165165
let results = metric!(
166166
timer(CardinalityLimiterTimers::Redis),

relay-config/src/upstream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl FromStr for UpstreamDescriptor<'static> {
146146

147147
Ok(UpstreamDescriptor {
148148
host: match url.host_str() {
149-
Some(host) => Cow::Owned(host.to_string()),
149+
Some(host) => Cow::Owned(host.to_owned()),
150150
None => return Err(UpstreamParseError::NoHost),
151151
},
152152
port: url.port().unwrap_or_else(|| scheme.default_port()),

relay-event-normalization/src/event.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ fn normalize_dist(distribution: &mut Annotated<String>) {
604604
meta.add_error(Error::new(ErrorKind::ValueTooLong));
605605
return Err(ProcessingAction::DeleteValueSoft);
606606
} else if trimmed != dist {
607-
*dist = trimmed.to_string();
607+
*dist = trimmed.to_owned();
608608
}
609609
Ok(())
610610
});
@@ -808,7 +808,7 @@ fn normalize_exception(exception: &mut Annotated<Exception>) {
808808
if let Some(value_str) = exception.value.value_mut() {
809809
let new_values = regex
810810
.captures(value_str)
811-
.map(|cap| (cap[1].to_string(), cap[2].trim().to_string().into()));
811+
.map(|cap| (cap[1].to_string(), cap[2].trim().to_owned().into()));
812812

813813
if let Some((new_type, new_value)) = new_values {
814814
exception.ty.set_value(Some(new_type));
@@ -1245,7 +1245,7 @@ fn shorten_logger(logger: String, meta: &mut Meta) -> String {
12451245
});
12461246
}
12471247
meta.set_original_length(Some(original_len));
1248-
return trimmed.to_string();
1248+
return trimmed.to_owned();
12491249
};
12501250
}
12511251

@@ -2101,7 +2101,7 @@ mod tests {
21012101
let max_name_and_unit_len = Some(30);
21022102

21032103
let mut measurements: BTreeMap<String, Annotated<Measurement>> = Object::new();
2104-
measurements.insert(name.to_string(), Annotated::new(measurement));
2104+
measurements.insert(name.to_owned(), Annotated::new(measurement));
21052105

21062106
let mut measurements = Measurements(measurements);
21072107
let mut meta = Meta::default();
@@ -4289,7 +4289,7 @@ mod tests {
42894289
#[test]
42904290
fn test_json_value() {
42914291
let mut exception = Annotated::new(Exception {
4292-
value: Annotated::new(r#"{"unauthorized":true}"#.to_string().into()),
4292+
value: Annotated::new(r#"{"unauthorized":true}"#.to_owned().into()),
42934293
..Exception::default()
42944294
});
42954295

relay-event-normalization/src/event_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl Processor for EmitEventErrors {
3333
value: Annotated::from(original_value.take()),
3434
other: error
3535
.data()
36-
.map(|(k, v)| (k.to_string(), Annotated::from(v.clone())))
36+
.map(|(k, v)| (k.to_owned(), Annotated::from(v.clone())))
3737
.collect(),
3838
});
3939
}

relay-event-normalization/src/mechanism.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ pub fn normalize_mechanism(mechanism: &mut Mechanism, os_hint: Option<OsHint>) {
609609
if cerror.name.value().is_none() {
610610
if let Some(errno) = cerror.number.value() {
611611
if let Some(name) = get_errno_name(*errno, os_hint) {
612-
cerror.name = Annotated::new(name.to_string());
612+
cerror.name = Annotated::new(name.to_owned());
613613
}
614614
}
615615
}
@@ -626,7 +626,7 @@ pub fn normalize_mechanism(mechanism: &mut Mechanism, os_hint: Option<OsHint>) {
626626
if os_hint == OsHint::Darwin && signal.code_name.value().is_none() {
627627
if let Some(code) = signal.code.value() {
628628
if let Some(code_name) = get_signal_code_name(*signo, *code) {
629-
signal.code_name = Annotated::new(code_name.to_string());
629+
signal.code_name = Annotated::new(code_name.to_owned());
630630
}
631631
}
632632
}

relay-event-normalization/src/normalize/breakdowns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ mod tests {
348348
let mut config = HashMap::new();
349349

350350
let span_ops_config = BreakdownConfig::SpanOperations(SpanOperationsConfig {
351-
matches: vec!["http".to_owned(), "db".to_string()],
351+
matches: vec!["http".to_owned(), "db".to_owned()],
352352
});
353353

354354
config.insert("span_ops".to_owned(), span_ops_config.clone());

relay-event-normalization/src/normalize/contexts.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ fn normalize_runtime_context(runtime: &mut RuntimeContext) {
9494
if runtime.name.value().is_empty() && runtime.version.value().is_empty() {
9595
if let Some(raw_description) = runtime.raw_description.as_str() {
9696
if let Some(captures) = RUNTIME_DOTNET_REGEX.captures(raw_description) {
97-
runtime.name = captures.name("name").map(|m| m.as_str().to_string()).into();
97+
runtime.name = captures.name("name").map(|m| m.as_str().to_owned()).into();
9898
runtime.version = captures
9999
.name("version")
100-
.map(|m| m.as_str().to_string())
100+
.map(|m| m.as_str().to_owned())
101101
.into();
102102
}
103103
}
@@ -200,62 +200,62 @@ fn normalize_os_context(os: &mut OsContext) {
200200
if let Some(raw_description) = os.raw_description.as_str() {
201201
if let Some((version, build_number)) = get_windows_version(raw_description) {
202202
os.name = "Windows".to_owned().into();
203-
os.version = version.to_string().into();
203+
os.version = version.to_owned().into();
204204
if os.build.is_empty() {
205205
// Keep raw version as build
206-
os.build.set_value(Some(build_number.to_string().into()));
206+
os.build.set_value(Some(build_number.to_owned().into()));
207207
}
208208
} else if let Some(captures) = OS_MACOS_REGEX.captures(raw_description) {
209209
os.name = "macOS".to_owned().into();
210210
os.version = captures
211211
.name("version")
212-
.map(|m| m.as_str().to_string())
212+
.map(|m| m.as_str().to_owned())
213213
.into();
214214
os.build = captures
215215
.name("build")
216-
.map(|m| m.as_str().to_string().into())
216+
.map(|m| m.as_str().to_owned().into())
217217
.into();
218218
} else if let Some(captures) = OS_IOS_REGEX.captures(raw_description) {
219219
os.name = "iOS".to_owned().into();
220220
os.version = captures
221221
.name("version")
222-
.map(|m| m.as_str().to_string())
222+
.map(|m| m.as_str().to_owned())
223223
.into();
224224
os.build = captures
225225
.name("build")
226-
.map(|m| m.as_str().to_string().into())
226+
.map(|m| m.as_str().to_owned().into())
227227
.into();
228228
} else if let Some(captures) = OS_IPADOS_REGEX.captures(raw_description) {
229229
os.name = "iPadOS".to_owned().into();
230230
os.version = captures
231231
.name("version")
232-
.map(|m| m.as_str().to_string())
232+
.map(|m| m.as_str().to_owned())
233233
.into();
234234
os.build = captures
235235
.name("build")
236-
.map(|m| m.as_str().to_string().into())
236+
.map(|m| m.as_str().to_owned().into())
237237
.into();
238238
} else if let Some(captures) = OS_LINUX_DISTRO_UNAME_REGEX.captures(raw_description) {
239-
os.name = captures.name("name").map(|m| m.as_str().to_string()).into();
239+
os.name = captures.name("name").map(|m| m.as_str().to_owned()).into();
240240
os.version = captures
241241
.name("version")
242-
.map(|m| m.as_str().to_string())
242+
.map(|m| m.as_str().to_owned())
243243
.into();
244244
os.kernel_version = captures
245245
.name("kernel_version")
246-
.map(|m| m.as_str().to_string())
246+
.map(|m| m.as_str().to_owned())
247247
.into();
248248
} else if let Some(captures) = OS_UNAME_REGEX.captures(raw_description) {
249-
os.name = captures.name("name").map(|m| m.as_str().to_string()).into();
249+
os.name = captures.name("name").map(|m| m.as_str().to_owned()).into();
250250
os.kernel_version = captures
251251
.name("kernel_version")
252-
.map(|m| m.as_str().to_string())
252+
.map(|m| m.as_str().to_owned())
253253
.into();
254254
} else if let Some(captures) = OS_ANDROID_REGEX.captures(raw_description) {
255255
os.name = "Android".to_owned().into();
256256
os.version = captures
257257
.name("version")
258-
.map(|m| m.as_str().to_string())
258+
.map(|m| m.as_str().to_owned())
259259
.into();
260260
} else if raw_description == "Nintendo Switch" {
261261
os.name = "Nintendo OS".to_owned().into();
@@ -302,13 +302,13 @@ fn normalize_response_data(response: &mut ResponseContext) {
302302
// Retain meta data on the body (e.g. trimming annotations) but remove anything on the
303303
// inferred content type.
304304
response.data.set_value(Some(parsed_data));
305-
response.inferred_content_type = Annotated::from(content_type.to_string());
305+
response.inferred_content_type = Annotated::from(content_type.to_owned());
306306
} else {
307307
response.inferred_content_type = response
308308
.headers
309309
.value()
310310
.and_then(|headers| headers.get_header("Content-Type"))
311-
.map(|value| value.split(';').next().unwrap_or(value).to_string())
311+
.map(|value| value.split(';').next().unwrap_or(value).to_owned())
312312
.into();
313313
}
314314
}
@@ -451,7 +451,7 @@ mod tests {
451451
// Environment.OSVersion on Windows 7 (CoreCLR 1.0+, .NET Framework 1.1+, Mono 1+)
452452
let mut os = OsContext {
453453
raw_description: "Microsoft Windows NT 6.1.7601 Service Pack 1"
454-
.to_string()
454+
.to_owned()
455455
.into(),
456456
..OsContext::default()
457457
};
@@ -574,7 +574,7 @@ mod tests {
574574
// RuntimeInformation.OSDescription on CentOS 7 (CoreCLR 2.0+, Mono 5.4+)
575575
let mut os = OsContext {
576576
raw_description: "Linux 3.10.0-693.21.1.el7.x86_64 #1 SMP Wed Mar 7 19:03:37 UTC 2018"
577-
.to_string()
577+
.to_owned()
578578
.into(),
579579
..OsContext::default()
580580
};
@@ -590,7 +590,7 @@ mod tests {
590590
// (CoreCLR 2.0+, Mono 5.4+)
591591
let mut os = OsContext {
592592
raw_description: "Linux 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014"
593-
.to_string()
593+
.to_owned()
594594
.into(),
595595
..OsContext::default()
596596
};
@@ -716,7 +716,7 @@ mod tests {
716716
fn test_unity_android_os() {
717717
let mut os = OsContext {
718718
raw_description: "Android OS 11 / API-30 (RP1A.201005.001/2107031736)"
719-
.to_string()
719+
.to_owned()
720720
.into(),
721721
..OsContext::default()
722722
};
@@ -763,7 +763,7 @@ mod tests {
763763
fn test_android_4_4_2() {
764764
let mut os = OsContext {
765765
raw_description: "Android OS 4.4.2 / API-19 (KOT49H/A536_S186_150813_ROW)"
766-
.to_string()
766+
.to_owned()
767767
.into(),
768768
..OsContext::default()
769769
};
@@ -776,7 +776,7 @@ mod tests {
776776
#[test]
777777
fn test_infer_json() {
778778
let mut response = ResponseContext {
779-
data: Annotated::from(Value::String(r#"{"foo":"bar"}"#.to_string())),
779+
data: Annotated::from(Value::String(r#"{"foo":"bar"}"#.to_owned())),
780780
..ResponseContext::default()
781781
};
782782

@@ -797,7 +797,7 @@ mod tests {
797797
#[test]
798798
fn test_broken_json_with_fallback() {
799799
let mut response = ResponseContext {
800-
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_string())),
800+
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_owned())),
801801
headers: Annotated::from(Headers(PairList(vec![Annotated::new((
802802
Annotated::new("Content-Type".to_owned().into()),
803803
Annotated::new("text/plain; encoding=utf-8".to_owned().into()),
@@ -813,7 +813,7 @@ mod tests {
813813
#[test]
814814
fn test_broken_json_without_fallback() {
815815
let mut response = ResponseContext {
816-
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_string())),
816+
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_owned())),
817817
..ResponseContext::default()
818818
};
819819

relay-event-normalization/src/normalize/request.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn normalize_url(request: &mut Request) {
5858
if let Some(fragment_index) = url_string.find('#') {
5959
let fragment = &url_string[fragment_index + 1..];
6060
if !fragment.is_empty() && request.fragment.value().is_none() {
61-
request.fragment.set_value(Some(fragment.to_string()));
61+
request.fragment.set_value(Some(fragment.to_owned()));
6262
}
6363
url_string.truncate(fragment_index);
6464
}
@@ -151,13 +151,13 @@ fn normalize_data(request: &mut Request) {
151151
// Retain meta data on the body (e.g. trimming annotations) but remove anything on the
152152
// inferred content type.
153153
request.data.set_value(Some(parsed_data));
154-
request.inferred_content_type = Annotated::from(content_type.to_string());
154+
request.inferred_content_type = Annotated::from(content_type.to_owned());
155155
} else {
156156
request.inferred_content_type = request
157157
.headers
158158
.value()
159159
.and_then(|headers| headers.get_header("Content-Type"))
160-
.map(|value| value.split(';').next().unwrap_or(value).to_string())
160+
.map(|value| value.split(';').next().unwrap_or(value).to_owned())
161161
.into();
162162
}
163163
}
@@ -439,7 +439,7 @@ mod tests {
439439
#[test]
440440
fn test_infer_json() {
441441
let mut request = Request {
442-
data: Annotated::from(Value::String(r#"{"foo":"bar"}"#.to_string())),
442+
data: Annotated::from(Value::String(r#"{"foo":"bar"}"#.to_owned())),
443443
..Request::default()
444444
};
445445

@@ -460,7 +460,7 @@ mod tests {
460460
#[test]
461461
fn test_broken_json_with_fallback() {
462462
let mut request = Request {
463-
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_string())),
463+
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_owned())),
464464
headers: Annotated::from(Headers(PairList(vec![Annotated::new((
465465
Annotated::new("Content-Type".to_owned().into()),
466466
Annotated::new("text/plain; encoding=utf-8".to_owned().into()),
@@ -476,7 +476,7 @@ mod tests {
476476
#[test]
477477
fn test_broken_json_without_fallback() {
478478
let mut request = Request {
479-
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_string())),
479+
data: Annotated::from(Value::String(r#"{"foo":"b"#.to_owned())),
480480
..Request::default()
481481
};
482482

@@ -488,7 +488,7 @@ mod tests {
488488
#[test]
489489
fn test_infer_url_encoded() {
490490
let mut request = Request {
491-
data: Annotated::from(Value::String(r#"foo=bar"#.to_string())),
491+
data: Annotated::from(Value::String(r#"foo=bar"#.to_owned())),
492492
..Request::default()
493493
};
494494

0 commit comments

Comments
 (0)