mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +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
|
// and valid URLs so we choose to be too eager to try to resolve what might be
|
||||||
// a URL.
|
// a URL.
|
||||||
if target.contains("://") {
|
if target.contains("://") {
|
||||||
(Some(LinkType::Inline), target.to_string(), title.to_string())
|
(Some(LinkType::Inline), target.to_owned(), title.to_owned())
|
||||||
} else {
|
} else {
|
||||||
// Two possibilities:
|
// Two possibilities:
|
||||||
// * path-based links: `../../module/struct.MyStruct.html`
|
// * 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) {
|
if let Some((target, title)) = rewrite_intra_doc_link(db, definition, target, title) {
|
||||||
(None, target, title)
|
(None, target, title)
|
||||||
} else if let Some(target) = rewrite_url_link(db, definition, target) {
|
} 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 {
|
} 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);
|
let (link, ns) = parse_intra_doc_link(&target);
|
||||||
Some((
|
Some((
|
||||||
TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
|
TextRange::new(range.start.try_into().ok()?, range.end.try_into().ok()?),
|
||||||
link.to_string(),
|
link.to_owned(),
|
||||||
ns,
|
ns,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -388,7 +388,7 @@ fn rewrite_intra_doc_link(
|
||||||
url = url.join(&file).ok()?;
|
url = url.join(&file).ok()?;
|
||||||
url.set_fragment(anchor);
|
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`).
|
/// 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) {
|
if let Some(region_name) = text.strip_prefix("// region:").map(str::trim) {
|
||||||
return Some(StructureNode {
|
return Some(StructureNode {
|
||||||
parent: None,
|
parent: None,
|
||||||
label: region_name.to_string(),
|
label: region_name.to_owned(),
|
||||||
navigation_range: comment.syntax().text_range(),
|
navigation_range: comment.syntax().text_range(),
|
||||||
node_range: comment.syntax().text_range(),
|
node_range: comment.syntax().text_range(),
|
||||||
kind: StructureNodeKind::Region,
|
kind: StructureNodeKind::Region,
|
||||||
|
|
|
@ -521,7 +521,7 @@ mod tests {
|
||||||
ReferenceCategory::Import => "import",
|
ReferenceCategory::Import => "import",
|
||||||
ReferenceCategory::Test => "test",
|
ReferenceCategory::Test => "test",
|
||||||
}
|
}
|
||||||
.to_string()
|
.to_owned()
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
@ -621,7 +621,7 @@ fn closure_ty(
|
||||||
})
|
})
|
||||||
.join("\n");
|
.join("\n");
|
||||||
if captures_rendered.trim().is_empty() {
|
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 targets: Vec<hir::ModuleDef> = Vec::new();
|
||||||
let mut push_new_def = |item: hir::ModuleDef| {
|
let mut push_new_def = |item: hir::ModuleDef| {
|
||||||
|
@ -823,7 +823,7 @@ fn keyword_hints(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => KeywordHint {
|
_ => KeywordHint {
|
||||||
description: token.text().to_string(),
|
description: token.text().to_owned(),
|
||||||
keyword_mod,
|
keyword_mod,
|
||||||
actions: Vec::new(),
|
actions: Vec::new(),
|
||||||
},
|
},
|
||||||
|
@ -835,9 +835,9 @@ fn keyword_hints(
|
||||||
Some(_) => format!("prim_{}", token.text()),
|
Some(_) => format!("prim_{}", token.text()),
|
||||||
None => format!("{}_keyword", 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()),
|
T![Self] => KeywordHint::new(token.text().to_owned(), "self_upper_keyword".into()),
|
||||||
_ => KeywordHint::new(token.text().to_string(), format!("{}_keyword", token.text())),
|
_ => 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 {
|
pub(crate) fn interpret_function(db: &RootDatabase, position: FilePosition) -> String {
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
let mut result = find_and_interpret(db, position)
|
let mut result =
|
||||||
.unwrap_or_else(|| "Not inside a function body".to_string());
|
find_and_interpret(db, position).unwrap_or_else(|| "Not inside a function body".to_owned());
|
||||||
let duration = Instant::now() - start_time;
|
let duration = Instant::now() - start_time;
|
||||||
writeln!(result).unwrap();
|
writeln!(result).unwrap();
|
||||||
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 range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
|
||||||
let replace_with = if no_space { "" } else { " " };
|
let replace_with = if no_space { "" } else { " " };
|
||||||
edit.replace(range, replace_with.to_string());
|
edit.replace(range, replace_with.to_owned());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ fn remove_newline(
|
||||||
};
|
};
|
||||||
edit.replace(
|
edit.replace(
|
||||||
TextRange::new(prev.text_range().start(), token.text_range().end()),
|
TextRange::new(prev.text_range().start(), token.text_range().end()),
|
||||||
space.to_string(),
|
space.to_owned(),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ fn remove_newline(
|
||||||
Some(_) => cov_mark::hit!(join_two_ifs_with_existing_else),
|
Some(_) => cov_mark::hit!(join_two_ifs_with_existing_else),
|
||||||
None => {
|
None => {
|
||||||
cov_mark::hit!(join_two_ifs);
|
cov_mark::hit!(join_two_ifs);
|
||||||
edit.replace(token.text_range(), " else ".to_string());
|
edit.replace(token.text_range(), " else ".to_owned());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ fn remove_newline(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove newline but add a computed amount of whitespace characters
|
// 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<()> {
|
fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> {
|
||||||
|
|
|
@ -238,7 +238,7 @@ impl Analysis {
|
||||||
let mut host = AnalysisHost::default();
|
let mut host = AnalysisHost::default();
|
||||||
let file_id = FileId::from_raw(0);
|
let file_id = FileId::from_raw(0);
|
||||||
let mut file_set = FileSet::default();
|
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 source_root = SourceRoot::new_local(file_set);
|
||||||
|
|
||||||
let mut change = Change::new();
|
let mut change = Change::new();
|
||||||
|
|
|
@ -383,18 +383,18 @@ pub(crate) fn def_to_moniker(
|
||||||
let (name, repo, version) = match krate.origin(db) {
|
let (name, repo, version) = match krate.origin(db) {
|
||||||
CrateOrigin::Library { repo, name } => (name, repo, krate.version(db)),
|
CrateOrigin::Library { repo, name } => (name, repo, krate.version(db)),
|
||||||
CrateOrigin::Local { repo, name } => (
|
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,
|
repo,
|
||||||
krate.version(db),
|
krate.version(db),
|
||||||
),
|
),
|
||||||
CrateOrigin::Rustc { name } => (
|
CrateOrigin::Rustc { name } => (
|
||||||
name.clone(),
|
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}",)),
|
Some(format!("https://github.com/rust-lang/rust/compiler/{name}",)),
|
||||||
),
|
),
|
||||||
CrateOrigin::Lang(lang) => (
|
CrateOrigin::Lang(lang) => (
|
||||||
krate.display_name(db)?.canonical_name().to_string(),
|
krate.display_name(db)?.canonical_name().to_owned(),
|
||||||
Some("https://github.com/rust-lang/rust/".to_string()),
|
Some("https://github.com/rust-lang/rust/".to_owned()),
|
||||||
Some(match lang {
|
Some(match lang {
|
||||||
LangCrateOrigin::Other => {
|
LangCrateOrigin::Other => {
|
||||||
"https://github.com/rust-lang/rust/library/".into()
|
"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#"
|
expect![[r#"
|
||||||
[
|
[
|
||||||
NavigationTarget {
|
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)
|
assert_eq!(navs.len(), 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ pub(crate) fn parallel_prime_caches(
|
||||||
work_sender
|
work_sender
|
||||||
.send((
|
.send((
|
||||||
crate_id,
|
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();
|
.ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ impl Runnable {
|
||||||
RunnableKind::Bench { test_id } => format!("bench {test_id}"),
|
RunnableKind::Bench { test_id } => format!("bench {test_id}"),
|
||||||
RunnableKind::DocTest { test_id, .. } => format!("doctest {test_id}"),
|
RunnableKind::DocTest { test_id, .. } => format!("doctest {test_id}"),
|
||||||
RunnableKind::Bin => {
|
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() {
|
for (label, source_change) in assists.into_iter() {
|
||||||
let assist = Assist {
|
let assist = Assist {
|
||||||
id,
|
id,
|
||||||
label: Label::new(label.to_string()),
|
label: Label::new(label.to_owned()),
|
||||||
group: Some(GroupLabel("Apply SSR".into())),
|
group: Some(GroupLabel("Apply SSR".into())),
|
||||||
target: comment_range,
|
target: comment_range,
|
||||||
source_change,
|
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
|
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> {
|
fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<String> {
|
||||||
// Range of the full node
|
// Range of the full node
|
||||||
let node_range = node.text_range();
|
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
|
// We start at some point inside the node
|
||||||
// Either we have selected the whole string
|
// 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)?;
|
let tree: ast::UseTree = find_node_at_offset(file.syntax(), offset)?;
|
||||||
|
|
||||||
Some(TextEdit::insert(
|
Some(TextEdit::insert(tree.syntax().text_range().end() + TextSize::of("{"), "}".to_owned()))
|
||||||
tree.syntax().text_range().end() + TextSize::of("{"),
|
|
||||||
"}".to_string(),
|
|
||||||
))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bracket_expr(
|
fn bracket_expr(
|
||||||
|
@ -235,7 +232,7 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let offset = expr.syntax().text_range().end();
|
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.
|
/// `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;
|
return None;
|
||||||
}
|
}
|
||||||
let offset = let_stmt.syntax().text_range().end();
|
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 let Some(t) = file.syntax().token_at_offset(offset).left_biased() {
|
||||||
if T![impl] == t.kind() {
|
if T![impl] == t.kind() {
|
||||||
return Some(ExtendedTextEdit {
|
return Some(ExtendedTextEdit {
|
||||||
edit: TextEdit::replace(range, "<$0>".to_string()),
|
edit: TextEdit::replace(range, "<$0>".to_owned()),
|
||||||
is_snippet: true,
|
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())
|
ast::GenericParamList::can_cast(n.kind()) || ast::GenericArgList::can_cast(n.kind())
|
||||||
}) {
|
}) {
|
||||||
Some(ExtendedTextEdit {
|
Some(ExtendedTextEdit {
|
||||||
edit: TextEdit::replace(range, "<$0>".to_string()),
|
edit: TextEdit::replace(range, "<$0>".to_owned()),
|
||||||
is_snippet: true,
|
is_snippet: true,
|
||||||
})
|
})
|
||||||
} else {
|
} 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)?;
|
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)]
|
#[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[]
|
// image::https://user-images.githubusercontent.com/48062697/113065588-068bdb80-91b1-11eb-9a78-0b4ef1e972fb.gif[]
|
||||||
pub(crate) fn view_hir(db: &RootDatabase, position: FilePosition) -> String {
|
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> {
|
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**
|
// | VS Code | **rust-analyzer: View Mir**
|
||||||
// |===
|
// |===
|
||||||
pub(crate) fn view_mir(db: &RootDatabase, position: FilePosition) -> String {
|
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> {
|
fn body_mir(db: &RootDatabase, position: FilePosition) -> Option<String> {
|
||||||
|
|
Loading…
Reference in a new issue