diff options
| author | Yotam Ofek <yotam.ofek@gmail.com> | 2025-03-16 15:54:04 +0000 | 
|---|---|---|
| committer | Yotam Ofek <yotam.ofek@gmail.com> | 2025-03-17 07:06:10 +0000 | 
| commit | a3e4dff1839e9ba70953b8a9ac8572a6cdb160b9 (patch) | |
| tree | 3dc7f99626d04ec860bf3f67de0551d5f0fb2d96 /compiler/rustc_hir_analysis/src | |
| parent | 8b87fefd76665236a304d3c0998e1021710ce1b0 (diff) | |
| download | rust-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.rs | 4 | 
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>`. | 
