Skip to content

Commit d580b2c

Browse files
hir-ty: Fix warnings about clippy str_to_string rule
1 parent cb95ee3 commit d580b2c

File tree

8 files changed

+20
-22
lines changed

8 files changed

+20
-22
lines changed

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;

crates/hir-ty/src/mir/eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ impl Evaluator<'_> {
17631763
}
17641764
};
17651765
mem.get(pos..pos + size)
1766-
.ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory read".to_string()))
1766+
.ok_or_else(|| MirEvalError::UndefinedBehavior("out of bound memory read".to_owned()))
17671767
}
17681768

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

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

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

18051805
match (addr, r.addr) {
18061806
(Stack(dst), Stack(src)) => {
@@ -2653,7 +2653,7 @@ pub fn render_const_using_debug_impl(
26532653
ptr: ArenaMap::new(),
26542654
body: db
26552655
.mir_body(owner.into())
2656-
.map_err(|_| MirEvalError::NotSupported("unreachable".to_string()))?,
2656+
.map_err(|_| MirEvalError::NotSupported("unreachable".to_owned()))?,
26572657
drop_flags: DropFlags::default(),
26582658
};
26592659
let data = evaluator.allocate_const_in_heap(locals, c)?;

crates/hir-ty/src/mir/eval/shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl Evaluator<'_> {
304304
use LangItem::*;
305305
let mut args = args.iter();
306306
match it {
307-
BeginPanic => Err(MirEvalError::Panic("<unknown-panic-payload>".to_string())),
307+
BeginPanic => Err(MirEvalError::Panic("<unknown-panic-payload>".to_owned())),
308308
PanicFmt => {
309309
let message = (|| {
310310
let resolver = self

crates/hir-ty/src/mir/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
16341634
self.set_goto(prev_block, begin, span);
16351635
f(self, begin)?;
16361636
let my = mem::replace(&mut self.current_loop_blocks, prev).ok_or(
1637-
MirLowerError::ImplementationError("current_loop_blocks is corrupt".to_string()),
1637+
MirLowerError::ImplementationError("current_loop_blocks is corrupt".to_owned()),
16381638
)?;
16391639
if let Some(prev) = prev_label {
16401640
self.labeled_loop_blocks.insert(label.unwrap(), prev);
@@ -1669,7 +1669,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
16691669
.current_loop_blocks
16701670
.as_mut()
16711671
.ok_or(MirLowerError::ImplementationError(
1672-
"Current loop access out of loop".to_string(),
1672+
"Current loop access out of loop".to_owned(),
16731673
))?
16741674
.end
16751675
{
@@ -1679,7 +1679,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
16791679
self.current_loop_blocks
16801680
.as_mut()
16811681
.ok_or(MirLowerError::ImplementationError(
1682-
"Current loop access out of loop".to_string(),
1682+
"Current loop access out of loop".to_owned(),
16831683
))?
16841684
.end = Some(s);
16851685
s

crates/hir-ty/src/mir/lower/as_place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl MirLowerCtx<'_> {
225225
{
226226
let Some(index_fn) = self.infer.method_resolution(expr_id) else {
227227
return Err(MirLowerError::UnresolvedMethod(
228-
"[overloaded index]".to_string(),
228+
"[overloaded index]".to_owned(),
229229
));
230230
};
231231
let Some((base_place, current)) =

crates/hir-ty/src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
100100
if only_types {
101101
types.insert(file_range, expected);
102102
} else if expected.starts_with("type: ") {
103-
types.insert(file_range, expected.trim_start_matches("type: ").to_string());
103+
types.insert(file_range, expected.trim_start_matches("type: ").to_owned());
104104
} else if expected.starts_with("expected") {
105105
mismatches.insert(file_range, expected);
106106
} else if expected.starts_with("adjustments:") {
@@ -110,7 +110,7 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
110110
.trim_start_matches("adjustments:")
111111
.trim()
112112
.split(',')
113-
.map(|it| it.trim().to_string())
113+
.map(|it| it.trim().to_owned())
114114
.filter(|it| !it.is_empty())
115115
.collect(),
116116
);
@@ -331,7 +331,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
331331
});
332332
for (node, ty) in &types {
333333
let (range, text) = if let Some(self_param) = ast::SelfParam::cast(node.value.clone()) {
334-
(self_param.name().unwrap().syntax().text_range(), "self".to_string())
334+
(self_param.name().unwrap().syntax().text_range(), "self".to_owned())
335335
} else {
336336
(node.value.text_range(), node.value.text().to_string().replace('\n', " "))
337337
};

crates/hir-ty/src/traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ pub(crate) fn trait_solve_query(
104104
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::Implemented(it))) => {
105105
db.trait_data(it.hir_trait_id()).name.display(db.upcast()).to_string()
106106
}
107-
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::AliasEq(_))) => "alias_eq".to_string(),
108-
_ => "??".to_string(),
107+
GoalData::DomainGoal(DomainGoal::Holds(WhereClause::AliasEq(_))) => "alias_eq".to_owned(),
108+
_ => "??".to_owned(),
109109
};
110110
let _p = tracing::span!(tracing::Level::INFO, "trait_solve_query", ?detail).entered();
111111
tracing::info!("trait_solve_query({:?})", goal.value.goal);

0 commit comments

Comments
 (0)