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

@ -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::<u32>()
if let Ok(code) = upper_cased_code.strip_prefix('E').unwrap_or(&upper_cased_code).parse::<u32>()
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code))
{
let mut is_in_code_block = false;