about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorYotam Ofek <yotam.ofek@gmail.com>2025-03-16 15:54:04 +0000
committerYotam Ofek <yotam.ofek@gmail.com>2025-03-17 07:06:10 +0000
commita3e4dff1839e9ba70953b8a9ac8572a6cdb160b9 (patch)
tree3dc7f99626d04ec860bf3f67de0551d5f0fb2d96 /compiler/rustc_hir_analysis/src
parent8b87fefd76665236a304d3c0998e1021710ce1b0 (diff)
downloadrust-a3e4dff1839e9ba70953b8a9ac8572a6cdb160b9.tar.gz
rust-a3e4dff1839e9ba70953b8a9ac8572a6cdb160b9.zip
Use `strip_{prefix|suffix}` instead of `{starts|ends}_with`+indexing
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
index fa061c80618..3b007c77198 100644
--- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
+++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
@@ -901,12 +901,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
                 .iter()
                 .map(|(item, _)| format!("{} = Type", item.name))
                 .collect();
-            let code = if snippet.ends_with('>') {
+            let code = if let Some(snippet) = snippet.strip_suffix('>') {
                 // The user wrote `Trait<'a>` or similar and we don't have a type we can
                 // suggest, but at least we can clue them to the correct syntax
                 // `Trait<'a, Item = Type>` while accounting for the `<'a>` in the
                 // suggestion.
-                format!("{}, {}>", &snippet[..snippet.len() - 1], types.join(", "))
+                format!("{}, {}>", snippet, types.join(", "))
             } else if in_expr_or_pat {
                 // The user wrote `Iterator`, so we don't have a type we can suggest, but at
                 // least we can clue them to the correct syntax `Iterator::<Item = Type>`.