Skip to content

Commit e71cee3

Browse files
committed
fixup
1 parent ea6700c commit e71cee3

File tree

6 files changed

+188
-100
lines changed

6 files changed

+188
-100
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ fn check_annotations(
11241124
}
11251125
ErrorMatchKind::Code(code) => {
11261126
let found = msgs.iter().position(|msg| {
1127-
msg.level >= Level::Warn
1127+
msg.level == Level::Error
11281128
&& msg.code.as_ref().is_some_and(|msg| *msg == **code)
11291129
});
11301130
if let Some(found) = found {

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ impl CommentParser<&mut Revisioned> {
791791
});
792792
} else if (*level_or_code).parse::<Level>().is_ok() {
793793
// Shouldn't conflict with any real diagnostic code
794-
self.error(pattern.span(), "no `:` after level found");
794+
self.error(level_or_code.span(), "no `:` after level found");
795795
return;
796796
} else if !pattern.trim_start().is_empty() {
797797
self.error(

src/tests.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,103 @@ fn main() {
362362
_ => panic!("{:#?}", errors),
363363
}
364364
}
365+
366+
#[test]
367+
fn find_code() {
368+
let s = r"
369+
fn main() {
370+
let _x: i32 = 0u32; //~ E0308
371+
}
372+
";
373+
let comments = Comments::parse(s).unwrap();
374+
let config = config();
375+
{
376+
let messages = vec![
377+
vec![],
378+
vec![],
379+
vec![],
380+
vec![Message {
381+
message: "mismatched types".to_string(),
382+
level: Level::Error,
383+
line_col: None,
384+
code: Some("E0308".into()),
385+
}],
386+
];
387+
let mut errors = vec![];
388+
check_annotations(
389+
messages,
390+
vec![],
391+
Path::new("moobar"),
392+
&mut errors,
393+
&config,
394+
"",
395+
&comments,
396+
)
397+
.unwrap();
398+
match &errors[..] {
399+
[] => {}
400+
_ => panic!("{:#?}", errors),
401+
}
402+
}
403+
404+
// different error code
405+
{
406+
let messages = vec![
407+
vec![],
408+
vec![],
409+
vec![],
410+
vec![Message {
411+
message: "mismatched types".to_string(),
412+
level: Level::Error,
413+
line_col: None,
414+
code: Some("SomeError".into()),
415+
}],
416+
];
417+
let mut errors = vec![];
418+
check_annotations(
419+
messages,
420+
vec![],
421+
Path::new("moobar"),
422+
&mut errors,
423+
&config,
424+
"",
425+
&comments,
426+
)
427+
.unwrap();
428+
match &errors[..] {
429+
[Error::CodeNotFound { code, .. }, Error::ErrorsWithoutPattern { msgs, .. }]
430+
if **code == "E0308" && code.line().get() == 3 && msgs.len() == 1 => {}
431+
_ => panic!("{:#?}", errors),
432+
}
433+
}
434+
435+
// warning instead of error
436+
{
437+
let messages = vec![
438+
vec![],
439+
vec![],
440+
vec![],
441+
vec![Message {
442+
message: "mismatched types".to_string(),
443+
level: Level::Warn,
444+
line_col: None,
445+
code: Some("E0308".into()),
446+
}],
447+
];
448+
let mut errors = vec![];
449+
check_annotations(
450+
messages,
451+
vec![],
452+
Path::new("moobar"),
453+
&mut errors,
454+
&config,
455+
"",
456+
&comments,
457+
)
458+
.unwrap();
459+
match &errors[..] {
460+
[Error::CodeNotFound { code, .. }] if **code == "E0308" && code.line().get() == 3 => {}
461+
_ => panic!("{:#?}", errors),
462+
}
463+
}
464+
}

tests/integrations/basic-fail/Cargo.stdout

Lines changed: 56 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ tests/actual_tests/foomp.rs ... FAILED
1313
tests/actual_tests/foomp2.rs ... FAILED
1414
tests/actual_tests/pattern_too_many_arrow.rs ... FAILED
1515
tests/actual_tests/rustc_ice.rs ... FAILED
16-
tests/actual_tests/wrong_diagnostic_code.rs ... FAILED
1716

1817
FAILED TEST: tests/actual_tests/bad_pattern.rs
1918
command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "--out-dir" "$TMP "tests/actual_tests/bad_pattern.rs" "--edition" "2021"
@@ -276,86 +275,6 @@ end of query stack
276275
full stdout:
277276

278277

279-
280-
FAILED TEST: tests/actual_tests/wrong_diagnostic_code.rs
281-
command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "--out-dir" "$TMP "tests/actual_tests/wrong_diagnostic_code.rs" "--edition" "2021"
282-
283-
error: fail test got exit status: 0, but expected 1
284-
285-
error: actual output differed from expected
286-
Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/wrong_diagnostic_code.stderr` to the actual output
287-
--- tests/actual_tests/wrong_diagnostic_code.stderr
288-
+++ <stderr output>
289-
+warning: unreachable expression
290-
+ --> $DIR/wrong_diagnostic_code.rs:6:5
291-
+ |
292-
+5 | panic!();
293-
+ | -------- any code following this expression is unreachable
294-
+6 | 0
295-
+ | ^ unreachable expression
296-
+ |
297-
+note: the lint level is defined here
298-
+ --> $DIR/wrong_diagnostic_code.rs:1:20
299-
+ |
300-
+1 | #![warn(dead_code, unreachable_code)]
301-
+ | ^^^^^^^^^^^^^^^^
302-
+
303-
+warning: function `foo` is never used
304-
+ --> $DIR/wrong_diagnostic_code.rs:3:4
305-
+ |
306-
+3 | fn foo() -> i32 {
307-
+ | ^^^
308-
+ |
309-
+note: the lint level is defined here
310-
+ --> $DIR/wrong_diagnostic_code.rs:1:9
311-
+ |
312-
+1 | #![warn(dead_code, unreachable_code)]
313-
+ | ^^^^^^^^^
314-
+
315-
+warning: 2 warnings emitted
316-
+
317-
318-
319-
error: diagnostic code `unreachable_code` not found on line 3
320-
--> tests/actual_tests/wrong_diagnostic_code.rs:4:10
321-
|
322-
4 | //~^ unreachable_code
323-
| ^^^^^^^^^^^^^^^^ expected because of this pattern
324-
|
325-
326-
full stderr:
327-
warning: unreachable expression
328-
--> tests/actual_tests/wrong_diagnostic_code.rs:6:5
329-
|
330-
5 | panic!();
331-
| -------- any code following this expression is unreachable
332-
6 | 0
333-
| ^ unreachable expression
334-
|
335-
note: the lint level is defined here
336-
--> tests/actual_tests/wrong_diagnostic_code.rs:1:20
337-
|
338-
1 | #![warn(dead_code, unreachable_code)]
339-
| ^^^^^^^^^^^^^^^^
340-
341-
warning: function `foo` is never used
342-
--> tests/actual_tests/wrong_diagnostic_code.rs:3:4
343-
|
344-
3 | fn foo() -> i32 {
345-
| ^^^
346-
|
347-
note: the lint level is defined here
348-
--> tests/actual_tests/wrong_diagnostic_code.rs:1:9
349-
|
350-
1 | #![warn(dead_code, unreachable_code)]
351-
| ^^^^^^^^^
352-
353-
warning: 2 warnings emitted
354-
355-
356-
full stdout:
357-
358-
359278
FAILURES:
360279
tests/actual_tests/bad_pattern.rs
361280
tests/actual_tests/executable.rs
@@ -366,9 +285,8 @@ FAILURES:
366285
tests/actual_tests/foomp2.rs
367286
tests/actual_tests/pattern_too_many_arrow.rs
368287
tests/actual_tests/rustc_ice.rs
369-
tests/actual_tests/wrong_diagnostic_code.rs
370288

371-
test result: FAIL. 10 failed;
289+
test result: FAIL. 9 failed;
372290

373291
Building dependencies ... ok
374292
tests/actual_tests_bless/aux_build_not_found.rs ... FAILED
@@ -411,6 +329,7 @@ tests/actual_tests_bless/rustfix-fail-revisions.rs (revision `b`) ... FAILED
411329
tests/actual_tests_bless/rustfix-fail.rs ... FAILED
412330
tests/actual_tests_bless/unknown_revision.rs ... FAILED
413331
tests/actual_tests_bless/unknown_revision2.rs ... FAILED
332+
tests/actual_tests_bless/wrong_diagnostic_code.rs ... FAILED
414333

415334
FAILED TEST: tests/actual_tests_bless/aux_build_not_found.rs
416335
command: "$CMD"
@@ -837,6 +756,57 @@ full stderr:
837756
full stdout:
838757

839758

759+
760+
FAILED TEST: tests/actual_tests_bless/wrong_diagnostic_code.rs
761+
command: "rustc" "--error-format=json" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail.rlib" "--extern" "basic_fail=$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug/libbasic_fail-$HASH.rmeta" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "-L" "$DIR/$DIR/../../../target/$TMP/$TRIPLE/debug" "--out-dir" "$TMP "tests/actual_tests_bless/wrong_diagnostic_code.rs" "--edition" "2021"
762+
763+
error: diagnostic code `should_be_dead_code` not found on line 3
764+
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:4:10
765+
|
766+
4 | //~^ should_be_dead_code
767+
| ^^^^^^^^^^^^^^^^^^^ expected because of this pattern
768+
|
769+
770+
error: there were 1 unmatched diagnostics
771+
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:3:4
772+
|
773+
3 | fn foo() -> i32 {
774+
| ^^^ Error: function `foo` is never used
775+
|
776+
777+
full stderr:
778+
error: unreachable expression
779+
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:6:5
780+
|
781+
5 | panic!();
782+
| -------- any code following this expression is unreachable
783+
6 | 0
784+
| ^ unreachable expression
785+
|
786+
note: the lint level is defined here
787+
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:1:20
788+
|
789+
1 | #![deny(dead_code, unreachable_code)]
790+
| ^^^^^^^^^^^^^^^^
791+
792+
error: function `foo` is never used
793+
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:3:4
794+
|
795+
3 | fn foo() -> i32 {
796+
| ^^^
797+
|
798+
note: the lint level is defined here
799+
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:1:9
800+
|
801+
1 | #![deny(dead_code, unreachable_code)]
802+
| ^^^^^^^^^
803+
804+
error: aborting due to 2 previous errors
805+
806+
807+
full stdout:
808+
809+
840810
FAILURES:
841811
tests/actual_tests_bless/aux_build_not_found.rs
842812
tests/actual_tests_bless/aux_proc_macro_misuse.rs
@@ -858,8 +828,9 @@ FAILURES:
858828
tests/actual_tests_bless/rustfix-fail.rs
859829
tests/actual_tests_bless/unknown_revision.rs
860830
tests/actual_tests_bless/unknown_revision2.rs
831+
tests/actual_tests_bless/wrong_diagnostic_code.rs
861832

862-
test result: FAIL. 20 failed; 14 passed; 3 ignored;
833+
test result: FAIL. 21 failed; 14 passed; 3 ignored;
863834

864835
Building dependencies ... ok
865836
tests/actual_tests_bless_yolo/revisions_bad.rs (revision `foo`) ... ok
@@ -905,7 +876,6 @@ tests/actual_tests/foomp.rs ... FAILED
905876
tests/actual_tests/foomp2.rs ... FAILED
906877
tests/actual_tests/pattern_too_many_arrow.rs ... FAILED
907878
tests/actual_tests/rustc_ice.rs ... FAILED
908-
tests/actual_tests/wrong_diagnostic_code.rs ... FAILED
909879

910880
FAILED TEST: tests/actual_tests/bad_pattern.rs
911881
command: "$CMD" "tests/actual_tests/bad_pattern.rs" "--edition" "2021"
@@ -1001,15 +971,6 @@ No such file or directory
1001971
full stdout:
1002972
could not spawn `"invalid_foobarlaksdfalsdfj"` as a process
1003973

1004-
1005-
FAILED TEST: tests/actual_tests/wrong_diagnostic_code.rs
1006-
command: "$CMD" "tests/actual_tests/wrong_diagnostic_code.rs" "--edition" "2021"
1007-
1008-
full stderr:
1009-
No such file or directory
1010-
full stdout:
1011-
could not spawn `"invalid_foobarlaksdfalsdfj"` as a process
1012-
1013974
FAILURES:
1014975
tests/actual_tests/bad_pattern.rs
1015976
tests/actual_tests/executable.rs
@@ -1020,9 +981,8 @@ FAILURES:
1020981
tests/actual_tests/foomp2.rs
1021982
tests/actual_tests/pattern_too_many_arrow.rs
1022983
tests/actual_tests/rustc_ice.rs
1023-
tests/actual_tests/wrong_diagnostic_code.rs
1024984

1025-
test result: FAIL. 10 failed;
985+
test result: FAIL. 9 failed;
1026986

1027987

1028988
running 0 tests

tests/integrations/basic-fail/tests/actual_tests/wrong_diagnostic_code.rs renamed to tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#![warn(dead_code, unreachable_code)]
1+
#![deny(dead_code, unreachable_code)]
22

33
fn foo() -> i32 {
4-
//~^ unreachable_code
4+
//~^ should_be_dead_code
55
panic!();
66
0 //~ unreachable_code
77
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: unreachable expression
2+
--> $DIR/wrong_diagnostic_code.rs:6:5
3+
|
4+
5 | panic!();
5+
| -------- any code following this expression is unreachable
6+
6 | 0
7+
| ^ unreachable expression
8+
|
9+
note: the lint level is defined here
10+
--> $DIR/wrong_diagnostic_code.rs:1:20
11+
|
12+
1 | #![deny(dead_code, unreachable_code)]
13+
| ^^^^^^^^^^^^^^^^
14+
15+
error: function `foo` is never used
16+
--> $DIR/wrong_diagnostic_code.rs:3:4
17+
|
18+
3 | fn foo() -> i32 {
19+
| ^^^
20+
|
21+
note: the lint level is defined here
22+
--> $DIR/wrong_diagnostic_code.rs:1:9
23+
|
24+
1 | #![deny(dead_code, unreachable_code)]
25+
| ^^^^^^^^^
26+
27+
error: aborting due to 2 previous errors
28+

0 commit comments

Comments
 (0)