Unnamed repository; edit this file 'description' to name the repository.
rust-analyzer: Fix warnings about clippy `str_to_string` rule
Tetsuharu Ohzeki 2024-02-09
parent 80e6842 · commit 395708d
-rw-r--r--crates/rust-analyzer/src/bin/main.rs4
-rw-r--r--crates/rust-analyzer/src/caps.rs16
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs8
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs2
-rw-r--r--crates/rust-analyzer/src/cli/lsif.rs10
-rw-r--r--crates/rust-analyzer/src/cli/progress_report.rs2
-rw-r--r--crates/rust-analyzer/src/cli/run_tests.rs2
-rw-r--r--crates/rust-analyzer/src/cli/scip.rs14
-rw-r--r--crates/rust-analyzer/src/config.rs4
-rw-r--r--crates/rust-analyzer/src/config/patch_old_style.rs2
-rw-r--r--crates/rust-analyzer/src/diagnostics.rs4
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs12
-rw-r--r--crates/rust-analyzer/src/dispatch.rs6
-rw-r--r--crates/rust-analyzer/src/global_state.rs4
-rw-r--r--crates/rust-analyzer/src/handlers/notification.rs4
-rw-r--r--crates/rust-analyzer/src/handlers/request.rs20
-rw-r--r--crates/rust-analyzer/src/lsp/from_proto.rs2
-rw-r--r--crates/rust-analyzer/src/lsp/to_proto.rs8
-rw-r--r--crates/rust-analyzer/src/lsp/utils.rs27
-rw-r--r--crates/rust-analyzer/src/main_loop.rs18
-rw-r--r--crates/rust-analyzer/src/reload.rs6
-rw-r--r--crates/rust-analyzer/tests/slow-tests/main.rs30
-rw-r--r--crates/rust-analyzer/tests/slow-tests/support.rs8
-rw-r--r--crates/rust-analyzer/tests/slow-tests/tidy.rs2
24 files changed, 107 insertions, 108 deletions
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 72dc67b48a..269dd3cfff 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -134,7 +134,7 @@ fn setup_logging(log_file_flag: Option<PathBuf>) -> anyhow::Result<()> {
writer,
// Deliberately enable all `error` logs if the user has not set RA_LOG, as there is usually
// useful information in there for debugging.
- filter: env::var("RA_LOG").ok().unwrap_or_else(|| "error".to_string()),
+ filter: env::var("RA_LOG").ok().unwrap_or_else(|| "error".to_owned()),
chalk_filter: env::var("CHALK_DEBUG").ok(),
profile_filter: env::var("RA_PROFILE").ok(),
}
@@ -224,7 +224,7 @@ fn run_server() -> anyhow::Result<()> {
MessageType, ShowMessageParams,
};
let not = lsp_server::Notification::new(
- ShowMessage::METHOD.to_string(),
+ ShowMessage::METHOD.to_owned(),
ShowMessageParams { typ: MessageType::WARNING, message: e.to_string() },
);
connection.sender.send(lsp_server::Message::Notification(not)).unwrap();
diff --git a/crates/rust-analyzer/src/caps.rs b/crates/rust-analyzer/src/caps.rs
index 94eab97e8f..a1469c22ab 100644
--- a/crates/rust-analyzer/src/caps.rs
+++ b/crates/rust-analyzer/src/caps.rs
@@ -44,17 +44,17 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
completion_provider: Some(CompletionOptions {
resolve_provider: completions_resolve_provider(config.caps()),
trigger_characters: Some(vec![
- ":".to_string(),
- ".".to_string(),
- "'".to_string(),
- "(".to_string(),
+ ":".to_owned(),
+ ".".to_owned(),
+ "'".to_owned(),
+ "(".to_owned(),
]),
all_commit_characters: None,
completion_item: completion_item(config),
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
}),
signature_help_provider: Some(SignatureHelpOptions {
- trigger_characters: Some(vec!["(".to_string(), ",".to_string(), "<".to_string()]),
+ trigger_characters: Some(vec!["(".to_owned(), ",".to_owned(), "<".to_owned()]),
retrigger_characters: None,
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
}),
@@ -74,7 +74,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
_ => Some(OneOf::Left(false)),
},
document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions {
- first_trigger_character: "=".to_string(),
+ first_trigger_character: "=".to_owned(),
more_trigger_character: Some(more_trigger_character(config)),
}),
selection_range_provider: Some(SelectionRangeProviderCapability::Simple(true)),
@@ -222,9 +222,9 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi
}
fn more_trigger_character(config: &Config) -> Vec<String> {
- let mut res = vec![".".to_string(), ">".to_string(), "{".to_string(), "(".to_string()];
+ let mut res = vec![".".to_owned(), ">".to_owned(), "{".to_owned(), "(".to_owned()];
if config.snippet_cap() {
- res.push("<".to_string());
+ res.push("<".to_owned());
}
res
}
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 31bdd2a0e8..2741b45222 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -397,7 +397,7 @@ impl flags::AnalysisStats {
module
.krate()
.display_name(db)
- .map(|it| it.canonical_name().to_string())
+ .map(|it| it.canonical_name().to_owned())
.into_iter()
.chain(
module
@@ -688,7 +688,7 @@ impl flags::AnalysisStats {
module
.krate()
.display_name(db)
- .map(|it| it.canonical_name().to_string())
+ .map(|it| it.canonical_name().to_owned())
.into_iter()
.chain(
module
@@ -833,7 +833,7 @@ impl flags::AnalysisStats {
fn location_csv_expr(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, expr_id: ExprId) -> String {
let src = match sm.expr_syntax(expr_id) {
Ok(s) => s,
- Err(SyntheticSyntax) => return "synthetic,,".to_string(),
+ Err(SyntheticSyntax) => return "synthetic,,".to_owned(),
};
let root = db.parse_or_expand(src.file_id);
let node = src.map(|e| e.to_node(&root).syntax().clone());
@@ -849,7 +849,7 @@ fn location_csv_expr(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, expr_id:
fn location_csv_pat(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, pat_id: PatId) -> String {
let src = match sm.pat_syntax(pat_id) {
Ok(s) => s,
- Err(SyntheticSyntax) => return "synthetic,,".to_string(),
+ Err(SyntheticSyntax) => return "synthetic,,".to_owned(),
};
let root = db.parse_or_expand(src.file_id);
let node = src.map(|e| e.to_node(&root).syntax().clone());
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 6d2e97be20..605670f6a8 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -45,7 +45,7 @@ impl flags::Diagnostics {
let file_id = module.definition_source_file_id(db).original_file(db);
if !visited_files.contains(&file_id) {
let crate_name =
- module.krate().display_name(db).as_deref().unwrap_or("unknown").to_string();
+ module.krate().display_name(db).as_deref().unwrap_or("unknown").to_owned();
println!("processing crate: {crate_name}, module: {}", _vfs.file_path(file_id));
for diagnostic in analysis
.diagnostics(
diff --git a/crates/rust-analyzer/src/cli/lsif.rs b/crates/rust-analyzer/src/cli/lsif.rs
index 1b6187f8df..1424a77577 100644
--- a/crates/rust-analyzer/src/cli/lsif.rs
+++ b/crates/rust-analyzer/src/cli/lsif.rs
@@ -104,12 +104,12 @@ impl LsifManager<'_> {
let result_set_id =
self.add_vertex(lsif::Vertex::PackageInformation(lsif::PackageInformation {
name: pi.name,
- manager: "cargo".to_string(),
+ manager: "cargo".to_owned(),
uri: None,
content: None,
repository: pi.repo.map(|url| lsif::Repository {
url,
- r#type: "git".to_string(),
+ r#type: "git".to_owned(),
commit_id: None,
}),
version: pi.version,
@@ -148,7 +148,7 @@ impl LsifManager<'_> {
let path = self.vfs.file_path(id);
let path = path.as_path().unwrap();
let doc_id = self.add_vertex(lsif::Vertex::Document(lsif::Document {
- language_id: "rust".to_string(),
+ language_id: "rust".to_owned(),
uri: lsp_types::Url::from_file_path(path).unwrap(),
}));
self.file_map.insert(id, doc_id);
@@ -175,7 +175,7 @@ impl LsifManager<'_> {
if let Some(moniker) = token.moniker {
let package_id = self.get_package_id(moniker.package_information);
let moniker_id = self.add_vertex(lsif::Vertex::Moniker(lsp_types::Moniker {
- scheme: "rust-analyzer".to_string(),
+ scheme: "rust-analyzer".to_owned(),
identifier: moniker.identifier.to_string(),
unique: lsp_types::UniquenessLevel::Scheme,
kind: Some(match moniker.kind {
@@ -313,7 +313,7 @@ impl flags::Lsif {
project_root: lsp_types::Url::from_file_path(path).unwrap(),
position_encoding: lsif::Encoding::Utf16,
tool_info: Some(lsp_types::lsif::ToolInfo {
- name: "rust-analyzer".to_string(),
+ name: "rust-analyzer".to_owned(),
args: vec![],
version: Some(version().to_string()),
}),
diff --git a/crates/rust-analyzer/src/cli/progress_report.rs b/crates/rust-analyzer/src/cli/progress_report.rs
index 8166aa23b4..b233730099 100644
--- a/crates/rust-analyzer/src/cli/progress_report.rs
+++ b/crates/rust-analyzer/src/cli/progress_report.rs
@@ -92,7 +92,7 @@ impl<'a> ProgressReport<'a> {
let _ = io::stdout().write(output.as_bytes());
let _ = io::stdout().flush();
- self.text = text.to_string();
+ self.text = text.to_owned();
}
fn set_value(&mut self, value: f32) {
diff --git a/crates/rust-analyzer/src/cli/run_tests.rs b/crates/rust-analyzer/src/cli/run_tests.rs
index d07dcdec25..6b43e09542 100644
--- a/crates/rust-analyzer/src/cli/run_tests.rs
+++ b/crates/rust-analyzer/src/cli/run_tests.rs
@@ -34,7 +34,7 @@ impl flags::RunTests {
.filter(|x| x.is_test(db));
let span_formatter = |file_id, text_range: TextRange| {
let line_col = match db.line_index(file_id).try_line_col(text_range.start()) {
- None => " (unknown line col)".to_string(),
+ None => " (unknown line col)".to_owned(),
Some(x) => format!("#{}:{}", x.line + 1, x.col),
};
let path = &db
diff --git a/crates/rust-analyzer/src/cli/scip.rs b/crates/rust-analyzer/src/cli/scip.rs
index 1b0cfa6a5d..f4aec28834 100644
--- a/crates/rust-analyzer/src/cli/scip.rs
+++ b/crates/rust-analyzer/src/cli/scip.rs
@@ -146,7 +146,7 @@ impl flags::Scip {
let signature_documentation =
token.signature.clone().map(|text| scip_types::Document {
relative_path: relative_path.clone(),
- language: "rust".to_string(),
+ language: "rust".to_owned(),
text,
position_encoding,
..Default::default()
@@ -186,7 +186,7 @@ impl flags::Scip {
scip_types::PositionEncoding::UTF8CodeUnitOffsetFromLineStart.into();
documents.push(scip_types::Document {
relative_path,
- language: "rust".to_string(),
+ language: "rust".to_owned(),
occurrences,
symbols,
text: String::new(),
@@ -216,7 +216,7 @@ fn get_relative_filepath(
rootpath: &vfs::AbsPathBuf,
file_id: ide::FileId,
) -> Option<String> {
- Some(vfs.file_path(file_id).as_path()?.strip_prefix(rootpath)?.as_ref().to_str()?.to_string())
+ Some(vfs.file_path(file_id).as_path()?.strip_prefix(rootpath)?.as_ref().to_str()?.to_owned())
}
// SCIP Ranges have a (very large) optimization that ranges if they are on the same line
@@ -239,8 +239,8 @@ fn new_descriptor_str(
suffix: scip_types::descriptor::Suffix,
) -> scip_types::Descriptor {
scip_types::Descriptor {
- name: name.to_string(),
- disambiguator: "".to_string(),
+ name: name.to_owned(),
+ disambiguator: "".to_owned(),
suffix: suffix.into(),
special_fields: Default::default(),
}
@@ -311,9 +311,9 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
scip_types::Symbol {
scheme: "rust-analyzer".into(),
package: Some(scip_types::Package {
- manager: "cargo".to_string(),
+ manager: "cargo".to_owned(),
name: package_name,
- version: version.unwrap_or_else(|| ".".to_string()),
+ version: version.unwrap_or_else(|| ".".to_owned()),
special_fields: Default::default(),
})
.into(),
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3ba30cc38e..7bdd9ec866 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -904,7 +904,7 @@ impl Config {
use serde::de::Error;
if self.data.check_command.is_empty() {
error_sink.push((
- "/check/command".to_string(),
+ "/check/command".to_owned(),
serde_json::Error::custom("expected a non-empty string"),
));
}
@@ -2626,7 +2626,7 @@ mod tests {
.replace('\n', "\n ")
.trim_start_matches('\n')
.trim_end()
- .to_string();
+ .to_owned();
schema.push_str(",\n");
// Transform the asciidoc form link to markdown style.
diff --git a/crates/rust-analyzer/src/config/patch_old_style.rs b/crates/rust-analyzer/src/config/patch_old_style.rs
index 73d2ed3298..92c0c0d048 100644
--- a/crates/rust-analyzer/src/config/patch_old_style.rs
+++ b/crates/rust-analyzer/src/config/patch_old_style.rs
@@ -19,7 +19,7 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
Some(it) => {
let mut last = it;
for segment in [$(stringify!($dst)),+].into_iter().rev() {
- last = Value::Object(serde_json::Map::from_iter(std::iter::once((segment.to_string(), last))));
+ last = Value::Object(serde_json::Map::from_iter(std::iter::once((segment.to_owned(), last))));
}
merge(json, last);
diff --git a/crates/rust-analyzer/src/diagnostics.rs b/crates/rust-analyzer/src/diagnostics.rs
index c91b22999d..a0a53f545c 100644
--- a/crates/rust-analyzer/src/diagnostics.rs
+++ b/crates/rust-analyzer/src/diagnostics.rs
@@ -135,11 +135,11 @@ pub(crate) fn fetch_native_diagnostics(
|line_index: &crate::line_index::LineIndex, d: ide::Diagnostic| lsp_types::Diagnostic {
range: lsp::to_proto::range(line_index, d.range.range),
severity: Some(lsp::to_proto::diagnostic_severity(d.severity)),
- code: Some(lsp_types::NumberOrString::String(d.code.as_str().to_string())),
+ code: Some(lsp_types::NumberOrString::String(d.code.as_str().to_owned())),
code_description: Some(lsp_types::CodeDescription {
href: lsp_types::Url::parse(&d.code.url()).unwrap(),
}),
- source: Some("rust-analyzer".to_string()),
+ source: Some("rust-analyzer".to_owned()),
message: d.message,
related_information: None,
tags: d.unused.then(|| vec![lsp_types::DiagnosticTag::UNNECESSARY]),
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index f79ae793c9..e900f2601d 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -403,16 +403,16 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
related_info_macro_calls.push(lsp_types::DiagnosticRelatedInformation {
location: secondary_location.clone(),
message: if is_in_macro_call {
- "Error originated from macro call here".to_string()
+ "Error originated from macro call here".to_owned()
} else {
- "Actual error occurred here".to_string()
+ "Actual error occurred here".to_owned()
},
});
// For the additional in-macro diagnostic we add the inverse message pointing to the error location in code.
let information_for_additional_diagnostic =
vec![lsp_types::DiagnosticRelatedInformation {
location: primary_location.clone(),
- message: "Exact error occurred here".to_string(),
+ message: "Exact error occurred here".to_owned(),
}];
let diagnostic = lsp_types::Diagnostic {
@@ -467,7 +467,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
// `related_information`, which just produces hard-to-read links, at least in VS Code.
let back_ref = lsp_types::DiagnosticRelatedInformation {
location: primary_location,
- message: "original diagnostic".to_string(),
+ message: "original diagnostic".to_owned(),
};
for sub in &subdiagnostics {
diagnostics.push(MappedRustDiagnostic {
@@ -685,7 +685,7 @@ mod tests {
fn rustc_unused_variable_as_info() {
check_with_config(
DiagnosticsMapConfig {
- warnings_as_info: vec!["unused_variables".to_string()],
+ warnings_as_info: vec!["unused_variables".to_owned()],
..DiagnosticsMapConfig::default()
},
r##"{
@@ -769,7 +769,7 @@ mod tests {
fn rustc_unused_variable_as_hint() {
check_with_config(
DiagnosticsMapConfig {
- warnings_as_hint: vec!["unused_variables".to_string()],
+ warnings_as_hint: vec!["unused_variables".to_owned()],
..DiagnosticsMapConfig::default()
},
r##"{
diff --git a/crates/rust-analyzer/src/dispatch.rs b/crates/rust-analyzer/src/dispatch.rs
index fa856a796a..7adaef4ff6 100644
--- a/crates/rust-analyzer/src/dispatch.rs
+++ b/crates/rust-analyzer/src/dispatch.rs
@@ -123,7 +123,7 @@ impl RequestDispatcher<'_> {
Err(_) => Task::Response(lsp_server::Response::new_err(
req.id,
lsp_server::ErrorCode::ContentModified as i32,
- "content modified".to_string(),
+ "content modified".to_owned(),
)),
}
}
@@ -179,7 +179,7 @@ impl RequestDispatcher<'_> {
let response = lsp_server::Response::new_err(
req.id,
lsp_server::ErrorCode::MethodNotFound as i32,
- "unknown request".to_string(),
+ "unknown request".to_owned(),
);
self.global_state.respond(response);
}
@@ -269,7 +269,7 @@ where
.map(String::as_str)
.or_else(|| panic.downcast_ref::<&str>().copied());
- let mut message = "request handler panicked".to_string();
+ let mut message = "request handler panicked".to_owned();
if let Some(panic_message) = panic_message {
message.push_str(": ");
message.push_str(panic_message)
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs
index 4b3bca8e4a..da4422a60a 100644
--- a/crates/rust-analyzer/src/global_state.rs
+++ b/crates/rust-analyzer/src/global_state.rs
@@ -388,7 +388,7 @@ impl GlobalState {
params: R::Params,
handler: ReqHandler,
) {
- let request = self.req_queue.outgoing.register(R::METHOD.to_string(), params, handler);
+ let request = self.req_queue.outgoing.register(R::METHOD.to_owned(), params, handler);
self.send(request.into());
}
@@ -405,7 +405,7 @@ impl GlobalState {
&self,
params: N::Params,
) {
- let not = lsp_server::Notification::new(N::METHOD.to_string(), params);
+ let not = lsp_server::Notification::new(N::METHOD.to_owned(), params);
self.send(not.into());
}
diff --git a/crates/rust-analyzer/src/handlers/notification.rs b/crates/rust-analyzer/src/handlers/notification.rs
index 365d5fb2e0..d3c2073f09 100644
--- a/crates/rust-analyzer/src/handlers/notification.rs
+++ b/crates/rust-analyzer/src/handlers/notification.rs
@@ -184,7 +184,7 @@ pub(crate) fn handle_did_change_configuration(
lsp_types::ConfigurationParams {
items: vec![lsp_types::ConfigurationItem {
scope_uri: None,
- section: Some("rust-analyzer".to_string()),
+ section: Some("rust-analyzer".to_owned()),
}],
},
|this, resp| {
@@ -236,7 +236,7 @@ pub(crate) fn handle_did_change_workspace_folders(
if !config.has_linked_projects() && config.detached_files().is_empty() {
config.rediscover_workspaces();
- state.fetch_workspaces_queue.request_op("client workspaces changed".to_string(), false)
+ state.fetch_workspaces_queue.request_op("client workspaces changed".to_owned(), false)
}
Ok(())
diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs
index 2be2ba5c44..2a3633a48e 100644
--- a/crates/rust-analyzer/src/handlers/request.rs
+++ b/crates/rust-analyzer/src/handlers/request.rs
@@ -54,7 +54,7 @@ pub(crate) fn handle_workspace_reload(state: &mut GlobalState, _: ()) -> anyhow:
state.proc_macro_clients = Arc::from_iter([]);
state.proc_macro_changed = false;
- state.fetch_workspaces_queue.request_op("reload workspace request".to_string(), false);
+ state.fetch_workspaces_queue.request_op("reload workspace request".to_owned(), false);
Ok(())
}
@@ -62,7 +62,7 @@ pub(crate) fn handle_proc_macros_rebuild(state: &mut GlobalState, _: ()) -> anyh
state.proc_macro_clients = Arc::from_iter([]);
state.proc_macro_changed = false;
- state.fetch_build_data_queue.request_op("rebuild proc macros request".to_string(), ());
+ state.fetch_build_data_queue.request_op("rebuild proc macros request".to_owned(), ());
Ok(())
}
@@ -562,7 +562,7 @@ pub(crate) fn handle_will_rename_files(
(Some(p1), Some(p2)) if p1 == p2 => {
if from_path.is_dir() {
// add '/' to end of url -- from `file://path/to/folder` to `file://path/to/folder/`
- let mut old_folder_name = from_path.file_stem()?.to_str()?.to_string();
+ let mut old_folder_name = from_path.file_stem()?.to_str()?.to_owned();
old_folder_name.push('/');
let from_with_trailing_slash = from.join(&old_folder_name).ok()?;
@@ -570,7 +570,7 @@ pub(crate) fn handle_will_rename_files(
let new_file_name = to_path.file_name()?.to_str()?;
Some((
snap.url_to_file_id(&imitate_from_url).ok()?,
- new_file_name.to_string(),
+ new_file_name.to_owned(),
))
} else {
let old_name = from_path.file_stem()?.to_str()?;
@@ -578,7 +578,7 @@ pub(crate) fn handle_will_rename_files(
match (old_name, new_name) {
("mod", _) => None,
(_, "mod") => None,
- _ => Some((snap.url_to_file_id(&from).ok()?, new_name.to_string())),
+ _ => Some((snap.url_to_file_id(&from).ok()?, new_name.to_owned())),
}
}
}
@@ -799,13 +799,13 @@ pub(crate) fn handle_runnables(
None => {
if !snap.config.linked_or_discovered_projects().is_empty() {
res.push(lsp_ext::Runnable {
- label: "cargo check --workspace".to_string(),
+ label: "cargo check --workspace".to_owned(),
location: None,
kind: lsp_ext::RunnableKind::Cargo,
args: lsp_ext::CargoRunnable {
workspace_root: None,
override_cargo: config.override_cargo,
- cargo_args: vec!["check".to_string(), "--workspace".to_string()],
+ cargo_args: vec!["check".to_owned(), "--workspace".to_owned()],
cargo_extra_args: config.cargo_extra_args,
executable_args: Vec::new(),
expect_test: None,
@@ -879,7 +879,7 @@ pub(crate) fn handle_completion_resolve(
if !all_edits_are_disjoint(&original_completion, &[]) {
return Err(invalid_params_error(
- "Received a completion with overlapping edits, this is not LSP-compliant".to_string(),
+ "Received a completion with overlapping edits, this is not LSP-compliant".to_owned(),
)
.into());
}
@@ -1191,7 +1191,7 @@ pub(crate) fn handle_code_action_resolve(
let _p = tracing::span!(tracing::Level::INFO, "handle_code_action_resolve").entered();
let params = match code_action.data.take() {
Some(it) => it,
- None => return Err(invalid_params_error("code action without data".to_string()).into()),
+ None => return Err(invalid_params_error("code action without data".to_owned()).into()),
};
let file_id = from_proto::file_id(&snap, &params.code_action_params.text_document.uri)?;
@@ -1270,7 +1270,7 @@ fn parse_action_id(action_id: &str) -> anyhow::Result<(usize, SingleResolve), St
};
Ok((index, SingleResolve { assist_id: assist_id_string.to_string(), assist_kind }))
}
- _ => Err("Action id contains incorrect number of segments".to_string()),
+ _ => Err("Action id contains incorrect number of segments".to_owned()),
}
}
diff --git a/crates/rust-analyzer/src/lsp/from_proto.rs b/crates/rust-analyzer/src/lsp/from_proto.rs
index 9923be382b..f42985a916 100644
--- a/crates/rust-analyzer/src/lsp/from_proto.rs
+++ b/crates/rust-analyzer/src/lsp/from_proto.rs
@@ -108,7 +108,7 @@ pub(crate) fn annotation(
code_lens: lsp_types::CodeLens,
) -> anyhow::Result<Option<Annotation>> {
let data =
- code_lens.data.ok_or_else(|| invalid_params_error("code lens without data".to_string()))?;
+ code_lens.data.ok_or_else(|| invalid_params_error("code lens without data".to_owned()))?;
let resolve = from_json::<lsp_ext::CodeLensResolveData>("CodeLensResolveData", &data)?;
match resolve.kind {
diff --git a/crates/rust-analyzer/src/lsp/to_proto.rs b/crates/rust-analyzer/src/lsp/to_proto.rs
index d363ac69fd..64f19f0b32 100644
--- a/crates/rust-analyzer/src/lsp/to_proto.rs
+++ b/crates/rust-analyzer/src/lsp/to_proto.rs
@@ -245,7 +245,7 @@ fn completion_item(
) {
let insert_replace_support = config.insert_replace_support().then_some(tdpp.position);
let ref_match = item.ref_match();
- let lookup = item.lookup().to_string();
+ let lookup = item.lookup().to_owned();
let mut additional_text_edits = Vec::new();
@@ -367,7 +367,7 @@ pub(crate) fn signature_help(
let params = call_info
.parameter_labels()
.map(|label| lsp_types::ParameterInformation {
- label: lsp_types::ParameterLabel::Simple(label.to_string()),
+ label: lsp_types::ParameterLabel::Simple(label.to_owned()),
documentation: None,
})
.collect::<Vec<_>>();
@@ -1498,7 +1498,7 @@ pub(crate) mod command {
pub(crate) fn run_single(runnable: &lsp_ext::Runnable, title: &str) -> lsp_types::Command {
lsp_types::Command {
- title: title.to_string(),
+ title: title.to_owned(),
command: "rust-analyzer.runSingle".into(),
arguments: Some(vec![to_value(runnable).unwrap()]),
}
@@ -1608,7 +1608,7 @@ fn main() {
}
}"#;
- let (analysis, file_id) = Analysis::from_single_file(text.to_string());
+ let (analysis, file_id) = Analysis::from_single_file(text.to_owned());
let folds = analysis.folding_ranges(file_id).unwrap();
assert_eq!(folds.len(), 4);
diff --git a/crates/rust-analyzer/src/lsp/utils.rs b/crates/rust-analyzer/src/lsp/utils.rs
index fa5ea5b57d..10335cb145 100644
--- a/crates/rust-analyzer/src/lsp/utils.rs
+++ b/crates/rust-analyzer/src/lsp/utils.rs
@@ -333,21 +333,20 @@ mod tests {
#[test]
fn empty_completion_disjoint_tests() {
- let empty_completion =
- CompletionItem::new_simple("label".to_string(), "detail".to_string());
+ let empty_completion = CompletionItem::new_simple("label".to_owned(), "detail".to_owned());
let disjoint_edit_1 = lsp_types::TextEdit::new(
Range::new(Position::new(2, 2), Position::new(3, 3)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let disjoint_edit_2 = lsp_types::TextEdit::new(
Range::new(Position::new(3, 3), Position::new(4, 4)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let joint_edit = lsp_types::TextEdit::new(
Range::new(Position::new(1, 1), Position::new(5, 5)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
assert!(
@@ -375,19 +374,19 @@ mod tests {
fn completion_with_joint_edits_disjoint_tests() {
let disjoint_edit = lsp_types::TextEdit::new(
Range::new(Position::new(1, 1), Position::new(2, 2)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let disjoint_edit_2 = lsp_types::TextEdit::new(
Range::new(Position::new(2, 2), Position::new(3, 3)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let joint_edit = lsp_types::TextEdit::new(
Range::new(Position::new(1, 1), Position::new(5, 5)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let mut completion_with_joint_edits =
- CompletionItem::new_simple("label".to_string(), "detail".to_string());
+ CompletionItem::new_simple("label".to_owned(), "detail".to_owned());
completion_with_joint_edits.additional_text_edits =
Some(vec![disjoint_edit.clone(), joint_edit.clone()]);
assert!(
@@ -405,7 +404,7 @@ mod tests {
completion_with_joint_edits.text_edit =
Some(CompletionTextEdit::InsertAndReplace(InsertReplaceEdit {
- new_text: "new_text".to_string(),
+ new_text: "new_text".to_owned(),
insert: disjoint_edit.range,
replace: disjoint_edit_2.range,
}));
@@ -420,19 +419,19 @@ mod tests {
fn completion_with_disjoint_edits_disjoint_tests() {
let disjoint_edit = lsp_types::TextEdit::new(
Range::new(Position::new(1, 1), Position::new(2, 2)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let disjoint_edit_2 = lsp_types::TextEdit::new(
Range::new(Position::new(2, 2), Position::new(3, 3)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let joint_edit = lsp_types::TextEdit::new(
Range::new(Position::new(1, 1), Position::new(5, 5)),
- "new_text".to_string(),
+ "new_text".to_owned(),
);
let mut completion_with_disjoint_edits =
- CompletionItem::new_simple("label".to_string(), "detail".to_string());
+ CompletionItem::new_simple("label".to_owned(), "detail".to_owned());
completion_with_disjoint_edits.text_edit = Some(CompletionTextEdit::Edit(disjoint_edit));
let completion_with_disjoint_edits = completion_with_disjoint_edits;
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 2a431a88bc..88660db7e9 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -139,7 +139,7 @@ impl GlobalState {
self.register_did_save_capability();
}
- self.fetch_workspaces_queue.request_op("startup".to_string(), false);
+ self.fetch_workspaces_queue.request_op("startup".to_owned(), false);
if let Some((cause, force_crate_graph_reload)) =
self.fetch_workspaces_queue.should_start_op()
{
@@ -185,8 +185,8 @@ impl GlobalState {
};
let registration = lsp_types::Registration {
- id: "textDocument/didSave".to_string(),
- method: "textDocument/didSave".to_string(),
+ id: "textDocument/didSave".to_owned(),
+ method: "textDocument/didSave".to_owned(),
register_options: Some(serde_json::to_value(save_registration_options).unwrap()),
};
self.send_request::<lsp_types::request::RegisterCapability>(
@@ -296,7 +296,7 @@ impl GlobalState {
self.prime_caches_queue.op_completed(());
if cancelled {
self.prime_caches_queue
- .request_op("restart after cancellation".to_string(), ());
+ .request_op("restart after cancellation".to_owned(), ());
}
}
};
@@ -340,7 +340,7 @@ impl GlobalState {
self.flycheck.iter().for_each(FlycheckHandle::restart_workspace);
}
if self.config.prefill_caches() {
- self.prime_caches_queue.request_op("became quiescent".to_string(), ());
+ self.prime_caches_queue.request_op("became quiescent".to_owned(), ());
}
}
@@ -390,7 +390,7 @@ impl GlobalState {
// See https://github.com/rust-lang/rust-analyzer/issues/13130
let patch_empty = |message: &mut String| {
if message.is_empty() {
- *message = " ".to_string();
+ *message = " ".to_owned();
}
};
@@ -557,12 +557,12 @@ impl GlobalState {
}
let old = Arc::clone(&self.workspaces);
- self.switch_workspaces("fetched workspace".to_string());
+ self.switch_workspaces("fetched workspace".to_owned());
let workspaces_updated = !Arc::ptr_eq(&old, &self.workspaces);
if self.config.run_build_scripts() && workspaces_updated {
self.fetch_build_data_queue
- .request_op("workspace updated".to_string(), ());
+ .request_op("workspace updated".to_owned(), ());
}
(Progress::End, None)
@@ -581,7 +581,7 @@ impl GlobalState {
tracing::error!("FetchBuildDataError:\n{e}");
}
- self.switch_workspaces("fetched build data".to_string());
+ self.switch_workspaces("fetched build data".to_owned());
self.send_hint_refresh_query = true;
(Some(Progress::End), None)
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index dcf6089ca7..7bd2877b00 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -83,7 +83,7 @@ impl GlobalState {
}
if self.config.linked_or_discovered_projects() != old_config.linked_or_discovered_projects()
{
- self.fetch_workspaces_queue.request_op("linked projects changed".to_string(), false)
+ self.fetch_workspaces_queue.request_op("linked projects changed".to_owned(), false)
} else if self.config.flycheck() != old_config.flycheck() {
self.reload_flycheck();
}
@@ -440,8 +440,8 @@ impl GlobalState {
.collect(),
};
let registration = lsp_types::Registration {
- id: "workspace/didChangeWatchedFiles".to_string(),
- method: "workspace/didChangeWatchedFiles".to_string(),
+ id: "workspace/didChangeWatchedFiles".to_owned(),
+ method: "workspace/didChangeWatchedFiles".to_owned(),
register_options: Some(serde_json::to_value(registration_options).unwrap()),
};
self.send_request::<lsp_types::request::RegisterCapability>(
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs
index 1ee1c1489a..79ae0c30cf 100644
--- a/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -632,9 +632,9 @@ fn main() {{}}
server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
text_document: TextDocumentItem {
uri: uri.clone(),
- language_id: "rust".to_string(),
+ language_id: "rust".to_owned(),
version: 0,
- text: "/// Docs\nfn foo() {}".to_string(),
+ text: "/// Docs\nfn foo() {}".to_owned(),
},
});
let expected = json!({
@@ -682,9 +682,9 @@ fn main() {{}}
server.notification::<DidOpenTextDocument>(DidOpenTextDocumentParams {
text_document: TextDocumentItem {
uri: server.doc_id(&format!("src/m{i}.rs")).uri,
- language_id: "rust".to_string(),
+ language_id: "rust".to_owned(),
version: 0,
- text: "/// Docs\nfn foo() {}".to_string(),
+ text: "/// Docs\nfn foo() {}".to_owned(),
},
});
}
@@ -1078,15 +1078,15 @@ use crate::old_folder::nested::foo as bar;
server.request::<WillRenameFiles>(
RenameFilesParams {
files: vec![FileRename {
- old_uri: base_path.join("src/old_file.rs").to_str().unwrap().to_string(),
- new_uri: base_path.join("src/new_file.rs").to_str().unwrap().to_string(),
+ old_uri: base_path.join("src/old_file.rs").to_str().unwrap().to_owned(),
+ new_uri: base_path.join("src/new_file.rs").to_str().unwrap().to_owned(),
}],
},
json!({
"documentChanges": [
{
"textDocument": {
- "uri": format!("file://{}", tmp_dir_path.join("src").join("lib.rs").to_str().unwrap().to_string().replace("C:\\", "/c:/").replace('\\', "/")),
+ "uri": format!("file://{}", tmp_dir_path.join("src").join("lib.rs").to_str().unwrap().to_owned().replace("C:\\", "/c:/").replace('\\', "/")),
"version": null
},
"edits": [
@@ -1113,8 +1113,8 @@ use crate::old_folder::nested::foo as bar;
server.request::<WillRenameFiles>(
RenameFilesParams {
files: vec![FileRename {
- old_uri: base_path.join("src/from_mod/mod.rs").to_str().unwrap().to_string(),
- new_uri: base_path.join("src/from_mod/foo.rs").to_str().unwrap().to_string(),
+ old_uri: base_path.join("src/from_mod/mod.rs").to_str().unwrap().to_owned(),
+ new_uri: base_path.join("src/from_mod/foo.rs").to_str().unwrap().to_owned(),
}],
},
json!(null),
@@ -1124,8 +1124,8 @@ use crate::old_folder::nested::foo as bar;
server.request::<WillRenameFiles>(
RenameFilesParams {
files: vec![FileRename {
- old_uri: base_path.join("src/to_mod/foo.rs").to_str().unwrap().to_string(),
- new_uri: base_path.join("src/to_mod/mod.rs").to_str().unwrap().to_string(),
+ old_uri: base_path.join("src/to_mod/foo.rs").to_str().unwrap().to_owned(),
+ new_uri: base_path.join("src/to_mod/mod.rs").to_str().unwrap().to_owned(),
}],
},
json!(null),
@@ -1135,15 +1135,15 @@ use crate::old_folder::nested::foo as bar;
server.request::<WillRenameFiles>(
RenameFilesParams {
files: vec![FileRename {
- old_uri: base_path.join("src/old_folder").to_str().unwrap().to_string(),
- new_uri: base_path.join("src/new_folder").to_str().unwrap().to_string(),
+ old_uri: base_path.join("src/old_folder").to_str().unwrap().to_owned(),
+ new_uri: base_path.join("src/new_folder").to_str().unwrap().to_owned(),
}],
},
json!({
"documentChanges": [
{
"textDocument": {
- "uri": format!("file://{}", tmp_dir_path.join("src").join("lib.rs").to_str().unwrap().to_string().replace("C:\\", "/c:/").replace('\\', "/")),
+ "uri": format!("file://{}", tmp_dir_path.join("src").join("lib.rs").to_str().unwrap().to_owned().replace("C:\\", "/c:/").replace('\\', "/")),
"version": null
},
"edits": [
@@ -1164,7 +1164,7 @@ use crate::old_folder::nested::foo as bar;
},
{
"textDocument": {
- "uri": format!("file://{}", tmp_dir_path.join("src").join("old_folder").join("nested.rs").to_str().unwrap().to_string().replace("C:\\", "/c:/").replace('\\', "/")),
+ "uri": format!("file://{}", tmp_dir_path.join("src").join("old_folder").join("nested.rs").to_str().unwrap().to_owned().replace("C:\\", "/c:/").replace('\\', "/")),
"version": null
},
"edits": [
diff --git a/crates/rust-analyzer/tests/slow-tests/support.rs b/crates/rust-analyzer/tests/slow-tests/support.rs
index c2bdefa217..d02cb45b8e 100644
--- a/crates/rust-analyzer/tests/slow-tests/support.rs
+++ b/crates/rust-analyzer/tests/slow-tests/support.rs
@@ -95,7 +95,7 @@ impl Project<'_> {
writer: TestWriter::default(),
// Deliberately enable all `error` logs if the user has not set RA_LOG, as there is usually
// useful information in there for debugging.
- filter: std::env::var("RA_LOG").ok().unwrap_or_else(|| "error".to_string()),
+ filter: std::env::var("RA_LOG").ok().unwrap_or_else(|| "error".to_owned()),
chalk_filter: std::env::var("CHALK_DEBUG").ok(),
profile_filter: std::env::var("RA_PROFILE").ok(),
};
@@ -193,7 +193,7 @@ impl Server {
let (connection, client) = Connection::memory();
let _thread = stdx::thread::Builder::new(stdx::thread::ThreadIntent::Worker)
- .name("test server".to_string())
+ .name("test server".to_owned())
.spawn(move || main_loop(config, connection).unwrap())
.expect("failed to spawn a thread");
@@ -210,7 +210,7 @@ impl Server {
N: lsp_types::notification::Notification,
N::Params: Serialize,
{
- let r = Notification::new(N::METHOD.to_string(), params);
+ let r = Notification::new(N::METHOD.to_owned(), params);
self.send_notification(r)
}
@@ -274,7 +274,7 @@ impl Server {
let id = self.req_id.get();
self.req_id.set(id.wrapping_add(1));
- let r = Request::new(id.into(), R::METHOD.to_string(), params);
+ let r = Request::new(id.into(), R::METHOD.to_owned(), params);
self.send_request_(r)
}
fn send_request_(&self, r: Request) -> Value {
diff --git a/crates/rust-analyzer/tests/slow-tests/tidy.rs b/crates/rust-analyzer/tests/slow-tests/tidy.rs
index 740626dfe3..3e38fc3ebc 100644
--- a/crates/rust-analyzer/tests/slow-tests/tidy.rs
+++ b/crates/rust-analyzer/tests/slow-tests/tidy.rs
@@ -373,7 +373,7 @@ fn find_marks(set: &mut HashSet<String>, text: &str, mark: &str) {
text = stripped_text.trim_start();
if let Some(idx2) = text.find(|c: char| !(c.is_alphanumeric() || c == '_')) {
let mark_text = &text[..idx2];
- set.insert(mark_text.to_string());
+ set.insert(mark_text.to_owned());
text = &text[idx2..];
}
}