Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: Enable str_to_string Clippy rule #16521

Merged
merged 28 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8c2f301
ide: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
a9a315f
base-db: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
99f5d7c
hir-def: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
cb95ee3
hir-def: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
d580b2c
hir-ty: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
eba1b13
hir: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
d00f1c1
ide-diagnostics: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
5d1f283
project-model: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
b89a403
proc-macro-api: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
80e6842
ide-assists: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
395708d
rust-analyzer: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
f4a4b66
ide-completion: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
fb8c0f5
ide-db: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
ae78dca
ide-ssr: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
8071325
load-cargo: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
edda6b8
mbe: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
f474bd7
parser: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
81c35d1
syntax: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
cee3c22
vfs: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
283b140
salsa: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
06f3995
xtask: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
0a879f7
sourcegen: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
c3699b9
test-utils: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
bffb888
lsp-server: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
1915d9a
tt: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
a897566
test-fixture: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
88f088c
text-edit: Fix warnings about clippy `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
71ea70e
clippy: Enable `str_to_string` rule
tetsuharuohzeki Feb 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,4 @@ print_stdout = "warn"
print_stderr = "warn"

rc_buffer = "warn"
# FIXME enable this, we use this pattern a lot so its annoying work ...
# str_to_string = "warn"
str_to_string = "warn"
2 changes: 1 addition & 1 deletion crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ impl FromStr for Edition {
"2018" => Edition::Edition2018,
"2021" => Edition::Edition2021,
"2024" => Edition::Edition2024,
_ => return Err(ParseEditionError { invalid_input: s.to_string() }),
_ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
};
Ok(res)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-def/src/body/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
"const {} = ",
match &it.name {
Some(name) => name.display(db.upcast()).to_string(),
None => "_".to_string(),
None => "_".to_owned(),
}
)
}),
DefWithBodyId::InTypeConstId(_) => "In type const = ".to_string(),
DefWithBodyId::InTypeConstId(_) => "In type const = ".to_owned(),
DefWithBodyId::VariantId(it) => {
let loc = it.lookup(db);
let enum_loc = loc.parent.lookup(db);
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Printer<'_> {
wln!(self);
f(self);
self.indent_level -= 1;
self.buf = self.buf.trim_end_matches('\n').to_string();
self.buf = self.buf.trim_end_matches('\n').to_owned();
}

fn whitespace(&mut self) {
Expand Down
18 changes: 8 additions & 10 deletions crates/hir-def/src/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ mod tests {
check_search(
ra_fixture,
"main",
Query::new("fmt".to_string()).fuzzy(),
Query::new("fmt".to_owned()).fuzzy(),
expect![[r#"
dep::fmt (t)
dep::fmt::Display::FMT_CONST (a)
Expand Down Expand Up @@ -888,9 +888,7 @@ mod tests {
check_search(
ra_fixture,
"main",
Query::new("fmt".to_string())
.fuzzy()
.assoc_search_mode(AssocSearchMode::AssocItemsOnly),
Query::new("fmt".to_owned()).fuzzy().assoc_search_mode(AssocSearchMode::AssocItemsOnly),
expect![[r#"
dep::fmt::Display::FMT_CONST (a)
dep::fmt::Display::format_function (a)
Expand All @@ -901,7 +899,7 @@ mod tests {
check_search(
ra_fixture,
"main",
Query::new("fmt".to_string()).fuzzy().assoc_search_mode(AssocSearchMode::Exclude),
Query::new("fmt".to_owned()).fuzzy().assoc_search_mode(AssocSearchMode::Exclude),
expect![[r#"
dep::fmt (t)
"#]],
Expand Down Expand Up @@ -937,7 +935,7 @@ pub mod fmt {
check_search(
ra_fixture,
"main",
Query::new("fmt".to_string()).fuzzy(),
Query::new("fmt".to_owned()).fuzzy(),
expect![[r#"
dep::Fmt (m)
dep::Fmt (t)
Expand All @@ -951,7 +949,7 @@ pub mod fmt {
check_search(
ra_fixture,
"main",
Query::new("fmt".to_string()),
Query::new("fmt".to_owned()),
expect![[r#"
dep::Fmt (m)
dep::Fmt (t)
Expand Down Expand Up @@ -991,7 +989,7 @@ pub mod fmt {
check_search(
ra_fixture,
"main",
Query::new("fmt".to_string()),
Query::new("fmt".to_owned()),
expect![[r#"
dep::Fmt (m)
dep::Fmt (t)
Expand All @@ -1015,7 +1013,7 @@ pub mod fmt {
check_search(
ra_fixture,
"main",
Query::new("FMT".to_string()),
Query::new("FMT".to_owned()),
expect![[r#"
dep::FMT (t)
dep::FMT (v)
Expand All @@ -1027,7 +1025,7 @@ pub mod fmt {
check_search(
ra_fixture,
"main",
Query::new("FMT".to_string()).case_sensitive(),
Query::new("FMT".to_owned()).case_sensitive(),
expect![[r#"
dep::FMT (t)
dep::FMT (v)
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/item_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ impl ItemScope {
format_to!(
buf,
"{}:",
name.map_or("_".to_string(), |name| name.display(db).to_string())
name.map_or("_".to_owned(), |name| name.display(db).to_string())
);

if let Some((.., i)) = def.types {
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/item_tree/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(super) fn print_item_tree(db: &dyn DefDatabase, tree: &ItemTree) -> String {
p.print_mod_item(*item);
}

let mut s = p.buf.trim_end_matches('\n').to_string();
let mut s = p.buf.trim_end_matches('\n').to_owned();
s.push('\n');
s
}
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Printer<'_> {
wln!(self);
f(self);
self.indent_level -= 1;
self.buf = self.buf.trim_end_matches('\n').to_string();
self.buf = self.buf.trim_end_matches('\n').to_owned();
}

/// Ensures that a blank line is output before the next text.
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-def/src/macro_expansion_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ fn reindent(indent: IndentLevel, pp: String) -> String {
return pp;
}
let mut lines = pp.split_inclusive('\n');
let mut res = lines.next().unwrap().to_string();
let mut res = lines.next().unwrap().to_owned();
for line in lines {
if line.trim().is_empty() {
res.push_str(line)
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-expand/src/builtin_fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ fn concat_bytes_expand(
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
let token = ast::make::tokens::literal(&lit.to_string());
match token.kind() {
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_owned()),
syntax::SyntaxKind::BYTE_STRING => {
let components = unquote_byte_string(lit).unwrap_or_default();
components.into_iter().for_each(|it| bytes.push(it.to_string()));
Expand Down Expand Up @@ -570,7 +570,7 @@ fn concat_bytes_expand_subtree(
let lit = ast::make::tokens::literal(&lit.to_string());
match lit.kind() {
syntax::SyntaxKind::BYTE | syntax::SyntaxKind::INT_NUMBER => {
bytes.push(lit.text().to_string())
bytes.push(lit.text().to_owned())
}
_ => {
return Err(mbe::ExpandError::UnexpectedToken.into());
Expand Down Expand Up @@ -749,7 +749,7 @@ fn env_expand(
// We cannot use an empty string here, because for
// `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become
// `include!("foo.rs"), which might go to infinite loop
"UNRESOLVED_ENV_VAR".to_string()
"UNRESOLVED_ENV_VAR".to_owned()
});
let expanded = quote! {span => #s };

Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/consteval/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn bit_op() {
check_number(r#"const GOAL: i8 = 1 << 7"#, (1i8 << 7) as i128);
check_number(r#"const GOAL: i8 = -1 << 2"#, (-1i8 << 2) as i128);
check_fail(r#"const GOAL: i8 = 1 << 8"#, |e| {
e == ConstEvalError::MirEvalError(MirEvalError::Panic("Overflow in Shl".to_string()))
e == ConstEvalError::MirEvalError(MirEvalError::Panic("Overflow in Shl".to_owned()))
});
check_number(r#"const GOAL: i32 = 100000000i32 << 11"#, (100000000i32 << 11) as i128);
}
Expand Down Expand Up @@ -2756,7 +2756,7 @@ fn memory_limit() {
"#,
|e| {
e == ConstEvalError::MirEvalError(MirEvalError::Panic(
"Memory allocation of 30000000000 bytes failed".to_string(),
"Memory allocation of 30000000000 bytes failed".to_owned(),
))
},
);
Expand Down
10 changes: 4 additions & 6 deletions crates/hir-ty/src/infer/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,15 @@ impl CapturedItem {
}
let variant_data = f.parent.variant_data(db.upcast());
let field = match &*variant_data {
VariantData::Record(fields) => fields[f.local_id]
.name
.as_str()
.unwrap_or("[missing field]")
.to_string(),
VariantData::Record(fields) => {
fields[f.local_id].name.as_str().unwrap_or("[missing field]").to_owned()
}
VariantData::Tuple(fields) => fields
.iter()
.position(|it| it.0 == f.local_id)
.unwrap_or_default()
.to_string(),
VariantData::Unit => "[missing field]".to_string(),
VariantData::Unit => "[missing field]".to_owned(),
};
result = format!("{result}.{field}");
field_need_paren = false;
Expand Down
8 changes: 4 additions & 4 deletions crates/hir-ty/src/mir/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ impl Evaluator<'_> {
}
};
mem.get(pos..pos + size)
.ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory read".to_string()))
.ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory read".to_owned()))
}

fn write_memory_using_ref(&mut self, addr: Address, size: usize) -> Result<&mut [u8]> {
Expand All @@ -1777,7 +1777,7 @@ impl Evaluator<'_> {
}
};
mem.get_mut(pos..pos + size)
.ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory write".to_string()))
.ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory write".to_owned()))
}

fn write_memory(&mut self, addr: Address, r: &[u8]) -> Result<()> {
Expand All @@ -1800,7 +1800,7 @@ impl Evaluator<'_> {
return Ok(());
}

let oob = || MirEvalError::UndefinedBehavior("out of bounds memory write".to_string());
let oob = || MirEvalError::UndefinedBehavior("out of bounds memory write".to_owned());

match (addr, r.addr) {
(Stack(dst), Stack(src)) => {
Expand Down Expand Up @@ -2653,7 +2653,7 @@ pub fn render_const_using_debug_impl(
ptr: ArenaMap::new(),
body: db
.mir_body(owner.into())
.map_err(|_| MirEvalError::NotSupported("unreachable".to_string()))?,
.map_err(|_| MirEvalError::NotSupported("unreachable".to_owned()))?,
drop_flags: DropFlags::default(),
};
let data = evaluator.allocate_const_in_heap(locals, c)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/mir/eval/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl Evaluator<'_> {
use LangItem::*;
let mut args = args.iter();
match it {
BeginPanic => Err(MirEvalError::Panic("<unknown-panic-payload>".to_string())),
BeginPanic => Err(MirEvalError::Panic("<unknown-panic-payload>".to_owned())),
PanicFmt => {
let message = (|| {
let resolver = self
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.set_goto(prev_block, begin, span);
f(self, begin)?;
let my = mem::replace(&mut self.current_loop_blocks, prev).ok_or(
MirLowerError::ImplementationError("current_loop_blocks is corrupt".to_string()),
MirLowerError::ImplementationError("current_loop_blocks is corrupt".to_owned()),
)?;
if let Some(prev) = prev_label {
self.labeled_loop_blocks.insert(label.unwrap(), prev);
Expand Down Expand Up @@ -1669,7 +1669,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
.current_loop_blocks
.as_mut()
.ok_or(MirLowerError::ImplementationError(
"Current loop access out of loop".to_string(),
"Current loop access out of loop".to_owned(),
))?
.end
{
Expand All @@ -1679,7 +1679,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.current_loop_blocks
.as_mut()
.ok_or(MirLowerError::ImplementationError(
"Current loop access out of loop".to_string(),
"Current loop access out of loop".to_owned(),
))?
.end = Some(s);
s
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-ty/src/mir/lower/as_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl MirLowerCtx<'_> {
{
let Some(index_fn) = self.infer.method_resolution(expr_id) else {
return Err(MirLowerError::UnresolvedMethod(
"[overloaded index]".to_string(),
"[overloaded index]".to_owned(),
));
};
let Some((base_place, current)) =
Expand Down
6 changes: 3 additions & 3 deletions crates/hir-ty/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
if only_types {
types.insert(file_range, expected);
} else if expected.starts_with("type: ") {
types.insert(file_range, expected.trim_start_matches("type: ").to_string());
types.insert(file_range, expected.trim_start_matches("type: ").to_owned());
} else if expected.starts_with("expected") {
mismatches.insert(file_range, expected);
} else if expected.starts_with("adjustments:") {
Expand All @@ -110,7 +110,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
.trim_start_matches("adjustments:")
.trim()
.split(',')
.map(|it| it.trim().to_string())
.map(|it| it.trim().to_owned())
.filter(|it| !it.is_empty())
.collect(),
);
Expand Down Expand Up @@ -331,7 +331,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
});
for (node, ty) in &types {
let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.value.clone()) {
(self_param.name().unwrap().syntax().text_range(), "self".to_string())
(self_param.name().unwrap().syntax().text_range(), "self".to_owned())
} else {
(node.value.text_range(), node.value.text().to_string().replace('\n', " "))
};
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ pub(crate) fn trait_solve_query(
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::Implemented(it))) => {
db.trait_data(it.hir_trait_id()).name.display(db.upcast()).to_string()
}
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::AliasEq(_))) => "alias_eq".to_string(),
_ => "??".to_string(),
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::AliasEq(_))) => "alias_eq".to_owned(),
_ => "??".to_owned(),
};
let _p = tracing::span!(tracing::Level::INFO, "trait_solve_query", ?detail).entered();
tracing::info!("trait_solve_query({:?})", goal.value.goal);
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ impl Function {
};
let (result, output) = interpret_mir(db, body, false, None);
let mut text = match result {
Ok(_) => "pass".to_string(),
Ok(_) => "pass".to_owned(),
Err(e) => {
let mut r = String::new();
_ = e.pretty_print(&mut r, db, &span_formatter);
Expand Down
4 changes: 2 additions & 2 deletions crates/ide-assists/src/handlers/apply_demorgan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext<'_>) -> Opti
let dm_lhs = demorganed.lhs()?;

acc.add_group(
&GroupLabel("Apply De Morgan's law".to_string()),
&GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan", AssistKind::RefactorRewrite),
"Apply De Morgan's law",
op_range,
Expand Down Expand Up @@ -187,7 +187,7 @@ pub(crate) fn apply_demorgan_iterator(acc: &mut Assists, ctx: &AssistContext<'_>
let op_range = method_call.syntax().text_range();
let label = format!("Apply De Morgan's law to `Iterator::{}`", name.text().as_str());
acc.add_group(
&GroupLabel("Apply De Morgan's law".to_string()),
&GroupLabel("Apply De Morgan's law".to_owned()),
AssistId("apply_demorgan_iterator", AssistKind::RefactorRewrite),
label,
op_range,
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/convert_comment_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn block_to_line(acc: &mut Assists, comment: ast::Comment) -> Option<()> {

// Don't introduce trailing whitespace
if line.is_empty() {
line_prefix.to_string()
line_prefix.to_owned()
} else {
format!("{line_prefix} {line}")
}
Expand Down
4 changes: 2 additions & 2 deletions crates/ide-assists/src/handlers/extract_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn make_function_name(semantics_scope: &hir::SemanticsScope<'_>) -> ast::NameRef

let default_name = "fun_name";

let mut name = default_name.to_string();
let mut name = default_name.to_owned();
let mut counter = 0;
while names_in_scope.contains(&name) {
counter += 1;
Expand Down Expand Up @@ -1949,7 +1949,7 @@ fn with_tail_expr(block: ast::BlockExpr, tail_expr: ast::Expr) -> ast::BlockExpr
}

fn format_type(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> String {
ty.display_source_code(ctx.db(), module.into(), true).ok().unwrap_or_else(|| "_".to_string())
ty.display_source_code(ctx.db(), module.into(), true).ok().unwrap_or_else(|| "_".to_owned())
}

fn make_ty(ty: &hir::Type, ctx: &AssistContext<'_>, module: hir::Module) -> ast::Type {
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/extract_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
let trailing_ws = if prev_ws.is_some_and(|it| it.text().starts_with('\n')) {
format!("\n{indent_to}")
} else {
" ".to_string()
" ".to_owned()
};

ted::insert_all_raw(
Expand Down
Loading
Loading