From e71cee3cd266f86203374b51db7e17e2c8456aea Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sun, 1 Oct 2023 15:29:08 -0400 Subject: [PATCH] fixup --- src/lib.rs | 2 +- src/parser.rs | 2 +- src/tests.rs | 100 ++++++++++++ tests/integrations/basic-fail/Cargo.stdout | 152 +++++++----------- .../wrong_diagnostic_code.rs | 4 +- .../wrong_diagnostic_code.stderr | 28 ++++ 6 files changed, 188 insertions(+), 100 deletions(-) rename tests/integrations/basic-fail/tests/{actual_tests => actual_tests_bless}/wrong_diagnostic_code.rs (53%) create mode 100644 tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.stderr diff --git a/src/lib.rs b/src/lib.rs index 2901fe19..17bec10c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { diff --git a/src/parser.rs b/src/parser.rs index f9d94d1d..61729469 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -791,7 +791,7 @@ impl CommentParser<&mut Revisioned> { }); } else if (*level_or_code).parse::().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( diff --git a/src/tests.rs b/src/tests.rs index 18f11486..2de55290 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -362,3 +362,103 @@ 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), + } + } + + // warning instead of error + { + let messages = vec![ + vec![], + vec![], + vec![], + vec![Message { + message: "mismatched types".to_string(), + level: Level::Warn, + 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[..] { + [Error::CodeNotFound { code, .. }] if **code == "E0308" && code.line().get() == 3 => {} + _ => panic!("{:#?}", errors), + } + } +} diff --git a/tests/integrations/basic-fail/Cargo.stdout b/tests/integrations/basic-fail/Cargo.stdout index d0ca8fbc..cf3dd2d1 100644 --- a/tests/integrations/basic-fail/Cargo.stdout +++ b/tests/integrations/basic-fail/Cargo.stdout @@ -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" @@ -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 -+++ -+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 @@ -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 @@ -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" @@ -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 @@ -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 @@ -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" @@ -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 @@ -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 diff --git a/tests/integrations/basic-fail/tests/actual_tests/wrong_diagnostic_code.rs b/tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.rs similarity index 53% rename from tests/integrations/basic-fail/tests/actual_tests/wrong_diagnostic_code.rs rename to tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.rs index 535e13bc..81958d46 100644 --- a/tests/integrations/basic-fail/tests/actual_tests/wrong_diagnostic_code.rs +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.rs @@ -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 } diff --git a/tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.stderr b/tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.stderr new file mode 100644 index 00000000..6e4e20bb --- /dev/null +++ b/tests/integrations/basic-fail/tests/actual_tests_bless/wrong_diagnostic_code.stderr @@ -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 +