Skip to content

Commit 81c35d1

Browse files
syntax: Fix warnings about clippy str_to_string rule
1 parent f474bd7 commit 81c35d1

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

crates/syntax/src/ast/make.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ pub fn impl_(
249249
let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
250250

251251
let body_newline =
252-
if where_clause.is_some() && body.is_none() { "\n".to_string() } else { String::new() };
252+
if where_clause.is_some() && body.is_none() { "\n".to_owned() } else { String::new() };
253253

254254
let where_clause = match where_clause {
255255
Some(pr) => format!("\n{pr}\n"),
256-
None => " ".to_string(),
256+
None => " ".to_owned(),
257257
};
258258

259259
let body = match body {
@@ -291,13 +291,13 @@ pub fn impl_trait(
291291

292292
let body_newline =
293293
if (ty_where_clause.is_some() || trait_where_clause.is_some()) && body.is_none() {
294-
"\n".to_string()
294+
"\n".to_owned()
295295
} else {
296296
String::new()
297297
};
298298

299299
let where_clause = merge_where_clause(ty_where_clause, trait_where_clause)
300-
.map_or_else(|| " ".to_string(), |wc| format!("\n{}\n", wc));
300+
.map_or_else(|| " ".to_owned(), |wc| format!("\n{}\n", wc));
301301

302302
let body = match body {
303303
Some(bd) => bd.iter().map(|elem| elem.to_string()).join(""),
@@ -378,7 +378,7 @@ pub fn use_tree(
378378
alias: Option<ast::Rename>,
379379
add_star: bool,
380380
) -> ast::UseTree {
381-
let mut buf = "use ".to_string();
381+
let mut buf = "use ".to_owned();
382382
buf += &path.syntax().to_string();
383383
if let Some(use_tree_list) = use_tree_list {
384384
format_to!(buf, "::{use_tree_list}");
@@ -444,7 +444,7 @@ pub fn block_expr(
444444
stmts: impl IntoIterator<Item = ast::Stmt>,
445445
tail_expr: Option<ast::Expr>,
446446
) -> ast::BlockExpr {
447-
let mut buf = "{\n".to_string();
447+
let mut buf = "{\n".to_owned();
448448
for stmt in stmts.into_iter() {
449449
format_to!(buf, " {stmt}\n");
450450
}
@@ -459,7 +459,7 @@ pub fn async_move_block_expr(
459459
stmts: impl IntoIterator<Item = ast::Stmt>,
460460
tail_expr: Option<ast::Expr>,
461461
) -> ast::BlockExpr {
462-
let mut buf = "async move {\n".to_string();
462+
let mut buf = "async move {\n".to_owned();
463463
for stmt in stmts.into_iter() {
464464
format_to!(buf, " {stmt}\n");
465465
}
@@ -482,7 +482,7 @@ pub fn hacky_block_expr(
482482
elements: impl IntoIterator<Item = crate::SyntaxElement>,
483483
tail_expr: Option<ast::Expr>,
484484
) -> ast::BlockExpr {
485-
let mut buf = "{\n".to_string();
485+
let mut buf = "{\n".to_owned();
486486
for node_or_token in elements.into_iter() {
487487
match node_or_token {
488488
rowan::NodeOrToken::Node(n) => format_to!(buf, " {n}\n"),

crates/syntax/src/fuzz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl CheckReparse {
3434
let mut lines = data.lines();
3535
let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len();
3636
let delete_len = usize::from_str(lines.next()?).ok()?;
37-
let insert = lines.next()?.to_string();
37+
let insert = lines.next()?.to_owned();
3838
let text = lines.collect::<Vec<_>>().join("\n");
3939
let text = format!("{PREFIX}{text}{SUFFIX}");
4040
text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range

crates/syntax/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn api_walkthrough() {
432432
WalkEvent::Enter(node) => {
433433
let text = match &node {
434434
NodeOrToken::Node(it) => it.text().to_string(),
435-
NodeOrToken::Token(it) => it.text().to_string(),
435+
NodeOrToken::Token(it) => it.text().to_owned(),
436436
};
437437
format_to!(buf, "{:indent$}{:?} {:?}\n", " ", text, node.kind(), indent = indent);
438438
indent += 2;

crates/syntax/src/parsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) fn build_tree(
2828
parser::StrStep::Enter { kind } => builder.start_node(kind),
2929
parser::StrStep::Exit => builder.finish_node(),
3030
parser::StrStep::Error { msg, pos } => {
31-
builder.error(msg.to_string(), pos.try_into().unwrap())
31+
builder.error(msg.to_owned(), pos.try_into().unwrap())
3232
}
3333
});
3434

crates/syntax/src/parsing/reparsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn get_text_after_edit(element: SyntaxElement, edit: &Indel) -> String {
105105
let edit = Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone());
106106

107107
let mut text = match element {
108-
NodeOrToken::Token(token) => token.text().to_string(),
108+
NodeOrToken::Token(token) => token.text().to_owned(),
109109
NodeOrToken::Node(node) => node.text().to_string(),
110110
};
111111
edit.apply(&mut text);

crates/syntax/src/tests/sourcegen_ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ fn lower(grammar: &Grammar) -> AstSrc {
573573
tokens:
574574
"Whitespace Comment String ByteString CString IntNumber FloatNumber Char Byte Ident"
575575
.split_ascii_whitespace()
576-
.map(|it| it.to_string())
576+
.map(|it| it.to_owned())
577577
.collect::<Vec<_>>(),
578578
..Default::default()
579579
};
@@ -816,7 +816,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str
816816
}
817817
}
818818
if to_remove.len() == methods.len() {
819-
node.traits.push(trait_name.to_string());
819+
node.traits.push(trait_name.to_owned());
820820
node.remove_field(to_remove);
821821
}
822822
}

0 commit comments

Comments
 (0)