about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-03-17 07:34:25 +0000
committerbors <bors@rust-lang.org>2025-03-17 07:34:25 +0000
commit9bad8ac498985707f29b0bdc0293cc0457a3ab38 (patch)
tree0f84864da4d1e6238839a4efb78c6cc327262acc /compiler/rustc_middle/src
parent10bcdad7df0de3cfb95c7bdb7b16908e73cafc09 (diff)
parenta3e4dff1839e9ba70953b8a9ac8572a6cdb160b9 (diff)
Auto merge of #138566 - yotamofek:pr/strip-prefix, r=nnethercote
Use `strip_{prefix|suffix}` instead of `{starts|ends}_with`+indexing

Randomly scratching an itch 😁
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/ty/diagnostics.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs
index 881381a5ee6..43a1c2282e0 100644
--- a/compiler/rustc_middle/src/ty/diagnostics.rs
+++ b/compiler/rustc_middle/src/ty/diagnostics.rs
@@ -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}>"));
         }