From dd381719e068bf9e680f22d928b5f2246002ddb1 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Fri, 6 Oct 2023 12:33:33 -0400 Subject: [PATCH] fixup --- src/config.rs | 4 ++-- src/lib.rs | 34 ++++++++++++---------------------- src/tests.rs | 18 ++++-------------- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/config.rs b/src/config.rs index aa799d8c..30fe6e65 100644 --- a/src/config.rs +++ b/src/config.rs @@ -61,7 +61,7 @@ pub struct Config { pub filter_exact: bool, /// Prefix added to all diagnostic code matchers. Note this will make it impossible /// match codes which do not contain this prefix. - pub diagnostic_code_prefix: Option, + pub diagnostic_code_prefix: String, } impl Config { @@ -106,7 +106,7 @@ impl Config { list: false, run_only_ignored: false, filter_exact: false, - diagnostic_code_prefix: None, + diagnostic_code_prefix: String::new(), } } diff --git a/src/lib.rs b/src/lib.rs index 93c174a6..5f6f2a3f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1010,7 +1010,6 @@ fn check_test_result( config, revision, comments, - config.diagnostic_code_prefix.as_deref(), )?; if errors.is_empty() { Ok(command) @@ -1065,7 +1064,6 @@ fn check_annotations( config: &Config, revision: &str, comments: &Comments, - diagnostic_code_prefix: Option<&str>, ) -> Result<(), Errored> { let error_patterns = comments .for_revision(revision) @@ -1125,21 +1123,14 @@ fn check_annotations( } } ErrorMatchKind::Code(code) => { - let found = if let Some(prefix) = diagnostic_code_prefix { - msgs.iter().position(|msg| { - msg.level == Level::Error - && msg - .code - .as_ref() - .and_then(|code| code.strip_prefix(prefix)) - .is_some_and(|msg| *msg == **code) - }) - } else { - msgs.iter().position(|msg| { - msg.level == Level::Error - && msg.code.as_ref().is_some_and(|msg| *msg == **code) - }) - }; + let found = msgs.iter().position(|msg| { + msg.level == Level::Error + && msg + .code + .as_ref() + .and_then(|code| code.strip_prefix(&config.diagnostic_code_prefix)) + .is_some_and(|msg| *msg == **code) + }); if let Some(found) = found { msgs.remove(found); @@ -1155,11 +1146,10 @@ fn check_annotations( expected_line: Some(line), }, ErrorMatchKind::Code(code) => Error::CodeNotFound { - code: if let Some(prefix) = diagnostic_code_prefix { - Spanned::new(format!("{prefix}{}", **code), code.span()) - } else { - code.clone() - }, + code: Spanned::new( + format!("{}{}", config.diagnostic_code_prefix, **code), + code.span(), + ), expected_line: Some(line), }, }); diff --git a/src/tests.rs b/src/tests.rs index 9efd6ee0..0e6c07f9 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -44,7 +44,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -84,7 +83,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -113,7 +111,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -146,7 +143,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -189,7 +185,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -235,7 +230,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -293,7 +287,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -362,7 +355,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -401,7 +393,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -432,7 +423,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -464,7 +454,6 @@ fn main() { &config, "", &comments, - None, ) .unwrap(); match &errors[..] { @@ -482,7 +471,10 @@ fn main() { } "; let comments = Comments::parse(s).unwrap(); - let config = config(); + let config = Config { + diagnostic_code_prefix: "prefix::".into(), + ..config() + }; { let messages = vec![ vec![], @@ -504,7 +496,6 @@ fn main() { &config, "", &comments, - Some("prefix::"), ) .unwrap(); match &errors[..] { @@ -535,7 +526,6 @@ fn main() { &config, "", &comments, - Some("prefix::"), ) .unwrap(); match &errors[..] {