Skip to content

Commit e6ff364

Browse files
committed
Call check_for_rustc_errors_attr from start_codegen
1 parent ce2f983 commit e6ff364

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,49 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
970970
Ok(())
971971
}
972972

973+
/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
974+
/// to write UI tests that actually test that compilation succeeds without reporting
975+
/// an error.
976+
fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
977+
let Some((def_id, _)) = tcx.entry_fn(()) else { return };
978+
for attr in tcx.get_attrs(def_id, sym::rustc_error) {
979+
match attr.meta_item_list() {
980+
// Check if there is a `#[rustc_error(delayed_bug_from_inside_query)]`.
981+
Some(list)
982+
if list.iter().any(|list_item| {
983+
matches!(
984+
list_item.ident().map(|i| i.name),
985+
Some(sym::delayed_bug_from_inside_query)
986+
)
987+
}) =>
988+
{
989+
tcx.ensure().trigger_delayed_bug(def_id);
990+
}
991+
992+
// Bare `#[rustc_error]`.
993+
None => {
994+
tcx.dcx().emit_fatal(errors::RustcErrorFatal { span: tcx.def_span(def_id) });
995+
}
996+
997+
// Some other attribute.
998+
Some(_) => {
999+
tcx.dcx().emit_warn(errors::RustcErrorUnexpectedAnnotation {
1000+
span: tcx.def_span(def_id),
1001+
});
1002+
}
1003+
}
1004+
}
1005+
}
1006+
9731007
/// Runs the codegen backend, after which the AST and analysis can
9741008
/// be discarded.
975-
pub fn start_codegen<'tcx>(
1009+
pub(crate) fn start_codegen<'tcx>(
9761010
codegen_backend: &dyn CodegenBackend,
9771011
tcx: TyCtxt<'tcx>,
9781012
) -> Box<dyn Any> {
1013+
// Hook for UI tests.
1014+
check_for_rustc_errors_attr(tcx);
1015+
9791016
info!("Pre-codegen\n{:?}", tcx.debug_stats());
9801017

9811018
let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx);

compiler/rustc_interface/src/queries.rs

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::errors::{FailedWritingFile, RustcErrorFatal, RustcErrorUnexpectedAnnotation};
1+
use crate::errors::FailedWritingFile;
22
use crate::interface::{Compiler, Result};
33
use crate::{errors, passes};
44

@@ -15,7 +15,6 @@ use rustc_middle::ty::{GlobalCtxt, TyCtxt};
1515
use rustc_serialize::opaque::FileEncodeResult;
1616
use rustc_session::config::{self, OutputFilenames, OutputType};
1717
use rustc_session::Session;
18-
use rustc_span::symbol::sym;
1918
use std::any::Any;
2019
use std::cell::{RefCell, RefMut};
2120
use std::sync::Arc;
@@ -125,39 +124,6 @@ impl<'tcx> Queries<'tcx> {
125124
Ok(())
126125
}
127126

128-
/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used
129-
/// to write UI tests that actually test that compilation succeeds without reporting
130-
/// an error.
131-
fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) {
132-
let Some((def_id, _)) = tcx.entry_fn(()) else { return };
133-
for attr in tcx.get_attrs(def_id, sym::rustc_error) {
134-
match attr.meta_item_list() {
135-
// Check if there is a `#[rustc_error(delayed_bug_from_inside_query)]`.
136-
Some(list)
137-
if list.iter().any(|list_item| {
138-
matches!(
139-
list_item.ident().map(|i| i.name),
140-
Some(sym::delayed_bug_from_inside_query)
141-
)
142-
}) =>
143-
{
144-
tcx.ensure().trigger_delayed_bug(def_id);
145-
}
146-
147-
// Bare `#[rustc_error]`.
148-
None => {
149-
tcx.dcx().emit_fatal(RustcErrorFatal { span: tcx.def_span(def_id) });
150-
}
151-
152-
// Some other attribute.
153-
Some(_) => {
154-
tcx.dcx()
155-
.emit_warn(RustcErrorUnexpectedAnnotation { span: tcx.def_span(def_id) });
156-
}
157-
}
158-
}
159-
}
160-
161127
pub fn codegen_and_build_linker(&'tcx self) -> Result<Linker> {
162128
self.global_ctxt()?.enter(|tcx| {
163129
// Don't do code generation if there were any errors. Likewise if
@@ -167,9 +133,6 @@ impl<'tcx> Queries<'tcx> {
167133
return Err(guar);
168134
}
169135

170-
// Hook for UI tests.
171-
Self::check_for_rustc_errors_attr(tcx);
172-
173136
let ongoing_codegen = passes::start_codegen(&*self.compiler.codegen_backend, tcx);
174137

175138
Ok(Linker {

0 commit comments

Comments
 (0)