Skip to content

Commit b1e043e

Browse files
async-llvm(27): Move #[rustc_error] check to an earlier point in order to restore some test expections.
1 parent cacc31f commit b1e043e

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/librustc_trans/base.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,24 +650,30 @@ pub fn set_link_section(ccx: &CrateContext,
650650
}
651651
}
652652

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+
653667
/// Create the `main` function which will initialise the rust runtime and call
654668
/// users main function.
655-
pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
669+
fn maybe_create_entry_wrapper(ccx: &CrateContext) {
656670
let (main_def_id, span) = match *ccx.sess().entry_fn.borrow() {
657671
Some((id, span)) => {
658672
(ccx.tcx().hir.local_def_id(id), span)
659673
}
660674
None => return,
661675
};
662676

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-
671677
let instance = Instance::mono(ccx.tcx(), main_def_id);
672678

673679
if !ccx.codegen_unit().contains_item(&TransItem::Fn(instance)) {
@@ -928,6 +934,8 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
928934
incremental_hashes_map: IncrementalHashesMap,
929935
output_filenames: &OutputFilenames)
930936
-> OngoingCrateTranslation {
937+
check_for_rustc_errors_attr(tcx);
938+
931939
// Be careful with this krate: obviously it gives access to the
932940
// entire contents of the krate. So if you push any subtasks of
933941
// `TransCrate`, you need to be careful to register "reads" of the

0 commit comments

Comments
 (0)