@@ -22,7 +22,7 @@ use crate::common::{
2222 output_base_dir, output_base_name, output_testname_unique,
2323} ;
2424use crate :: compute_diff:: { DiffLine , make_diff, write_diff, write_filtered_diff} ;
25- use crate :: errors:: { self , Error , ErrorKind } ;
25+ use crate :: errors:: { Error , ErrorKind } ;
2626use crate :: header:: TestProps ;
2727use crate :: read2:: { Truncated , read2_abbreviated} ;
2828use crate :: util:: { PathBufExt , add_dylib_path, logv, static_regex} ;
@@ -674,7 +674,7 @@ impl<'test> TestCx<'test> {
674674 }
675675 }
676676
677- fn check_expected_errors ( & self , expected_errors : Vec < errors :: Error > , proc_res : & ProcRes ) {
677+ fn check_expected_errors ( & self , expected_errors : Vec < Error > , proc_res : & ProcRes ) {
678678 debug ! (
679679 "check_expected_errors: expected_errors={:?} proc_res.status={:?}" ,
680680 expected_errors, proc_res. status
@@ -709,9 +709,12 @@ impl<'test> TestCx<'test> {
709709 self . testpaths . file . display ( ) . to_string ( )
710710 } ;
711711
712- let expect_help = expected_errors. iter ( ) . any ( |ee| ee. kind == Some ( ErrorKind :: Help ) ) ;
713- let expect_note = expected_errors. iter ( ) . any ( |ee| ee. kind == Some ( ErrorKind :: Note ) ) ;
714- let expect_sugg = expected_errors. iter ( ) . any ( |ee| ee. kind == Some ( ErrorKind :: Suggestion ) ) ;
712+ // Errors and warnings are always expected, other diagnostics are only expected
713+ // if one of them actually occurs in the test.
714+ let expected_kinds: HashSet < _ > = [ ErrorKind :: Error , ErrorKind :: Warning ]
715+ . into_iter ( )
716+ . chain ( expected_errors. iter ( ) . filter_map ( |e| e. kind ) )
717+ . collect ( ) ;
715718
716719 // Parse the JSON output from the compiler and extract out the messages.
717720 let actual_errors = json:: parse_output ( & diagnostic_file_name, & proc_res. stderr , proc_res) ;
@@ -737,13 +740,12 @@ impl<'test> TestCx<'test> {
737740 }
738741
739742 None => {
740- // If the test is a known bug, don't require that the error is annotated
741- if self . is_unexpected_compiler_message (
742- & actual_error,
743- expect_help,
744- expect_note,
745- expect_sugg,
746- ) {
743+ if actual_error. require_annotation
744+ && actual_error. kind . map_or ( false , |kind| {
745+ expected_kinds. contains ( & kind)
746+ && !self . props . dont_require_annotations . contains ( & kind)
747+ } )
748+ {
747749 self . error ( & format ! (
748750 "{}:{}: unexpected {}: '{}'" ,
749751 file_name,
@@ -800,29 +802,6 @@ impl<'test> TestCx<'test> {
800802 }
801803 }
802804
803- /// Returns `true` if we should report an error about `actual_error`,
804- /// which did not match any of the expected error.
805- fn is_unexpected_compiler_message (
806- & self ,
807- actual_error : & Error ,
808- expect_help : bool ,
809- expect_note : bool ,
810- expect_sugg : bool ,
811- ) -> bool {
812- actual_error. require_annotation
813- && actual_error. kind . map_or ( false , |err_kind| {
814- // If the test being checked doesn't contain any "help" or "note" annotations, then
815- // we don't require annotating "help" or "note" (respecively) diagnostics at all.
816- let default_require_annotations = self . props . require_annotations [ & err_kind] ;
817- match err_kind {
818- ErrorKind :: Help => expect_help && default_require_annotations,
819- ErrorKind :: Note => expect_note && default_require_annotations,
820- ErrorKind :: Suggestion => expect_sugg && default_require_annotations,
821- _ => default_require_annotations,
822- }
823- } )
824- }
825-
826805 fn should_emit_metadata ( & self , pm : Option < PassMode > ) -> Emit {
827806 match ( pm, self . props . fail_mode , self . config . mode ) {
828807 ( Some ( PassMode :: Check ) , ..) | ( _, Some ( FailMode :: Check ) , Ui ) => Emit :: Metadata ,
0 commit comments