Skip to content

Commit 395708d

Browse files
rust-analyzer: Fix warnings about clippy str_to_string rule
1 parent 80e6842 commit 395708d

24 files changed

+107
-108
lines changed

crates/rust-analyzer/src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn setup_logging(log_file_flag: Option<PathBuf>) -> anyhow::Result<()> {
134134
writer,
135135
// Deliberately enable all `error` logs if the user has not set RA_LOG, as there is usually
136136
// useful information in there for debugging.
137-
filter: env::var("RA_LOG").ok().unwrap_or_else(|| "error".to_string()),
137+
filter: env::var("RA_LOG").ok().unwrap_or_else(|| "error".to_owned()),
138138
chalk_filter: env::var("CHALK_DEBUG").ok(),
139139
profile_filter: env::var("RA_PROFILE").ok(),
140140
}
@@ -224,7 +224,7 @@ fn run_server() -> anyhow::Result<()> {
224224
MessageType, ShowMessageParams,
225225
};
226226
let not = lsp_server::Notification::new(
227-
ShowMessage::METHOD.to_string(),
227+
ShowMessage::METHOD.to_owned(),
228228
ShowMessageParams { typ: MessageType::WARNING, message: e.to_string() },
229229
);
230230
connection.sender.send(lsp_server::Message::Notification(not)).unwrap();

crates/rust-analyzer/src/caps.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
4444
completion_provider: Some(CompletionOptions {
4545
resolve_provider: completions_resolve_provider(config.caps()),
4646
trigger_characters: Some(vec![
47-
":".to_string(),
48-
".".to_string(),
49-
"'".to_string(),
50-
"(".to_string(),
47+
":".to_owned(),
48+
".".to_owned(),
49+
"'".to_owned(),
50+
"(".to_owned(),
5151
]),
5252
all_commit_characters: None,
5353
completion_item: completion_item(config),
5454
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
5555
}),
5656
signature_help_provider: Some(SignatureHelpOptions {
57-
trigger_characters: Some(vec!["(".to_string(), ",".to_string(), "<".to_string()]),
57+
trigger_characters: Some(vec!["(".to_owned(), ",".to_owned(), "<".to_owned()]),
5858
retrigger_characters: None,
5959
work_done_progress_options: WorkDoneProgressOptions { work_done_progress: None },
6060
}),
@@ -74,7 +74,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
7474
_ => Some(OneOf::Left(false)),
7575
},
7676
document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions {
77-
first_trigger_character: "=".to_string(),
77+
first_trigger_character: "=".to_owned(),
7878
more_trigger_character: Some(more_trigger_character(config)),
7979
}),
8080
selection_range_provider: Some(SelectionRangeProviderCapability::Simple(true)),
@@ -222,9 +222,9 @@ fn code_action_capabilities(client_caps: &ClientCapabilities) -> CodeActionProvi
222222
}
223223

224224
fn more_trigger_character(config: &Config) -> Vec<String> {
225-
let mut res = vec![".".to_string(), ">".to_string(), "{".to_string(), "(".to_string()];
225+
let mut res = vec![".".to_owned(), ">".to_owned(), "{".to_owned(), "(".to_owned()];
226226
if config.snippet_cap() {
227-
res.push("<".to_string());
227+
res.push("<".to_owned());
228228
}
229229
res
230230
}

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl flags::AnalysisStats {
397397
module
398398
.krate()
399399
.display_name(db)
400-
.map(|it| it.canonical_name().to_string())
400+
.map(|it| it.canonical_name().to_owned())
401401
.into_iter()
402402
.chain(
403403
module
@@ -688,7 +688,7 @@ impl flags::AnalysisStats {
688688
module
689689
.krate()
690690
.display_name(db)
691-
.map(|it| it.canonical_name().to_string())
691+
.map(|it| it.canonical_name().to_owned())
692692
.into_iter()
693693
.chain(
694694
module
@@ -833,7 +833,7 @@ impl flags::AnalysisStats {
833833
fn location_csv_expr(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, expr_id: ExprId) -> String {
834834
let src = match sm.expr_syntax(expr_id) {
835835
Ok(s) => s,
836-
Err(SyntheticSyntax) => return "synthetic,,".to_string(),
836+
Err(SyntheticSyntax) => return "synthetic,,".to_owned(),
837837
};
838838
let root = db.parse_or_expand(src.file_id);
839839
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:
849849
fn location_csv_pat(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, pat_id: PatId) -> String {
850850
let src = match sm.pat_syntax(pat_id) {
851851
Ok(s) => s,
852-
Err(SyntheticSyntax) => return "synthetic,,".to_string(),
852+
Err(SyntheticSyntax) => return "synthetic,,".to_owned(),
853853
};
854854
let root = db.parse_or_expand(src.file_id);
855855
let node = src.map(|e| e.to_node(&root).syntax().clone());

crates/rust-analyzer/src/cli/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl flags::Diagnostics {
4545
let file_id = module.definition_source_file_id(db).original_file(db);
4646
if !visited_files.contains(&file_id) {
4747
let crate_name =
48-
module.krate().display_name(db).as_deref().unwrap_or("unknown").to_string();
48+
module.krate().display_name(db).as_deref().unwrap_or("unknown").to_owned();
4949
println!("processing crate: {crate_name}, module: {}", _vfs.file_path(file_id));
5050
for diagnostic in analysis
5151
.diagnostics(

crates/rust-analyzer/src/cli/lsif.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ impl LsifManager<'_> {
104104
let result_set_id =
105105
self.add_vertex(lsif::Vertex::PackageInformation(lsif::PackageInformation {
106106
name: pi.name,
107-
manager: "cargo".to_string(),
107+
manager: "cargo".to_owned(),
108108
uri: None,
109109
content: None,
110110
repository: pi.repo.map(|url| lsif::Repository {
111111
url,
112-
r#type: "git".to_string(),
112+
r#type: "git".to_owned(),
113113
commit_id: None,
114114
}),
115115
version: pi.version,
@@ -148,7 +148,7 @@ impl LsifManager<'_> {
148148
let path = self.vfs.file_path(id);
149149
let path = path.as_path().unwrap();
150150
let doc_id = self.add_vertex(lsif::Vertex::Document(lsif::Document {
151-
language_id: "rust".to_string(),
151+
language_id: "rust".to_owned(),
152152
uri: lsp_types::Url::from_file_path(path).unwrap(),
153153
}));
154154
self.file_map.insert(id, doc_id);
@@ -175,7 +175,7 @@ impl LsifManager<'_> {
175175
if let Some(moniker) = token.moniker {
176176
let package_id = self.get_package_id(moniker.package_information);
177177
let moniker_id = self.add_vertex(lsif::Vertex::Moniker(lsp_types::Moniker {
178-
scheme: "rust-analyzer".to_string(),
178+
scheme: "rust-analyzer".to_owned(),
179179
identifier: moniker.identifier.to_string(),
180180
unique: lsp_types::UniquenessLevel::Scheme,
181181
kind: Some(match moniker.kind {
@@ -313,7 +313,7 @@ impl flags::Lsif {
313313
project_root: lsp_types::Url::from_file_path(path).unwrap(),
314314
position_encoding: lsif::Encoding::Utf16,
315315
tool_info: Some(lsp_types::lsif::ToolInfo {
316-
name: "rust-analyzer".to_string(),
316+
name: "rust-analyzer".to_owned(),
317317
args: vec![],
318318
version: Some(version().to_string()),
319319
}),

crates/rust-analyzer/src/cli/progress_report.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a> ProgressReport<'a> {
9292

9393
let _ = io::stdout().write(output.as_bytes());
9494
let _ = io::stdout().flush();
95-
self.text = text.to_string();
95+
self.text = text.to_owned();
9696
}
9797

9898
fn set_value(&mut self, value: f32) {

crates/rust-analyzer/src/cli/run_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl flags::RunTests {
3434
.filter(|x| x.is_test(db));
3535
let span_formatter = |file_id, text_range: TextRange| {
3636
let line_col = match db.line_index(file_id).try_line_col(text_range.start()) {
37-
None => " (unknown line col)".to_string(),
37+
None => " (unknown line col)".to_owned(),
3838
Some(x) => format!("#{}:{}", x.line + 1, x.col),
3939
};
4040
let path = &db

crates/rust-analyzer/src/cli/scip.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl flags::Scip {
146146
let signature_documentation =
147147
token.signature.clone().map(|text| scip_types::Document {
148148
relative_path: relative_path.clone(),
149-
language: "rust".to_string(),
149+
language: "rust".to_owned(),
150150
text,
151151
position_encoding,
152152
..Default::default()
@@ -186,7 +186,7 @@ impl flags::Scip {
186186
scip_types::PositionEncoding::UTF8CodeUnitOffsetFromLineStart.into();
187187
documents.push(scip_types::Document {
188188
relative_path,
189-
language: "rust".to_string(),
189+
language: "rust".to_owned(),
190190
occurrences,
191191
symbols,
192192
text: String::new(),
@@ -216,7 +216,7 @@ fn get_relative_filepath(
216216
rootpath: &vfs::AbsPathBuf,
217217
file_id: ide::FileId,
218218
) -> Option<String> {
219-
Some(vfs.file_path(file_id).as_path()?.strip_prefix(rootpath)?.as_ref().to_str()?.to_string())
219+
Some(vfs.file_path(file_id).as_path()?.strip_prefix(rootpath)?.as_ref().to_str()?.to_owned())
220220
}
221221

222222
// SCIP Ranges have a (very large) optimization that ranges if they are on the same line
@@ -239,8 +239,8 @@ fn new_descriptor_str(
239239
suffix: scip_types::descriptor::Suffix,
240240
) -> scip_types::Descriptor {
241241
scip_types::Descriptor {
242-
name: name.to_string(),
243-
disambiguator: "".to_string(),
242+
name: name.to_owned(),
243+
disambiguator: "".to_owned(),
244244
suffix: suffix.into(),
245245
special_fields: Default::default(),
246246
}
@@ -311,9 +311,9 @@ fn moniker_to_symbol(moniker: &MonikerResult) -> scip_types::Symbol {
311311
scip_types::Symbol {
312312
scheme: "rust-analyzer".into(),
313313
package: Some(scip_types::Package {
314-
manager: "cargo".to_string(),
314+
manager: "cargo".to_owned(),
315315
name: package_name,
316-
version: version.unwrap_or_else(|| ".".to_string()),
316+
version: version.unwrap_or_else(|| ".".to_owned()),
317317
special_fields: Default::default(),
318318
})
319319
.into(),

crates/rust-analyzer/src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ impl Config {
904904
use serde::de::Error;
905905
if self.data.check_command.is_empty() {
906906
error_sink.push((
907-
"/check/command".to_string(),
907+
"/check/command".to_owned(),
908908
serde_json::Error::custom("expected a non-empty string"),
909909
));
910910
}
@@ -2626,7 +2626,7 @@ mod tests {
26262626
.replace('\n', "\n ")
26272627
.trim_start_matches('\n')
26282628
.trim_end()
2629-
.to_string();
2629+
.to_owned();
26302630
schema.push_str(",\n");
26312631

26322632
// Transform the asciidoc form link to markdown style.

crates/rust-analyzer/src/config/patch_old_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(super) fn patch_json_for_outdated_configs(json: &mut Value) {
1919
Some(it) => {
2020
let mut last = it;
2121
for segment in [$(stringify!($dst)),+].into_iter().rev() {
22-
last = Value::Object(serde_json::Map::from_iter(std::iter::once((segment.to_string(), last))));
22+
last = Value::Object(serde_json::Map::from_iter(std::iter::once((segment.to_owned(), last))));
2323
}
2424

2525
merge(json, last);

0 commit comments

Comments
 (0)