diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index a0ad17538bc..74a2255d67c 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -969,12 +969,49 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> { Ok(()) } +/// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used +/// to write UI tests that actually test that compilation succeeds without reporting +/// an error. +fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) { + let Some((def_id, _)) = tcx.entry_fn(()) else { return }; + for attr in tcx.get_attrs(def_id, sym::rustc_error) { + match attr.meta_item_list() { + // Check if there is a `#[rustc_error(delayed_bug_from_inside_query)]`. + Some(list) + if list.iter().any(|list_item| { + matches!( + list_item.ident().map(|i| i.name), + Some(sym::delayed_bug_from_inside_query) + ) + }) => + { + tcx.ensure().trigger_delayed_bug(def_id); + } + + // Bare `#[rustc_error]`. + None => { + tcx.dcx().emit_fatal(errors::RustcErrorFatal { span: tcx.def_span(def_id) }); + } + + // Some other attribute. + Some(_) => { + tcx.dcx().emit_warn(errors::RustcErrorUnexpectedAnnotation { + span: tcx.def_span(def_id), + }); + } + } + } +} + /// Runs the codegen backend, after which the AST and analysis can /// be discarded. -pub fn start_codegen<'tcx>( +pub(crate) fn start_codegen<'tcx>( codegen_backend: &dyn CodegenBackend, tcx: TyCtxt<'tcx>, ) -> Box { + // Hook for UI tests. + check_for_rustc_errors_attr(tcx); + info!("Pre-codegen\n{:?}", tcx.debug_stats()); let (metadata, need_metadata_module) = rustc_metadata::fs::encode_and_write_metadata(tcx); diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index 3b06b82d037..5138e145051 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -1,4 +1,4 @@ -use crate::errors::{FailedWritingFile, RustcErrorFatal, RustcErrorUnexpectedAnnotation}; +use crate::errors::FailedWritingFile; use crate::interface::{Compiler, Result}; use crate::{errors, passes}; @@ -15,7 +15,6 @@ use rustc_serialize::opaque::FileEncodeResult; use rustc_session::config::{self, OutputFilenames, OutputType}; use rustc_session::Session; -use rustc_span::symbol::sym; use std::any::Any; use std::cell::{RefCell, RefMut}; use std::sync::Arc; @@ -125,39 +124,6 @@ pub fn write_dep_info(&'tcx self) -> Result<()> { Ok(()) } - /// Check for the `#[rustc_error]` annotation, which forces an error in codegen. This is used - /// to write UI tests that actually test that compilation succeeds without reporting - /// an error. - fn check_for_rustc_errors_attr(tcx: TyCtxt<'_>) { - let Some((def_id, _)) = tcx.entry_fn(()) else { return }; - for attr in tcx.get_attrs(def_id, sym::rustc_error) { - match attr.meta_item_list() { - // Check if there is a `#[rustc_error(delayed_bug_from_inside_query)]`. - Some(list) - if list.iter().any(|list_item| { - matches!( - list_item.ident().map(|i| i.name), - Some(sym::delayed_bug_from_inside_query) - ) - }) => - { - tcx.ensure().trigger_delayed_bug(def_id); - } - - // Bare `#[rustc_error]`. - None => { - tcx.dcx().emit_fatal(RustcErrorFatal { span: tcx.def_span(def_id) }); - } - - // Some other attribute. - Some(_) => { - tcx.dcx() - .emit_warn(RustcErrorUnexpectedAnnotation { span: tcx.def_span(def_id) }); - } - } - } - } - pub fn codegen_and_build_linker(&'tcx self) -> Result { self.global_ctxt()?.enter(|tcx| { // Don't do code generation if there were any errors. Likewise if @@ -167,9 +133,6 @@ pub fn codegen_and_build_linker(&'tcx self) -> Result { return Err(guar); } - // Hook for UI tests. - Self::check_for_rustc_errors_attr(tcx); - let ongoing_codegen = passes::start_codegen(&*self.compiler.codegen_backend, tcx); Ok(Linker {