From 20f1b1cc0a99492b04a6a5994fa5456fd8c54ab9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 23 Jun 2021 16:42:35 +0200 Subject: [PATCH] Greatly improve code --- src/tools/tidy/src/error_codes_check.rs | 44 +++---------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index 8d816296675..d1d43e9449c 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -1,7 +1,6 @@ //! Checks that all error codes have at least one test to prevent having error //! codes that are silently not thrown by the compiler anymore. -use std::collections::hash_map::Entry; use std::collections::HashMap; use std::ffi::OsStr; use std::fs::read_to_string; @@ -106,19 +105,8 @@ fn extract_error_codes( ) .0 .to_owned(); - match error_codes.entry(err_code.clone()) { - Entry::Occupied(mut e) => { - let mut entry = e.get_mut(); - entry.has_explanation = true - } - Entry::Vacant(e) => { - e.insert(ErrorCodeStatus { - has_test: false, - is_used: false, - has_explanation: true, - }); - } - } + error_codes.entry(err_code.clone()).or_default().has_explanation = true; + // Now we extract the tests from the markdown file! let md_file_name = match s.split_once("include_str!(\"") { None => continue, @@ -184,19 +172,7 @@ fn extract_error_codes_from_tests(f: &str, error_codes: &mut HashMap err_code, }, }; - match error_codes.entry(err_code.to_owned()) { - Entry::Occupied(mut e) => { - let mut entry = e.get_mut(); - entry.has_test = true - } - Entry::Vacant(e) => { - e.insert(ErrorCodeStatus { - has_test: true, - is_used: false, - has_explanation: false, - }); - } - } + error_codes.entry(err_code.to_owned()).or_default().has_test = true; } } } @@ -212,19 +188,7 @@ fn extract_error_codes_from_source( } for cap in regex.captures_iter(line) { if let Some(error_code) = cap.get(1) { - match error_codes.entry(error_code.as_str().to_owned()) { - Entry::Occupied(mut e) => { - let mut entry = e.get_mut(); - entry.is_used = true - } - Entry::Vacant(e) => { - e.insert(ErrorCodeStatus { - has_test: false, - is_used: true, - has_explanation: false, - }); - } - } + error_codes.entry(error_code.as_str().to_owned()).or_default().is_used = true; } } }