Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7e92655

Browse files
committed
Auto merge of rust-lang#16521 - tetsuharuohzeki:experiment-enable-str_to_string, r=lnicola
internal: Enable str_to_string Clippy rule This fix [the FIXME comment](https://github.com/rust-lang/rust-analyzer/blob/bb0de88f24cc3a8de10837585fbb8172f6859752/Cargo.toml#L183-L184)
2 parents bb0de88 + 71ea70e commit 7e92655

File tree

149 files changed

+382
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+382
-391
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,4 @@ print_stdout = "warn"
180180
print_stderr = "warn"
181181

182182
rc_buffer = "warn"
183-
# FIXME enable this, we use this pattern a lot so its annoying work ...
184-
# str_to_string = "warn"
183+
str_to_string = "warn"

crates/base-db/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl FromStr for Edition {
782782
"2018" => Edition::Edition2018,
783783
"2021" => Edition::Edition2021,
784784
"2024" => Edition::Edition2024,
785-
_ => return Err(ParseEditionError { invalid_input: s.to_string() }),
785+
_ => return Err(ParseEditionError { invalid_input: s.to_owned() }),
786786
};
787787
Ok(res)
788788
}

crates/hir-def/src/body/pretty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
2929
"const {} = ",
3030
match &it.name {
3131
Some(name) => name.display(db.upcast()).to_string(),
32-
None => "_".to_string(),
32+
None => "_".to_owned(),
3333
}
3434
)
3535
}),
36-
DefWithBodyId::InTypeConstId(_) => "In type const = ".to_string(),
36+
DefWithBodyId::InTypeConstId(_) => "In type const = ".to_owned(),
3737
DefWithBodyId::VariantId(it) => {
3838
let loc = it.lookup(db);
3939
let enum_loc = loc.parent.lookup(db);
@@ -123,7 +123,7 @@ impl Printer<'_> {
123123
wln!(self);
124124
f(self);
125125
self.indent_level -= 1;
126-
self.buf = self.buf.trim_end_matches('\n').to_string();
126+
self.buf = self.buf.trim_end_matches('\n').to_owned();
127127
}
128128

129129
fn whitespace(&mut self) {

crates/hir-def/src/import_map.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ mod tests {
859859
check_search(
860860
ra_fixture,
861861
"main",
862-
Query::new("fmt".to_string()).fuzzy(),
862+
Query::new("fmt".to_owned()).fuzzy(),
863863
expect![[r#"
864864
dep::fmt (t)
865865
dep::fmt::Display::FMT_CONST (a)
@@ -888,9 +888,7 @@ mod tests {
888888
check_search(
889889
ra_fixture,
890890
"main",
891-
Query::new("fmt".to_string())
892-
.fuzzy()
893-
.assoc_search_mode(AssocSearchMode::AssocItemsOnly),
891+
Query::new("fmt".to_owned()).fuzzy().assoc_search_mode(AssocSearchMode::AssocItemsOnly),
894892
expect![[r#"
895893
dep::fmt::Display::FMT_CONST (a)
896894
dep::fmt::Display::format_function (a)
@@ -901,7 +899,7 @@ mod tests {
901899
check_search(
902900
ra_fixture,
903901
"main",
904-
Query::new("fmt".to_string()).fuzzy().assoc_search_mode(AssocSearchMode::Exclude),
902+
Query::new("fmt".to_owned()).fuzzy().assoc_search_mode(AssocSearchMode::Exclude),
905903
expect![[r#"
906904
dep::fmt (t)
907905
"#]],
@@ -937,7 +935,7 @@ pub mod fmt {
937935
check_search(
938936
ra_fixture,
939937
"main",
940-
Query::new("fmt".to_string()).fuzzy(),
938+
Query::new("fmt".to_owned()).fuzzy(),
941939
expect![[r#"
942940
dep::Fmt (m)
943941
dep::Fmt (t)
@@ -951,7 +949,7 @@ pub mod fmt {
951949
check_search(
952950
ra_fixture,
953951
"main",
954-
Query::new("fmt".to_string()),
952+
Query::new("fmt".to_owned()),
955953
expect![[r#"
956954
dep::Fmt (m)
957955
dep::Fmt (t)
@@ -991,7 +989,7 @@ pub mod fmt {
991989
check_search(
992990
ra_fixture,
993991
"main",
994-
Query::new("fmt".to_string()),
992+
Query::new("fmt".to_owned()),
995993
expect![[r#"
996994
dep::Fmt (m)
997995
dep::Fmt (t)
@@ -1015,7 +1013,7 @@ pub mod fmt {
10151013
check_search(
10161014
ra_fixture,
10171015
"main",
1018-
Query::new("FMT".to_string()),
1016+
Query::new("FMT".to_owned()),
10191017
expect![[r#"
10201018
dep::FMT (t)
10211019
dep::FMT (v)
@@ -1027,7 +1025,7 @@ pub mod fmt {
10271025
check_search(
10281026
ra_fixture,
10291027
"main",
1030-
Query::new("FMT".to_string()).case_sensitive(),
1028+
Query::new("FMT".to_owned()).case_sensitive(),
10311029
expect![[r#"
10321030
dep::FMT (t)
10331031
dep::FMT (v)

crates/hir-def/src/item_scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ impl ItemScope {
672672
format_to!(
673673
buf,
674674
"{}:",
675-
name.map_or("_".to_string(), |name| name.display(db).to_string())
675+
name.map_or("_".to_owned(), |name| name.display(db).to_string())
676676
);
677677

678678
if let Some((.., i)) = def.types {

crates/hir-def/src/item_tree/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn print_item_tree(db: &dyn DefDatabase, tree: &ItemTree) -> String {
2424
p.print_mod_item(*item);
2525
}
2626

27-
let mut s = p.buf.trim_end_matches('\n').to_string();
27+
let mut s = p.buf.trim_end_matches('\n').to_owned();
2828
s.push('\n');
2929
s
3030
}
@@ -58,7 +58,7 @@ impl Printer<'_> {
5858
wln!(self);
5959
f(self);
6060
self.indent_level -= 1;
61-
self.buf = self.buf.trim_end_matches('\n').to_string();
61+
self.buf = self.buf.trim_end_matches('\n').to_owned();
6262
}
6363

6464
/// Ensures that a blank line is output before the next text.

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ fn reindent(indent: IndentLevel, pp: String) -> String {
224224
return pp;
225225
}
226226
let mut lines = pp.split_inclusive('\n');
227-
let mut res = lines.next().unwrap().to_string();
227+
let mut res = lines.next().unwrap().to_owned();
228228
for line in lines {
229229
if line.trim().is_empty() {
230230
res.push_str(line)

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ fn concat_bytes_expand(
515515
tt::TokenTree::Leaf(tt::Leaf::Literal(lit)) => {
516516
let token = ast::make::tokens::literal(&lit.to_string());
517517
match token.kind() {
518-
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_string()),
518+
syntax::SyntaxKind::BYTE => bytes.push(token.text().to_owned()),
519519
syntax::SyntaxKind::BYTE_STRING => {
520520
let components = unquote_byte_string(lit).unwrap_or_default();
521521
components.into_iter().for_each(|it| bytes.push(it.to_string()));
@@ -570,7 +570,7 @@ fn concat_bytes_expand_subtree(
570570
let lit = ast::make::tokens::literal(&lit.to_string());
571571
match lit.kind() {
572572
syntax::SyntaxKind::BYTE | syntax::SyntaxKind::INT_NUMBER => {
573-
bytes.push(lit.text().to_string())
573+
bytes.push(lit.text().to_owned())
574574
}
575575
_ => {
576576
return Err(mbe::ExpandError::UnexpectedToken.into());
@@ -749,7 +749,7 @@ fn env_expand(
749749
// We cannot use an empty string here, because for
750750
// `include!(concat!(env!("OUT_DIR"), "/foo.rs"))` will become
751751
// `include!("foo.rs"), which might go to infinite loop
752-
"UNRESOLVED_ENV_VAR".to_string()
752+
"UNRESOLVED_ENV_VAR".to_owned()
753753
});
754754
let expanded = quote! {span => #s };
755755

crates/hir-ty/src/consteval/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ fn bit_op() {
133133
check_number(r#"const GOAL: i8 = 1 << 7"#, (1i8 << 7) as i128);
134134
check_number(r#"const GOAL: i8 = -1 << 2"#, (-1i8 << 2) as i128);
135135
check_fail(r#"const GOAL: i8 = 1 << 8"#, |e| {
136-
e == ConstEvalError::MirEvalError(MirEvalError::Panic("Overflow in Shl".to_string()))
136+
e == ConstEvalError::MirEvalError(MirEvalError::Panic("Overflow in Shl".to_owned()))
137137
});
138138
check_number(r#"const GOAL: i32 = 100000000i32 << 11"#, (100000000i32 << 11) as i128);
139139
}
@@ -2756,7 +2756,7 @@ fn memory_limit() {
27562756
"#,
27572757
|e| {
27582758
e == ConstEvalError::MirEvalError(MirEvalError::Panic(
2759-
"Memory allocation of 30000000000 bytes failed".to_string(),
2759+
"Memory allocation of 30000000000 bytes failed".to_owned(),
27602760
))
27612761
},
27622762
);

crates/hir-ty/src/infer/closure.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,15 @@ impl CapturedItem {
194194
}
195195
let variant_data = f.parent.variant_data(db.upcast());
196196
let field = match &*variant_data {
197-
VariantData::Record(fields) => fields[f.local_id]
198-
.name
199-
.as_str()
200-
.unwrap_or("[missing field]")
201-
.to_string(),
197+
VariantData::Record(fields) => {
198+
fields[f.local_id].name.as_str().unwrap_or("[missing field]").to_owned()
199+
}
202200
VariantData::Tuple(fields) => fields
203201
.iter()
204202
.position(|it| it.0 == f.local_id)
205203
.unwrap_or_default()
206204
.to_string(),
207-
VariantData::Unit => "[missing field]".to_string(),
205+
VariantData::Unit => "[missing field]".to_owned(),
208206
};
209207
result = format!("{result}.{field}");
210208
field_need_paren = false;

0 commit comments

Comments
 (0)