Skip to content

Commit e2aadc2

Browse files
committed
Call check_for_rustc_errors_attr from start_codegen
1 parent c8380cb commit e2aadc2

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
@@ -969,12 +969,49 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
969969
Ok(())
970970
}
971971

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

9801017
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)