syntax: Fix warnings about clippy str_to_string rule

This commit is contained in:
Tetsuharu Ohzeki 2024-02-10 00:51:58 +09:00
parent f474bd77be
commit 81c35d1f56
6 changed files with 14 additions and 14 deletions

View file

@ -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"),

View file

@ -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

View file

@ -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;

View file

@ -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())
}
});

View file

@ -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);

View file

@ -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);
}
}