about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTetsuharu Ohzeki <tetsuharu.ohzeki@gmail.com>2024-02-10 00:51:58 +0900
committerTetsuharu Ohzeki <tetsuharu.ohzeki@gmail.com>2024-02-10 01:00:40 +0900
commit81c35d1f5633ba2fd10d242f4539e5d731279a8d (patch)
treeb94953a7bd7e72c145f354cc6f31a8c91cde63bb
parentf474bd77be417f2de3f0679e2847d0190b1d27c6 (diff)
downloadrust-81c35d1f5633ba2fd10d242f4539e5d731279a8d.tar.gz
rust-81c35d1f5633ba2fd10d242f4539e5d731279a8d.zip
syntax: Fix warnings about clippy `str_to_string` rule
-rw-r--r--crates/syntax/src/ast/make.rs16
-rw-r--r--crates/syntax/src/fuzz.rs2
-rw-r--r--crates/syntax/src/lib.rs2
-rw-r--r--crates/syntax/src/parsing.rs2
-rw-r--r--crates/syntax/src/parsing/reparsing.rs2
-rw-r--r--crates/syntax/src/tests/sourcegen_ast.rs4
6 files changed, 14 insertions, 14 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 9d6ed673610..120d801c8d1 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -249,11 +249,11 @@ pub fn impl_(
     let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
 
     let body_newline =
-        if where_clause.is_some() && body.is_none() { "\n".to_string() } else { String::new() };
+        if where_clause.is_some() && body.is_none() { "\n".to_owned() } else { String::new() };
 
     let where_clause = match where_clause {
         Some(pr) => format!("\n{pr}\n"),
-        None => " ".to_string(),
+        None => " ".to_owned(),
     };
 
     let body = match body {
@@ -291,13 +291,13 @@ pub fn impl_trait(
 
     let body_newline =
         if (ty_where_clause.is_some() || trait_where_clause.is_some()) && body.is_none() {
-            "\n".to_string()
+            "\n".to_owned()
         } else {
             String::new()
         };
 
     let where_clause = merge_where_clause(ty_where_clause, trait_where_clause)
-        .map_or_else(|| " ".to_string(), |wc| format!("\n{}\n", wc));
+        .map_or_else(|| " ".to_owned(), |wc| format!("\n{}\n", wc));
 
     let body = match body {
         Some(bd) => bd.iter().map(|elem| elem.to_string()).join(""),
@@ -378,7 +378,7 @@ pub fn use_tree(
     alias: Option<ast::Rename>,
     add_star: bool,
 ) -> ast::UseTree {
-    let mut buf = "use ".to_string();
+    let mut buf = "use ".to_owned();
     buf += &path.syntax().to_string();
     if let Some(use_tree_list) = use_tree_list {
         format_to!(buf, "::{use_tree_list}");
@@ -444,7 +444,7 @@ pub fn block_expr(
     stmts: impl IntoIterator<Item = ast::Stmt>,
     tail_expr: Option<ast::Expr>,
 ) -> ast::BlockExpr {
-    let mut buf = "{\n".to_string();
+    let mut buf = "{\n".to_owned();
     for stmt in stmts.into_iter() {
         format_to!(buf, "    {stmt}\n");
     }
@@ -459,7 +459,7 @@ pub fn async_move_block_expr(
     stmts: impl IntoIterator<Item = ast::Stmt>,
     tail_expr: Option<ast::Expr>,
 ) -> ast::BlockExpr {
-    let mut buf = "async move {\n".to_string();
+    let mut buf = "async move {\n".to_owned();
     for stmt in stmts.into_iter() {
         format_to!(buf, "    {stmt}\n");
     }
@@ -482,7 +482,7 @@ pub fn hacky_block_expr(
     elements: impl IntoIterator<Item = crate::SyntaxElement>,
     tail_expr: Option<ast::Expr>,
 ) -> ast::BlockExpr {
-    let mut buf = "{\n".to_string();
+    let mut buf = "{\n".to_owned();
     for node_or_token in elements.into_iter() {
         match node_or_token {
             rowan::NodeOrToken::Node(n) => format_to!(buf, "    {n}\n"),
diff --git a/crates/syntax/src/fuzz.rs b/crates/syntax/src/fuzz.rs
index 15e68fc575d..28738671790 100644
--- a/crates/syntax/src/fuzz.rs
+++ b/crates/syntax/src/fuzz.rs
@@ -34,7 +34,7 @@ impl CheckReparse {
         let mut lines = data.lines();
         let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len();
         let delete_len = usize::from_str(lines.next()?).ok()?;
-        let insert = lines.next()?.to_string();
+        let insert = lines.next()?.to_owned();
         let text = lines.collect::<Vec<_>>().join("\n");
         let text = format!("{PREFIX}{text}{SUFFIX}");
         text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs
index 62a0261d7a4..960889b7421 100644
--- a/crates/syntax/src/lib.rs
+++ b/crates/syntax/src/lib.rs
@@ -432,7 +432,7 @@ fn api_walkthrough() {
             WalkEvent::Enter(node) => {
                 let text = match &node {
                     NodeOrToken::Node(it) => it.text().to_string(),
-                    NodeOrToken::Token(it) => it.text().to_string(),
+                    NodeOrToken::Token(it) => it.text().to_owned(),
                 };
                 format_to!(buf, "{:indent$}{:?} {:?}\n", " ", text, node.kind(), indent = indent);
                 indent += 2;
diff --git a/crates/syntax/src/parsing.rs b/crates/syntax/src/parsing.rs
index 047e670c9f4..1250b5274c1 100644
--- a/crates/syntax/src/parsing.rs
+++ b/crates/syntax/src/parsing.rs
@@ -28,7 +28,7 @@ pub(crate) fn build_tree(
         parser::StrStep::Enter { kind } => builder.start_node(kind),
         parser::StrStep::Exit => builder.finish_node(),
         parser::StrStep::Error { msg, pos } => {
-            builder.error(msg.to_string(), pos.try_into().unwrap())
+            builder.error(msg.to_owned(), pos.try_into().unwrap())
         }
     });
 
diff --git a/crates/syntax/src/parsing/reparsing.rs b/crates/syntax/src/parsing/reparsing.rs
index 0ddc641711f..14715b57253 100644
--- a/crates/syntax/src/parsing/reparsing.rs
+++ b/crates/syntax/src/parsing/reparsing.rs
@@ -105,7 +105,7 @@ fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String {
     let edit = Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone());
 
     let mut text = match element {
-        NodeOrToken::Token(token) => token.text().to_string(),
+        NodeOrToken::Token(token) => token.text().to_owned(),
         NodeOrToken::Node(node) => node.text().to_string(),
     };
     edit.apply(&mut text);
diff --git a/crates/syntax/src/tests/sourcegen_ast.rs b/crates/syntax/src/tests/sourcegen_ast.rs
index ccb13a0d933..2fd7a473498 100644
--- a/crates/syntax/src/tests/sourcegen_ast.rs
+++ b/crates/syntax/src/tests/sourcegen_ast.rs
@@ -573,7 +573,7 @@ fn lower(grammar: &Grammar) -> AstSrc {
         tokens:
             "Whitespace Comment String ByteString CString IntNumber FloatNumber Char Byte Ident"
                 .split_ascii_whitespace()
-                .map(|it| it.to_string())
+                .map(|it| it.to_owned())
                 .collect::<Vec<_>>(),
         ..Default::default()
     };
@@ -816,7 +816,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str
         }
     }
     if to_remove.len() == methods.len() {
-        node.traits.push(trait_name.to_string());
+        node.traits.push(trait_name.to_owned());
         node.remove_field(to_remove);
     }
 }