Skip to content

Commit 8c2f301

Browse files
ide: Fix warnings about clippy str_to_string rule
1 parent bb0de88 commit 8c2f301

17 files changed

+38
-41
lines changed

crates/ide/src/doc_links.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: Defin
5858
// and valid URLs so we choose to be too eager to try to resolve what might be
5959
// a URL.
6060
if target.contains("://") {
61-
(Some(LinkType::Inline), target.to_string(), title.to_string())
61+
(Some(LinkType::Inline), target.to_owned(), title.to_owned())
6262
} else {
6363
// Two possibilities:
6464
// * path-based links: `../../module/struct.MyStruct.html`
6565
// * module-based links (AKA intra-doc links): `super::super::module::MyStruct`
6666
if let Some((target, title)) = rewrite_intra_doc_link(db, definition, target, title) {
6767
(None, target, title)
6868
} else if let Some(target) = rewrite_url_link(db, definition, target) {
69-
(Some(LinkType::Inline), target, title.to_string())
69+
(Some(LinkType::Inline), target, title.to_owned())
7070
} else {
71-
(None, target.to_string(), title.to_string())
71+
(None, target.to_owned(), title.to_owned())
7272
}
7373
}
7474
});
@@ -186,7 +186,7 @@ pub(crate) fn extract_definitions_from_docs(
186186
let (link, ns) = parse_intra_doc_link(&target);
187187
Some((
188188
TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
189-
link.to_string(),
189+
link.to_owned(),
190190
ns,
191191
))
192192
}
@@ -388,7 +388,7 @@ fn rewrite_intra_doc_link(
388388
url = url.join(&file).ok()?;
389389
url.set_fragment(anchor);
390390

391-
Some((url.into(), strip_prefixes_suffixes(title).to_string()))
391+
Some((url.into(), strip_prefixes_suffixes(title).to_owned()))
392392
}
393393

394394
/// Try to resolve path to local documentation via path-based links (i.e. `../gateway/struct.Shard.html`).

crates/ide/src/file_structure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn structure_token(token: SyntaxToken) -> Option<StructureNode> {
193193
if let Some(region_name) = text.strip_prefix("// region:").map(str::trim) {
194194
return Some(StructureNode {
195195
parent: None,
196-
label: region_name.to_string(),
196+
label: region_name.to_owned(),
197197
navigation_range: comment.syntax().text_range(),
198198
node_range: comment.syntax().text_range(),
199199
kind: StructureNodeKind::Region,

crates/ide/src/highlight_related.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ mod tests {
521521
ReferenceCategory::Import => "import",
522522
ReferenceCategory::Test => "test",
523523
}
524-
.to_string()
524+
.to_owned()
525525
}),
526526
)
527527
})

crates/ide/src/hover/render.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ fn closure_ty(
621621
})
622622
.join("\n");
623623
if captures_rendered.trim().is_empty() {
624-
captures_rendered = "This closure captures nothing".to_string();
624+
captures_rendered = "This closure captures nothing".to_owned();
625625
}
626626
let mut targets: Vec<hir::ModuleDef> = Vec::new();
627627
let mut push_new_def = |item: hir::ModuleDef| {
@@ -823,7 +823,7 @@ fn keyword_hints(
823823
}
824824
}
825825
_ => KeywordHint {
826-
description: token.text().to_string(),
826+
description: token.text().to_owned(),
827827
keyword_mod,
828828
actions: Vec::new(),
829829
},
@@ -835,9 +835,9 @@ fn keyword_hints(
835835
Some(_) => format!("prim_{}", token.text()),
836836
None => format!("{}_keyword", token.text()),
837837
};
838-
KeywordHint::new(token.text().to_string(), module)
838+
KeywordHint::new(token.text().to_owned(), module)
839839
}
840-
T![Self] => KeywordHint::new(token.text().to_string(), "self_upper_keyword".into()),
841-
_ => KeywordHint::new(token.text().to_string(), format!("{}_keyword", token.text())),
840+
T![Self] => KeywordHint::new(token.text().to_owned(), "self_upper_keyword".into()),
841+
_ => KeywordHint::new(token.text().to_owned(), format!("{}_keyword", token.text())),
842842
}
843843
}

crates/ide/src/interpret_function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use syntax::{algo::ancestors_at_offset, ast, AstNode, TextRange};
1515
// |===
1616
pub(crate) fn interpret_function(db: &RootDatabase, position: FilePosition) -> String {
1717
let start_time = Instant::now();
18-
let mut result = find_and_interpret(db, position)
19-
.unwrap_or_else(|| "Not inside a function body".to_string());
18+
let mut result =
19+
find_and_interpret(db, position).unwrap_or_else(|| "Not inside a function body".to_owned());
2020
let duration = Instant::now() - start_time;
2121
writeln!(result).unwrap();
2222
writeln!(result, "----------------------").unwrap();

crates/ide/src/join_lines.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn remove_newline(
115115

116116
let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
117117
let replace_with = if no_space { "" } else { " " };
118-
edit.replace(range, replace_with.to_string());
118+
edit.replace(range, replace_with.to_owned());
119119
return;
120120
}
121121

@@ -140,7 +140,7 @@ fn remove_newline(
140140
};
141141
edit.replace(
142142
TextRange::new(prev.text_range().start(), token.text_range().end()),
143-
space.to_string(),
143+
space.to_owned(),
144144
);
145145
return;
146146
}
@@ -154,7 +154,7 @@ fn remove_newline(
154154
Some(_) => cov_mark::hit!(join_two_ifs_with_existing_else),
155155
None => {
156156
cov_mark::hit!(join_two_ifs);
157-
edit.replace(token.text_range(), " else ".to_string());
157+
edit.replace(token.text_range(), " else ".to_owned());
158158
return;
159159
}
160160
}
@@ -203,7 +203,7 @@ fn remove_newline(
203203
}
204204

205205
// Remove newline but add a computed amount of whitespace characters
206-
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
206+
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_owned());
207207
}
208208

209209
fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> {

crates/ide/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl Analysis {
238238
let mut host = AnalysisHost::default();
239239
let file_id = FileId::from_raw(0);
240240
let mut file_set = FileSet::default();
241-
file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string()));
241+
file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_owned()));
242242
let source_root = SourceRoot::new_local(file_set);
243243

244244
let mut change = Change::new();

crates/ide/src/moniker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,18 +383,18 @@ pub(crate) fn def_to_moniker(
383383
let (name, repo, version) = match krate.origin(db) {
384384
CrateOrigin::Library { repo, name } => (name, repo, krate.version(db)),
385385
CrateOrigin::Local { repo, name } => (
386-
name.unwrap_or(krate.display_name(db)?.canonical_name().to_string()),
386+
name.unwrap_or(krate.display_name(db)?.canonical_name().to_owned()),
387387
repo,
388388
krate.version(db),
389389
),
390390
CrateOrigin::Rustc { name } => (
391391
name.clone(),
392-
Some("https://github.com/rust-lang/rust/".to_string()),
392+
Some("https://github.com/rust-lang/rust/".to_owned()),
393393
Some(format!("https://github.com/rust-lang/rust/compiler/{name}",)),
394394
),
395395
CrateOrigin::Lang(lang) => (
396-
krate.display_name(db)?.canonical_name().to_string(),
397-
Some("https://github.com/rust-lang/rust/".to_string()),
396+
krate.display_name(db)?.canonical_name().to_owned(),
397+
Some("https://github.com/rust-lang/rust/".to_owned()),
398398
Some(match lang {
399399
LangCrateOrigin::Other => {
400400
"https://github.com/rust-lang/rust/library/".into()

crates/ide/src/navigation_target.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ fn foo() { enum FooInner { } }
860860
"#,
861861
);
862862

863-
let navs = analysis.symbol_search(Query::new("FooInner".to_string()), !0).unwrap();
863+
let navs = analysis.symbol_search(Query::new("FooInner".to_owned()), !0).unwrap();
864864
expect![[r#"
865865
[
866866
NavigationTarget {
@@ -898,7 +898,7 @@ struct Foo;
898898
"#,
899899
);
900900

901-
let navs = analysis.symbol_search(Query::new("foo".to_string()), !0).unwrap();
901+
let navs = analysis.symbol_search(Query::new("foo".to_owned()), !0).unwrap();
902902
assert_eq!(navs.len(), 2)
903903
}
904904
}

crates/ide/src/prime_caches.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(crate) fn parallel_prime_caches(
105105
work_sender
106106
.send((
107107
crate_id,
108-
graph[crate_id].display_name.as_deref().unwrap_or_default().to_string(),
108+
graph[crate_id].display_name.as_deref().unwrap_or_default().to_owned(),
109109
))
110110
.ok();
111111
}

0 commit comments

Comments
 (0)