@@ -22,7 +22,7 @@ use crate::common::{
22
22
output_base_dir, output_base_name, output_testname_unique,
23
23
} ;
24
24
use crate :: compute_diff:: { DiffLine , make_diff, write_diff, write_filtered_diff} ;
25
- use crate :: errors:: { self , Error , ErrorKind } ;
25
+ use crate :: errors:: { Error , ErrorKind } ;
26
26
use crate :: header:: TestProps ;
27
27
use crate :: read2:: { Truncated , read2_abbreviated} ;
28
28
use crate :: util:: { PathBufExt , add_dylib_path, logv, static_regex} ;
@@ -674,7 +674,7 @@ impl<'test> TestCx<'test> {
674
674
}
675
675
}
676
676
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 ) {
678
678
debug ! (
679
679
"check_expected_errors: expected_errors={:?} proc_res.status={:?}" ,
680
680
expected_errors, proc_res. status
@@ -709,9 +709,12 @@ impl<'test> TestCx<'test> {
709
709
self . testpaths . file . display ( ) . to_string ( )
710
710
} ;
711
711
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 ( ) ;
715
718
716
719
// Parse the JSON output from the compiler and extract out the messages.
717
720
let actual_errors = json:: parse_output ( & diagnostic_file_name, & proc_res. stderr , proc_res) ;
@@ -737,13 +740,12 @@ impl<'test> TestCx<'test> {
737
740
}
738
741
739
742
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
+ {
747
749
self . error ( & format ! (
748
750
"{}:{}: unexpected {}: '{}'" ,
749
751
file_name,
@@ -800,29 +802,6 @@ impl<'test> TestCx<'test> {
800
802
}
801
803
}
802
804
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
-
826
805
fn should_emit_metadata ( & self , pm : Option < PassMode > ) -> Emit {
827
806
match ( pm, self . props . fail_mode , self . config . mode ) {
828
807
( Some ( PassMode :: Check ) , ..) | ( _, Some ( FailMode :: Check ) , Ui ) => Emit :: Metadata ,
0 commit comments