@@ -650,24 +650,30 @@ pub fn set_link_section(ccx: &CrateContext,
650
650
}
651
651
}
652
652
653
+ // check for the #[rustc_error] annotation, which forces an
654
+ // error in trans. This is used to write compile-fail tests
655
+ // that actually test that compilation succeeds without
656
+ // reporting an error.
657
+ fn check_for_rustc_errors_attr ( tcx : TyCtxt ) {
658
+ if let Some ( ( id, span) ) = * tcx. sess . entry_fn . borrow ( ) {
659
+ let main_def_id = tcx. hir . local_def_id ( id) ;
660
+
661
+ if tcx. has_attr ( main_def_id, "rustc_error" ) {
662
+ tcx. sess . span_fatal ( span, "compilation successful" ) ;
663
+ }
664
+ }
665
+ }
666
+
653
667
/// Create the `main` function which will initialise the rust runtime and call
654
668
/// users main function.
655
- pub fn maybe_create_entry_wrapper ( ccx : & CrateContext ) {
669
+ fn maybe_create_entry_wrapper ( ccx : & CrateContext ) {
656
670
let ( main_def_id, span) = match * ccx. sess ( ) . entry_fn . borrow ( ) {
657
671
Some ( ( id, span) ) => {
658
672
( ccx. tcx ( ) . hir . local_def_id ( id) , span)
659
673
}
660
674
None => return ,
661
675
} ;
662
676
663
- // check for the #[rustc_error] annotation, which forces an
664
- // error in trans. This is used to write compile-fail tests
665
- // that actually test that compilation succeeds without
666
- // reporting an error.
667
- if ccx. tcx ( ) . has_attr ( main_def_id, "rustc_error" ) {
668
- ccx. tcx ( ) . sess . span_fatal ( span, "compilation successful" ) ;
669
- }
670
-
671
677
let instance = Instance :: mono ( ccx. tcx ( ) , main_def_id) ;
672
678
673
679
if !ccx. codegen_unit ( ) . contains_item ( & TransItem :: Fn ( instance) ) {
@@ -928,6 +934,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
928
934
incremental_hashes_map : IncrementalHashesMap ,
929
935
output_filenames : & OutputFilenames )
930
936
-> OngoingCrateTranslation {
937
+ check_for_rustc_errors_attr ( tcx) ;
938
+
931
939
// Be careful with this krate: obviously it gives access to the
932
940
// entire contents of the krate. So if you push any subtasks of
933
941
// `TransCrate`, you need to be careful to register "reads" of the
0 commit comments