Skip to content

Commit dd38171

Browse files
committed
fixup
1 parent a260a61 commit dd38171

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct Config {
6161
pub filter_exact: bool,
6262
/// Prefix added to all diagnostic code matchers. Note this will make it impossible
6363
/// match codes which do not contain this prefix.
64-
pub diagnostic_code_prefix: Option<String>,
64+
pub diagnostic_code_prefix: String,
6565
}
6666

6767
impl Config {
@@ -106,7 +106,7 @@ impl Config {
106106
list: false,
107107
run_only_ignored: false,
108108
filter_exact: false,
109-
diagnostic_code_prefix: None,
109+
diagnostic_code_prefix: String::new(),
110110
}
111111
}
112112

src/lib.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,6 @@ fn check_test_result(
10101010
config,
10111011
revision,
10121012
comments,
1013-
config.diagnostic_code_prefix.as_deref(),
10141013
)?;
10151014
if errors.is_empty() {
10161015
Ok(command)
@@ -1065,7 +1064,6 @@ fn check_annotations(
10651064
config: &Config,
10661065
revision: &str,
10671066
comments: &Comments,
1068-
diagnostic_code_prefix: Option<&str>,
10691067
) -> Result<(), Errored> {
10701068
let error_patterns = comments
10711069
.for_revision(revision)
@@ -1125,21 +1123,14 @@ fn check_annotations(
11251123
}
11261124
}
11271125
ErrorMatchKind::Code(code) => {
1128-
let found = if let Some(prefix) = diagnostic_code_prefix {
1129-
msgs.iter().position(|msg| {
1130-
msg.level == Level::Error
1131-
&& msg
1132-
.code
1133-
.as_ref()
1134-
.and_then(|code| code.strip_prefix(prefix))
1135-
.is_some_and(|msg| *msg == **code)
1136-
})
1137-
} else {
1138-
msgs.iter().position(|msg| {
1139-
msg.level == Level::Error
1140-
&& msg.code.as_ref().is_some_and(|msg| *msg == **code)
1141-
})
1142-
};
1126+
let found = msgs.iter().position(|msg| {
1127+
msg.level == Level::Error
1128+
&& msg
1129+
.code
1130+
.as_ref()
1131+
.and_then(|code| code.strip_prefix(&config.diagnostic_code_prefix))
1132+
.is_some_and(|msg| *msg == **code)
1133+
});
11431134

11441135
if let Some(found) = found {
11451136
msgs.remove(found);
@@ -1155,11 +1146,10 @@ fn check_annotations(
11551146
expected_line: Some(line),
11561147
},
11571148
ErrorMatchKind::Code(code) => Error::CodeNotFound {
1158-
code: if let Some(prefix) = diagnostic_code_prefix {
1159-
Spanned::new(format!("{prefix}{}", **code), code.span())
1160-
} else {
1161-
code.clone()
1162-
},
1149+
code: Spanned::new(
1150+
format!("{}{}", config.diagnostic_code_prefix, **code),
1151+
code.span(),
1152+
),
11631153
expected_line: Some(line),
11641154
},
11651155
});

src/tests.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ fn main() {
4444
&config,
4545
"",
4646
&comments,
47-
None,
4847
)
4948
.unwrap();
5049
match &errors[..] {
@@ -84,7 +83,6 @@ fn main() {
8483
&config,
8584
"",
8685
&comments,
87-
None,
8886
)
8987
.unwrap();
9088
match &errors[..] {
@@ -113,7 +111,6 @@ fn main() {
113111
&config,
114112
"",
115113
&comments,
116-
None,
117114
)
118115
.unwrap();
119116
match &errors[..] {
@@ -146,7 +143,6 @@ fn main() {
146143
&config,
147144
"",
148145
&comments,
149-
None,
150146
)
151147
.unwrap();
152148
match &errors[..] {
@@ -189,7 +185,6 @@ fn main() {
189185
&config,
190186
"",
191187
&comments,
192-
None,
193188
)
194189
.unwrap();
195190
match &errors[..] {
@@ -235,7 +230,6 @@ fn main() {
235230
&config,
236231
"",
237232
&comments,
238-
None,
239233
)
240234
.unwrap();
241235
match &errors[..] {
@@ -293,7 +287,6 @@ fn main() {
293287
&config,
294288
"",
295289
&comments,
296-
None,
297290
)
298291
.unwrap();
299292
match &errors[..] {
@@ -362,7 +355,6 @@ fn main() {
362355
&config,
363356
"",
364357
&comments,
365-
None,
366358
)
367359
.unwrap();
368360
match &errors[..] {
@@ -401,7 +393,6 @@ fn main() {
401393
&config,
402394
"",
403395
&comments,
404-
None,
405396
)
406397
.unwrap();
407398
match &errors[..] {
@@ -432,7 +423,6 @@ fn main() {
432423
&config,
433424
"",
434425
&comments,
435-
None,
436426
)
437427
.unwrap();
438428
match &errors[..] {
@@ -464,7 +454,6 @@ fn main() {
464454
&config,
465455
"",
466456
&comments,
467-
None,
468457
)
469458
.unwrap();
470459
match &errors[..] {
@@ -482,7 +471,10 @@ fn main() {
482471
}
483472
";
484473
let comments = Comments::parse(s).unwrap();
485-
let config = config();
474+
let config = Config {
475+
diagnostic_code_prefix: "prefix::".into(),
476+
..config()
477+
};
486478
{
487479
let messages = vec![
488480
vec![],
@@ -504,7 +496,6 @@ fn main() {
504496
&config,
505497
"",
506498
&comments,
507-
Some("prefix::"),
508499
)
509500
.unwrap();
510501
match &errors[..] {
@@ -535,7 +526,6 @@ fn main() {
535526
&config,
536527
"",
537528
&comments,
538-
Some("prefix::"),
539529
)
540530
.unwrap();
541531
match &errors[..] {

0 commit comments

Comments
 (0)