mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
ide: Fix warnings about clippy str_to_string
rule
This commit is contained in:
parent
bb0de88f24
commit
8c2f301a41
17 changed files with 38 additions and 41 deletions
|
@ -58,7 +58,7 @@ pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: Defin
|
|||
// and valid URLs so we choose to be too eager to try to resolve what might be
|
||||
// a URL.
|
||||
if target.contains("://") {
|
||||
(Some(LinkType::Inline), target.to_string(), title.to_string())
|
||||
(Some(LinkType::Inline), target.to_owned(), title.to_owned())
|
||||
} else {
|
||||
// Two possibilities:
|
||||
// * path-based links: `../../module/struct.MyStruct.html`
|
||||
|
@ -66,9 +66,9 @@ pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: Defin
|
|||
if let Some((target, title)) = rewrite_intra_doc_link(db, definition, target, title) {
|
||||
(None, target, title)
|
||||
} else if let Some(target) = rewrite_url_link(db, definition, target) {
|
||||
(Some(LinkType::Inline), target, title.to_string())
|
||||
(Some(LinkType::Inline), target, title.to_owned())
|
||||
} else {
|
||||
(None, target.to_string(), title.to_string())
|
||||
(None, target.to_owned(), title.to_owned())
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -186,7 +186,7 @@ pub(crate) fn extract_definitions_from_docs(
|
|||
let (link, ns) = parse_intra_doc_link(&target);
|
||||
Some((
|
||||
TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
|
||||
link.to_string(),
|
||||
link.to_owned(),
|
||||
ns,
|
||||
))
|
||||
}
|
||||
|
@ -388,7 +388,7 @@ fn rewrite_intra_doc_link(
|
|||
url = url.join(&file).ok()?;
|
||||
url.set_fragment(anchor);
|
||||
|
||||
Some((url.into(), strip_prefixes_suffixes(title).to_string()))
|
||||
Some((url.into(), strip_prefixes_suffixes(title).to_owned()))
|
||||
}
|
||||
|
||||
/// Try to resolve path to local documentation via path-based links (i.e. `../gateway/struct.Shard.html`).
|
||||
|
|
|
@ -193,7 +193,7 @@ fn structure_token(token: SyntaxToken) -> Option<StructureNode> {
|
|||
if let Some(region_name) = text.strip_prefix("// region:").map(str::trim) {
|
||||
return Some(StructureNode {
|
||||
parent: None,
|
||||
label: region_name.to_string(),
|
||||
label: region_name.to_owned(),
|
||||
navigation_range: comment.syntax().text_range(),
|
||||
node_range: comment.syntax().text_range(),
|
||||
kind: StructureNodeKind::Region,
|
||||
|
|
|
@ -521,7 +521,7 @@ mod tests {
|
|||
ReferenceCategory::Import => "import",
|
||||
ReferenceCategory::Test => "test",
|
||||
}
|
||||
.to_string()
|
||||
.to_owned()
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
|
|
@ -621,7 +621,7 @@ fn closure_ty(
|
|||
})
|
||||
.join("\n");
|
||||
if captures_rendered.trim().is_empty() {
|
||||
captures_rendered = "This closure captures nothing".to_string();
|
||||
captures_rendered = "This closure captures nothing".to_owned();
|
||||
}
|
||||
let mut targets: Vec<hir::ModuleDef> = Vec::new();
|
||||
let mut push_new_def = |item: hir::ModuleDef| {
|
||||
|
@ -823,7 +823,7 @@ fn keyword_hints(
|
|||
}
|
||||
}
|
||||
_ => KeywordHint {
|
||||
description: token.text().to_string(),
|
||||
description: token.text().to_owned(),
|
||||
keyword_mod,
|
||||
actions: Vec::new(),
|
||||
},
|
||||
|
@ -835,9 +835,9 @@ fn keyword_hints(
|
|||
Some(_) => format!("prim_{}", token.text()),
|
||||
None => format!("{}_keyword", token.text()),
|
||||
};
|
||||
KeywordHint::new(token.text().to_string(), module)
|
||||
KeywordHint::new(token.text().to_owned(), module)
|
||||
}
|
||||
T![Self] => KeywordHint::new(token.text().to_string(), "self_upper_keyword".into()),
|
||||
_ => KeywordHint::new(token.text().to_string(), format!("{}_keyword", token.text())),
|
||||
T![Self] => KeywordHint::new(token.text().to_owned(), "self_upper_keyword".into()),
|
||||
_ => KeywordHint::new(token.text().to_owned(), format!("{}_keyword", token.text())),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ use syntax::{algo::ancestors_at_offset, ast, AstNode, TextRange};
|
|||
// |===
|
||||
pub(crate) fn interpret_function(db: &RootDatabase, position: FilePosition) -> String {
|
||||
let start_time = Instant::now();
|
||||
let mut result = find_and_interpret(db, position)
|
||||
.unwrap_or_else(|| "Not inside a function body".to_string());
|
||||
let mut result =
|
||||
find_and_interpret(db, position).unwrap_or_else(|| "Not inside a function body".to_owned());
|
||||
let duration = Instant::now() - start_time;
|
||||
writeln!(result).unwrap();
|
||||
writeln!(result, "----------------------").unwrap();
|
||||
|
|
|
@ -115,7 +115,7 @@ fn remove_newline(
|
|||
|
||||
let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
|
||||
let replace_with = if no_space { "" } else { " " };
|
||||
edit.replace(range, replace_with.to_string());
|
||||
edit.replace(range, replace_with.to_owned());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ fn remove_newline(
|
|||
};
|
||||
edit.replace(
|
||||
TextRange::new(prev.text_range().start(), token.text_range().end()),
|
||||
space.to_string(),
|
||||
space.to_owned(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ fn remove_newline(
|
|||
Some(_) => cov_mark::hit!(join_two_ifs_with_existing_else),
|
||||
None => {
|
||||
cov_mark::hit!(join_two_ifs);
|
||||
edit.replace(token.text_range(), " else ".to_string());
|
||||
edit.replace(token.text_range(), " else ".to_owned());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ fn remove_newline(
|
|||
}
|
||||
|
||||
// Remove newline but add a computed amount of whitespace characters
|
||||
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
|
||||
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_owned());
|
||||
}
|
||||
|
||||
fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> {
|
||||
|
|
|
@ -238,7 +238,7 @@ impl Analysis {
|
|||
let mut host = AnalysisHost::default();
|
||||
let file_id = FileId::from_raw(0);
|
||||
let mut file_set = FileSet::default();
|
||||
file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_string()));
|
||||
file_set.insert(file_id, VfsPath::new_virtual_path("/main.rs".to_owned()));
|
||||
let source_root = SourceRoot::new_local(file_set);
|
||||
|
||||
let mut change = Change::new();
|
||||
|
|
|
@ -383,18 +383,18 @@ pub(crate) fn def_to_moniker(
|
|||
let (name, repo, version) = match krate.origin(db) {
|
||||
CrateOrigin::Library { repo, name } => (name, repo, krate.version(db)),
|
||||
CrateOrigin::Local { repo, name } => (
|
||||
name.unwrap_or(krate.display_name(db)?.canonical_name().to_string()),
|
||||
name.unwrap_or(krate.display_name(db)?.canonical_name().to_owned()),
|
||||
repo,
|
||||
krate.version(db),
|
||||
),
|
||||
CrateOrigin::Rustc { name } => (
|
||||
name.clone(),
|
||||
Some("https://github.com/rust-lang/rust/".to_string()),
|
||||
Some("https://github.com/rust-lang/rust/".to_owned()),
|
||||
Some(format!("https://github.com/rust-lang/rust/compiler/{name}",)),
|
||||
),
|
||||
CrateOrigin::Lang(lang) => (
|
||||
krate.display_name(db)?.canonical_name().to_string(),
|
||||
Some("https://github.com/rust-lang/rust/".to_string()),
|
||||
krate.display_name(db)?.canonical_name().to_owned(),
|
||||
Some("https://github.com/rust-lang/rust/".to_owned()),
|
||||
Some(match lang {
|
||||
LangCrateOrigin::Other => {
|
||||
"https://github.com/rust-lang/rust/library/".into()
|
||||
|
|
|
@ -860,7 +860,7 @@ fn foo() { enum FooInner { } }
|
|||
"#,
|
||||
);
|
||||
|
||||
let navs = analysis.symbol_search(Query::new("FooInner".to_string()), !0).unwrap();
|
||||
let navs = analysis.symbol_search(Query::new("FooInner".to_owned()), !0).unwrap();
|
||||
expect![[r#"
|
||||
[
|
||||
NavigationTarget {
|
||||
|
@ -898,7 +898,7 @@ struct Foo;
|
|||
"#,
|
||||
);
|
||||
|
||||
let navs = analysis.symbol_search(Query::new("foo".to_string()), !0).unwrap();
|
||||
let navs = analysis.symbol_search(Query::new("foo".to_owned()), !0).unwrap();
|
||||
assert_eq!(navs.len(), 2)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ pub(crate) fn parallel_prime_caches(
|
|||
work_sender
|
||||
.send((
|
||||
crate_id,
|
||||
graph[crate_id].display_name.as_deref().unwrap_or_default().to_string(),
|
||||
graph[crate_id].display_name.as_deref().unwrap_or_default().to_owned(),
|
||||
))
|
||||
.ok();
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Runnable {
|
|||
RunnableKind::Bench { test_id } => format!("bench {test_id}"),
|
||||
RunnableKind::DocTest { test_id, .. } => format!("doctest {test_id}"),
|
||||
RunnableKind::Bin => {
|
||||
target.map_or_else(|| "run binary".to_string(), |t| format!("run {t}"))
|
||||
target.map_or_else(|| "run binary".to_owned(), |t| format!("run {t}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) fn ssr_assists(
|
|||
for (label, source_change) in assists.into_iter() {
|
||||
let assist = Assist {
|
||||
id,
|
||||
label: Label::new(label.to_string()),
|
||||
label: Label::new(label.to_owned()),
|
||||
group: Some(GroupLabel("Apply SSR".into())),
|
||||
target: comment_range,
|
||||
source_change,
|
||||
|
|
|
@ -105,7 +105,7 @@ pub(crate) fn status(db: &RootDatabase, file_id: Option<FileId>) -> String {
|
|||
}
|
||||
}
|
||||
|
||||
buf.trim().to_string()
|
||||
buf.trim().to_owned()
|
||||
}
|
||||
|
||||
fn collect_query<'q, Q>(table: QueryTable<'q, Q>) -> <Q as QueryCollect>::Collector
|
||||
|
|
|
@ -55,7 +55,7 @@ fn syntax_tree_for_string(token: &SyntaxToken, text_range: TextRange) -> Option<
|
|||
fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<String> {
|
||||
// Range of the full node
|
||||
let node_range = node.text_range();
|
||||
let text = node.text().to_string();
|
||||
let text = node.text().to_owned();
|
||||
|
||||
// We start at some point inside the node
|
||||
// Either we have selected the whole string
|
||||
|
|
|
@ -149,10 +149,7 @@ fn on_opening_bracket_typed(
|
|||
|
||||
let tree: ast::UseTree = find_node_at_offset(file.syntax(), offset)?;
|
||||
|
||||
Some(TextEdit::insert(
|
||||
tree.syntax().text_range().end() + TextSize::of("{"),
|
||||
"}".to_string(),
|
||||
))
|
||||
Some(TextEdit::insert(tree.syntax().text_range().end() + TextSize::of("{"), "}".to_owned()))
|
||||
}
|
||||
|
||||
fn bracket_expr(
|
||||
|
@ -235,7 +232,7 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
|
|||
return None;
|
||||
}
|
||||
let offset = expr.syntax().text_range().end();
|
||||
Some(TextEdit::insert(offset, ";".to_string()))
|
||||
Some(TextEdit::insert(offset, ";".to_owned()))
|
||||
}
|
||||
|
||||
/// `a =$0 b;` removes the semicolon if an expression is valid in this context.
|
||||
|
@ -275,7 +272,7 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
|
|||
return None;
|
||||
}
|
||||
let offset = let_stmt.syntax().text_range().end();
|
||||
Some(TextEdit::insert(offset, ";".to_string()))
|
||||
Some(TextEdit::insert(offset, ";".to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +350,7 @@ fn on_left_angle_typed(file: &SourceFile, offset: TextSize) -> Option<ExtendedTe
|
|||
if let Some(t) = file.syntax().token_at_offset(offset).left_biased() {
|
||||
if T![impl] == t.kind() {
|
||||
return Some(ExtendedTextEdit {
|
||||
edit: TextEdit::replace(range, "<$0>".to_string()),
|
||||
edit: TextEdit::replace(range, "<$0>".to_owned()),
|
||||
is_snippet: true,
|
||||
});
|
||||
}
|
||||
|
@ -363,7 +360,7 @@ fn on_left_angle_typed(file: &SourceFile, offset: TextSize) -> Option<ExtendedTe
|
|||
ast::GenericParamList::can_cast(n.kind()) || ast::GenericArgList::can_cast(n.kind())
|
||||
}) {
|
||||
Some(ExtendedTextEdit {
|
||||
edit: TextEdit::replace(range, "<$0>".to_string()),
|
||||
edit: TextEdit::replace(range, "<$0>".to_owned()),
|
||||
is_snippet: true,
|
||||
})
|
||||
} else {
|
||||
|
@ -383,7 +380,7 @@ fn on_right_angle_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit>
|
|||
}
|
||||
find_node_at_offset::<ast::RetType>(file.syntax(), offset)?;
|
||||
|
||||
Some(TextEdit::insert(after_arrow, " ".to_string()))
|
||||
Some(TextEdit::insert(after_arrow, " ".to_owned()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -12,7 +12,7 @@ use syntax::{algo::ancestors_at_offset, ast, AstNode};
|
|||
// |===
|
||||
// image::https://user-images.githubusercontent.com/48062697/113065588-068bdb80-91b1-11eb-9a78-0b4ef1e972fb.gif[]
|
||||
pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String {
|
||||
body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_string())
|
||||
body_hir(db, position).unwrap_or_else(|| "Not inside a function body".to_owned())
|
||||
}
|
||||
|
||||
fn body_hir(db: &RootDatabase, position: FilePosition) -> Option<String> {
|
||||
|
|
|
@ -11,7 +11,7 @@ use syntax::{algo::ancestors_at_offset, ast, AstNode};
|
|||
// | VS Code | **rust-analyzer: View Mir**
|
||||
// |===
|
||||
pub(crate) fn view_mir(db: &RootDatabase, position: FilePosition) -> String {
|
||||
body_mir(db, position).unwrap_or_else(|| "Not inside a function body".to_string())
|
||||
body_mir(db, position).unwrap_or_else(|| "Not inside a function body".to_owned())
|
||||
}
|
||||
|
||||
fn body_mir(db: &RootDatabase, position: FilePosition) -> Option<String> {
|
||||
|
|
Loading…
Reference in a new issue