mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Call check_for_rustc_errors_attr from start_codegen
This commit is contained in:
parent
c8380cbe6a
commit
e2aadc296d
@ -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<dyn Any> {
|
||||
// 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);
|
||||
|
@ -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_middle::ty::{GlobalCtxt, TyCtxt};
|
||||
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 @@ impl<'tcx> Queries<'tcx> {
|
||||
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<Linker> {
|
||||
self.global_ctxt()?.enter(|tcx| {
|
||||
// Don't do code generation if there were any errors. Likewise if
|
||||
@ -167,9 +133,6 @@ impl<'tcx> Queries<'tcx> {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user