mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
syntax: Fix warnings about clippy str_to_string
rule
This commit is contained in:
parent
f474bd77be
commit
81c35d1f56
6 changed files with 14 additions and 14 deletions
|
@ -249,11 +249,11 @@ pub fn impl_(
|
||||||
let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
|
let gen_params = generic_params.map_or_else(String::new, |it| it.to_string());
|
||||||
|
|
||||||
let body_newline =
|
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 {
|
let where_clause = match where_clause {
|
||||||
Some(pr) => format!("\n{pr}\n"),
|
Some(pr) => format!("\n{pr}\n"),
|
||||||
None => " ".to_string(),
|
None => " ".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let body = match body {
|
let body = match body {
|
||||||
|
@ -291,13 +291,13 @@ pub fn impl_trait(
|
||||||
|
|
||||||
let body_newline =
|
let body_newline =
|
||||||
if (ty_where_clause.is_some() || trait_where_clause.is_some()) && body.is_none() {
|
if (ty_where_clause.is_some() || trait_where_clause.is_some()) && body.is_none() {
|
||||||
"\n".to_string()
|
"\n".to_owned()
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
let where_clause = merge_where_clause(ty_where_clause, trait_where_clause)
|
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 {
|
let body = match body {
|
||||||
Some(bd) => bd.iter().map(|elem| elem.to_string()).join(""),
|
Some(bd) => bd.iter().map(|elem| elem.to_string()).join(""),
|
||||||
|
@ -378,7 +378,7 @@ pub fn use_tree(
|
||||||
alias: Option<ast::Rename>,
|
alias: Option<ast::Rename>,
|
||||||
add_star: bool,
|
add_star: bool,
|
||||||
) -> ast::UseTree {
|
) -> ast::UseTree {
|
||||||
let mut buf = "use ".to_string();
|
let mut buf = "use ".to_owned();
|
||||||
buf += &path.syntax().to_string();
|
buf += &path.syntax().to_string();
|
||||||
if let Some(use_tree_list) = use_tree_list {
|
if let Some(use_tree_list) = use_tree_list {
|
||||||
format_to!(buf, "::{use_tree_list}");
|
format_to!(buf, "::{use_tree_list}");
|
||||||
|
@ -444,7 +444,7 @@ pub fn block_expr(
|
||||||
stmts: impl IntoIterator<Item = ast::Stmt>,
|
stmts: impl IntoIterator<Item = ast::Stmt>,
|
||||||
tail_expr: Option<ast::Expr>,
|
tail_expr: Option<ast::Expr>,
|
||||||
) -> ast::BlockExpr {
|
) -> ast::BlockExpr {
|
||||||
let mut buf = "{\n".to_string();
|
let mut buf = "{\n".to_owned();
|
||||||
for stmt in stmts.into_iter() {
|
for stmt in stmts.into_iter() {
|
||||||
format_to!(buf, " {stmt}\n");
|
format_to!(buf, " {stmt}\n");
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ pub fn async_move_block_expr(
|
||||||
stmts: impl IntoIterator<Item = ast::Stmt>,
|
stmts: impl IntoIterator<Item = ast::Stmt>,
|
||||||
tail_expr: Option<ast::Expr>,
|
tail_expr: Option<ast::Expr>,
|
||||||
) -> ast::BlockExpr {
|
) -> ast::BlockExpr {
|
||||||
let mut buf = "async move {\n".to_string();
|
let mut buf = "async move {\n".to_owned();
|
||||||
for stmt in stmts.into_iter() {
|
for stmt in stmts.into_iter() {
|
||||||
format_to!(buf, " {stmt}\n");
|
format_to!(buf, " {stmt}\n");
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,7 @@ pub fn hacky_block_expr(
|
||||||
elements: impl IntoIterator<Item = crate::SyntaxElement>,
|
elements: impl IntoIterator<Item = crate::SyntaxElement>,
|
||||||
tail_expr: Option<ast::Expr>,
|
tail_expr: Option<ast::Expr>,
|
||||||
) -> ast::BlockExpr {
|
) -> ast::BlockExpr {
|
||||||
let mut buf = "{\n".to_string();
|
let mut buf = "{\n".to_owned();
|
||||||
for node_or_token in elements.into_iter() {
|
for node_or_token in elements.into_iter() {
|
||||||
match node_or_token {
|
match node_or_token {
|
||||||
rowan::NodeOrToken::Node(n) => format_to!(buf, " {n}\n"),
|
rowan::NodeOrToken::Node(n) => format_to!(buf, " {n}\n"),
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl CheckReparse {
|
||||||
let mut lines = data.lines();
|
let mut lines = data.lines();
|
||||||
let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len();
|
let delete_start = usize::from_str(lines.next()?).ok()? + PREFIX.len();
|
||||||
let delete_len = usize::from_str(lines.next()?).ok()?;
|
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 = lines.collect::<Vec<_>>().join("\n");
|
||||||
let text = format!("{PREFIX}{text}{SUFFIX}");
|
let text = format!("{PREFIX}{text}{SUFFIX}");
|
||||||
text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range
|
text.get(delete_start..delete_start.checked_add(delete_len)?)?; // make sure delete is a valid range
|
||||||
|
|
|
@ -432,7 +432,7 @@ fn api_walkthrough() {
|
||||||
WalkEvent::Enter(node) => {
|
WalkEvent::Enter(node) => {
|
||||||
let text = match &node {
|
let text = match &node {
|
||||||
NodeOrToken::Node(it) => it.text().to_string(),
|
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);
|
format_to!(buf, "{:indent$}{:?} {:?}\n", " ", text, node.kind(), indent = indent);
|
||||||
indent += 2;
|
indent += 2;
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub(crate) fn build_tree(
|
||||||
parser::StrStep::Enter { kind } => builder.start_node(kind),
|
parser::StrStep::Enter { kind } => builder.start_node(kind),
|
||||||
parser::StrStep::Exit => builder.finish_node(),
|
parser::StrStep::Exit => builder.finish_node(),
|
||||||
parser::StrStep::Error { msg, pos } => {
|
parser::StrStep::Error { msg, pos } => {
|
||||||
builder.error(msg.to_string(), pos.try_into().unwrap())
|
builder.error(msg.to_owned(), pos.try_into().unwrap())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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 edit = Indel::replace(edit.delete - element.text_range().start(), edit.insert.clone());
|
||||||
|
|
||||||
let mut text = match element {
|
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(),
|
NodeOrToken::Node(node) => node.text().to_string(),
|
||||||
};
|
};
|
||||||
edit.apply(&mut text);
|
edit.apply(&mut text);
|
||||||
|
|
|
@ -573,7 +573,7 @@ fn lower(grammar: &Grammar) -> AstSrc {
|
||||||
tokens:
|
tokens:
|
||||||
"Whitespace Comment String ByteString CString IntNumber FloatNumber Char Byte Ident"
|
"Whitespace Comment String ByteString CString IntNumber FloatNumber Char Byte Ident"
|
||||||
.split_ascii_whitespace()
|
.split_ascii_whitespace()
|
||||||
.map(|it| it.to_string())
|
.map(|it| it.to_owned())
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
@ -816,7 +816,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if to_remove.len() == methods.len() {
|
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);
|
node.remove_field(to_remove);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue