1
Fork 0

Use strip_{prefix|suffix} instead of {starts|ends}_with+indexing

This commit is contained in:
Yotam Ofek 2025-03-16 15:54:04 +00:00
parent 8b87fefd76
commit a3e4dff183
7 changed files with 20 additions and 21 deletions

View file

@ -142,8 +142,8 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
if let Some((name, term)) = associated_ty {
// FIXME: this case overlaps with code in TyCtxt::note_and_explain_type_err.
// That should be extracted into a helper function.
if constraint.ends_with('>') {
constraint = format!("{}, {} = {}>", &constraint[..constraint.len() - 1], name, term);
if let Some(stripped) = constraint.strip_suffix('>') {
constraint = format!("{stripped}, {name} = {term}>");
} else {
constraint.push_str(&format!("<{name} = {term}>"));
}