hir-ty: Fix warnings about clippy str_to_string rule

This commit is contained in:
Tetsuharu Ohzeki 2024-02-10 00:31:33 +09:00
parent cb95ee3bc0
commit d580b2c7bc
8 changed files with 20 additions and 22 deletions

View File

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

View File

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

View File

@ -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]> {
@ -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<()> {
@ -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)) => {
@ -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)?;

View File

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

View File

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

View File

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

View File

@ -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:") {
@ -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(),
);
@ -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', " "))
};

View File

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