Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarcho committed Oct 1, 2023
1 parent ea6700c commit 8323dad
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ fn check_annotations(
}
ErrorMatchKind::Code(code) => {
let found = msgs.iter().position(|msg| {
msg.level >= Level::Warn
msg.level == Level::Error
&& msg.code.as_ref().is_some_and(|msg| *msg == **code)
});
if let Some(found) = found {
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ impl CommentParser<&mut Revisioned> {
});
} else if (*level_or_code).parse::<Level>().is_ok() {
// Shouldn't conflict with any real diagnostic code
self.error(pattern.span(), "no `:` after level found");
self.error(level_or_code.span(), "no `:` after level found");
return;
} else if !pattern.trim_start().is_empty() {
self.error(
Expand Down
70 changes: 70 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,73 @@ fn main() {
_ => panic!("{:#?}", errors),
}
}

#[test]
fn find_code() {
let s = r"
fn main() {
let _x: i32 = 0u32; //~ E0308
}
";
let comments = Comments::parse(s).unwrap();
let config = config();
{
let messages = vec![
vec![],
vec![],
vec![],
vec![Message {
message: "mismatched types".to_string(),
level: Level::Error,
line_col: None,
code: Some("E0308".into()),
}],
];
let mut errors = vec![];
check_annotations(
messages,
vec![],
Path::new("moobar"),
&mut errors,
&config,
"",
&comments,
)
.unwrap();
match &errors[..] {
[] => {}
_ => panic!("{:#?}", errors),
}
}

// different error code
{
let messages = vec![
vec![],
vec![],
vec![],
vec![Message {
message: "mismatched types".to_string(),
level: Level::Error,
line_col: None,
code: Some("SomeError".into()),
}],
];
let mut errors = vec![];
check_annotations(
messages,
vec![],
Path::new("moobar"),
&mut errors,
&config,
"",
&comments,
)
.unwrap();
match &errors[..] {
[Error::CodeNotFound { code, .. }, Error::ErrorsWithoutPattern { msgs, .. }]
if **code == "E0308" && code.line().get() == 3 && msgs.len() == 1 => {}
_ => panic!("{:#?}", errors),
}
}
}
152 changes: 56 additions & 96 deletions tests/integrations/basic-fail/Cargo.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ tests/actual_tests/foomp.rs ... FAILED
tests/actual_tests/foomp2.rs ... FAILED
tests/actual_tests/pattern_too_many_arrow.rs ... FAILED
tests/actual_tests/rustc_ice.rs ... FAILED
tests/actual_tests/wrong_diagnostic_code.rs ... FAILED

FAILED TEST: tests/actual_tests/bad_pattern.rs
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"
Expand Down Expand Up @@ -276,86 +275,6 @@ end of query stack
full stdout:



FAILED TEST: tests/actual_tests/wrong_diagnostic_code.rs
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"

error: fail test got exit status: 0, but expected 1

error: actual output differed from expected
Execute `DO NOT BLESS. These are meant to fail` to update `tests/actual_tests/wrong_diagnostic_code.stderr` to the actual output
--- tests/actual_tests/wrong_diagnostic_code.stderr
+++ <stderr output>
+warning: unreachable expression
+ --> $DIR/wrong_diagnostic_code.rs:6:5
+ |
+5 | panic!();
+ | -------- any code following this expression is unreachable
+6 | 0
+ | ^ unreachable expression
+ |
+note: the lint level is defined here
+ --> $DIR/wrong_diagnostic_code.rs:1:20
+ |
+1 | #![warn(dead_code, unreachable_code)]
+ | ^^^^^^^^^^^^^^^^
+
+warning: function `foo` is never used
+ --> $DIR/wrong_diagnostic_code.rs:3:4
+ |
+3 | fn foo() -> i32 {
+ | ^^^
+ |
+note: the lint level is defined here
+ --> $DIR/wrong_diagnostic_code.rs:1:9
+ |
+1 | #![warn(dead_code, unreachable_code)]
+ | ^^^^^^^^^
+
+warning: 2 warnings emitted
+


error: diagnostic code `unreachable_code` not found on line 3
--> tests/actual_tests/wrong_diagnostic_code.rs:4:10
|
4 | //~^ unreachable_code
| ^^^^^^^^^^^^^^^^ expected because of this pattern
|

full stderr:
warning: unreachable expression
--> tests/actual_tests/wrong_diagnostic_code.rs:6:5
|
5 | panic!();
| -------- any code following this expression is unreachable
6 | 0
| ^ unreachable expression
|
note: the lint level is defined here
--> tests/actual_tests/wrong_diagnostic_code.rs:1:20
|
1 | #![warn(dead_code, unreachable_code)]
| ^^^^^^^^^^^^^^^^

warning: function `foo` is never used
--> tests/actual_tests/wrong_diagnostic_code.rs:3:4
|
3 | fn foo() -> i32 {
| ^^^
|
note: the lint level is defined here
--> tests/actual_tests/wrong_diagnostic_code.rs:1:9
|
1 | #![warn(dead_code, unreachable_code)]
| ^^^^^^^^^

warning: 2 warnings emitted


full stdout:


FAILURES:
tests/actual_tests/bad_pattern.rs
tests/actual_tests/executable.rs
Expand All @@ -366,9 +285,8 @@ FAILURES:
tests/actual_tests/foomp2.rs
tests/actual_tests/pattern_too_many_arrow.rs
tests/actual_tests/rustc_ice.rs
tests/actual_tests/wrong_diagnostic_code.rs

test result: FAIL. 10 failed;
test result: FAIL. 9 failed;

Building dependencies ... ok
tests/actual_tests_bless/aux_build_not_found.rs ... FAILED
Expand Down Expand Up @@ -411,6 +329,7 @@ tests/actual_tests_bless/rustfix-fail-revisions.rs (revision `b`) ... FAILED
tests/actual_tests_bless/rustfix-fail.rs ... FAILED
tests/actual_tests_bless/unknown_revision.rs ... FAILED
tests/actual_tests_bless/unknown_revision2.rs ... FAILED
tests/actual_tests_bless/wrong_diagnostic_code.rs ... FAILED

FAILED TEST: tests/actual_tests_bless/aux_build_not_found.rs
command: "$CMD"
Expand Down Expand Up @@ -837,6 +756,57 @@ full stderr:
full stdout:



FAILED TEST: tests/actual_tests_bless/wrong_diagnostic_code.rs
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"

error: diagnostic code `should_be_dead_code` not found on line 3
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:4:10
|
4 | //~^ should_be_dead_code
| ^^^^^^^^^^^^^^^^^^^ expected because of this pattern
|

error: there were 1 unmatched diagnostics
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:3:4
|
3 | fn foo() -> i32 {
| ^^^ Error: function `foo` is never used
|

full stderr:
error: unreachable expression
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:6:5
|
5 | panic!();
| -------- any code following this expression is unreachable
6 | 0
| ^ unreachable expression
|
note: the lint level is defined here
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:1:20
|
1 | #![deny(dead_code, unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: function `foo` is never used
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:3:4
|
3 | fn foo() -> i32 {
| ^^^
|
note: the lint level is defined here
--> tests/actual_tests_bless/wrong_diagnostic_code.rs:1:9
|
1 | #![deny(dead_code, unreachable_code)]
| ^^^^^^^^^

error: aborting due to 2 previous errors


full stdout:


FAILURES:
tests/actual_tests_bless/aux_build_not_found.rs
tests/actual_tests_bless/aux_proc_macro_misuse.rs
Expand All @@ -858,8 +828,9 @@ FAILURES:
tests/actual_tests_bless/rustfix-fail.rs
tests/actual_tests_bless/unknown_revision.rs
tests/actual_tests_bless/unknown_revision2.rs
tests/actual_tests_bless/wrong_diagnostic_code.rs

test result: FAIL. 20 failed; 14 passed; 3 ignored;
test result: FAIL. 21 failed; 14 passed; 3 ignored;

Building dependencies ... ok
tests/actual_tests_bless_yolo/revisions_bad.rs (revision `foo`) ... ok
Expand Down Expand Up @@ -905,7 +876,6 @@ tests/actual_tests/foomp.rs ... FAILED
tests/actual_tests/foomp2.rs ... FAILED
tests/actual_tests/pattern_too_many_arrow.rs ... FAILED
tests/actual_tests/rustc_ice.rs ... FAILED
tests/actual_tests/wrong_diagnostic_code.rs ... FAILED

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


FAILED TEST: tests/actual_tests/wrong_diagnostic_code.rs
command: "$CMD" "tests/actual_tests/wrong_diagnostic_code.rs" "--edition" "2021"

full stderr:
No such file or directory
full stdout:
could not spawn `"invalid_foobarlaksdfalsdfj"` as a process

FAILURES:
tests/actual_tests/bad_pattern.rs
tests/actual_tests/executable.rs
Expand All @@ -1020,9 +981,8 @@ FAILURES:
tests/actual_tests/foomp2.rs
tests/actual_tests/pattern_too_many_arrow.rs
tests/actual_tests/rustc_ice.rs
tests/actual_tests/wrong_diagnostic_code.rs

test result: FAIL. 10 failed;
test result: FAIL. 9 failed;


running 0 tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![warn(dead_code, unreachable_code)]
#![deny(dead_code, unreachable_code)]

fn foo() -> i32 {
//~^ unreachable_code
//~^ should_be_dead_code
panic!();
0 //~ unreachable_code
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error: unreachable expression
--> $DIR/wrong_diagnostic_code.rs:6:5
|
5 | panic!();
| -------- any code following this expression is unreachable
6 | 0
| ^ unreachable expression
|
note: the lint level is defined here
--> $DIR/wrong_diagnostic_code.rs:1:20
|
1 | #![deny(dead_code, unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: function `foo` is never used
--> $DIR/wrong_diagnostic_code.rs:3:4
|
3 | fn foo() -> i32 {
| ^^^
|
note: the lint level is defined here
--> $DIR/wrong_diagnostic_code.rs:1:9
|
1 | #![deny(dead_code, unreachable_code)]
| ^^^^^^^^^

error: aborting due to 2 previous errors

0 comments on commit 8323dad

Please sign in to comment.