From a3e4dff1839e9ba70953b8a9ac8572a6cdb160b9 Mon Sep 17 00:00:00 2001 From: Yotam Ofek Date: Sun, 16 Mar 2025 15:54:04 +0000 Subject: Use `strip_{prefix|suffix}` instead of `{starts|ends}_with`+indexing --- compiler/rustc_driver_impl/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'compiler/rustc_driver_impl/src') diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index ed5662da16d..ea7e7a7c87a 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -457,8 +457,7 @@ pub enum Compilation { fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, color: ColorConfig) { // Allow "E0123" or "0123" form. let upper_cased_code = code.to_ascii_uppercase(); - let start = if upper_cased_code.starts_with('E') { 1 } else { 0 }; - if let Ok(code) = upper_cased_code[start..].parse::() + if let Ok(code) = upper_cased_code.strip_prefix('E').unwrap_or(&upper_cased_code).parse::() && let Ok(description) = registry.try_find_description(ErrCode::from_u32(code)) { let mut is_in_code_block = false; -- cgit 1.4.1-3-g733a5