Never bail out early while running all the type check queries

This commit is contained in:
Oli Scherer 2024-03-07 13:59:50 +00:00
parent a6d93acf5f
commit 4279da583c
6 changed files with 20 additions and 28 deletions

View File

@ -336,7 +336,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirTree => { ThirTree => {
let tcx = ex.tcx(); let tcx = ex.tcx();
let mut out = String::new(); let mut out = String::new();
if rustc_hir_analysis::check_crate(tcx).is_err() { rustc_hir_analysis::check_crate(tcx);
if tcx.dcx().has_errors().is_some() {
FatalError.raise(); FatalError.raise();
} }
debug!("pretty printing THIR tree"); debug!("pretty printing THIR tree");
@ -348,7 +349,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
ThirFlat => { ThirFlat => {
let tcx = ex.tcx(); let tcx = ex.tcx();
let mut out = String::new(); let mut out = String::new();
if rustc_hir_analysis::check_crate(tcx).is_err() { rustc_hir_analysis::check_crate(tcx);
if tcx.dcx().has_errors().is_some() {
FatalError.raise(); FatalError.raise();
} }
debug!("pretty printing THIR flat"); debug!("pretty printing THIR flat");

View File

@ -5,22 +5,20 @@
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem}; use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP}; use rustc_span::{sym, DUMMY_SP};
use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType}; use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType};
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) {
let mut res = Ok(());
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) { if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
for id in tcx.hir().items() { for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) { if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
let type_of = tcx.type_of(id.owner_id).instantiate_identity(); let type_of = tcx.type_of(id.owner_id).instantiate_identity();
res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of })); tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of });
} }
} }
} }
res
} }
/// Checks "defining uses" of opaque `impl Trait` in associated types. /// Checks "defining uses" of opaque `impl Trait` in associated types.

View File

@ -98,7 +98,6 @@
pub mod structured_errors; pub mod structured_errors;
mod variance; mod variance;
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::middle; use rustc_middle::middle;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
@ -156,11 +155,11 @@ pub fn provide(providers: &mut Providers) {
hir_wf_check::provide(providers); hir_wf_check::provide(providers);
} }
pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { pub fn check_crate(tcx: TyCtxt<'_>) {
let _prof_timer = tcx.sess.timer("type_check_crate"); let _prof_timer = tcx.sess.timer("type_check_crate");
if tcx.features().rustc_attrs { if tcx.features().rustc_attrs {
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?; tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
} }
tcx.sess.time("coherence_checking", || { tcx.sess.time("coherence_checking", || {
@ -177,11 +176,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
}); });
if tcx.features().rustc_attrs { if tcx.features().rustc_attrs {
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?; tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
} }
if tcx.features().rustc_attrs { if tcx.features().rustc_attrs {
collect::test_opaque_hidden_types(tcx)?; collect::test_opaque_hidden_types(tcx);
} }
// Make sure we evaluate all static and (non-associated) const items, even if unused. // Make sure we evaluate all static and (non-associated) const items, even if unused.
@ -211,8 +210,6 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
}); });
tcx.ensure().check_unused_traits(()); tcx.ensure().check_unused_traits(());
Ok(())
} }
/// A quasi-deprecated helper used in rustdoc and clippy to get /// A quasi-deprecated helper used in rustdoc and clippy to get

View File

@ -1,8 +1,7 @@
use rustc_middle::ty::{self, TyCtxt}; use rustc_middle::ty::{self, TyCtxt};
use rustc_span::{symbol::sym, ErrorGuaranteed}; use rustc_span::symbol::sym;
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
let mut res = Ok(());
for id in tcx.hir().items() { for id in tcx.hir().items() {
// For unit testing: check for a special "rustc_outlives" // For unit testing: check for a special "rustc_outlives"
// attribute and report an error with various results if found. // attribute and report an error with various results if found.
@ -23,8 +22,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
for p in pred { for p in pred {
err.note(p); err.note(p);
} }
res = Err(err.emit()); err.emit();
} }
} }
res
} }

View File

@ -2,21 +2,19 @@
use rustc_hir::def_id::CRATE_DEF_ID; use rustc_hir::def_id::CRATE_DEF_ID;
use rustc_middle::ty::TyCtxt; use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::ErrorGuaranteed;
use crate::errors; use crate::errors;
pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> { pub fn test_variance(tcx: TyCtxt<'_>) {
let mut res = Ok(());
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) { if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
for id in tcx.hir().items() { for id in tcx.hir().items() {
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) { if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
let variances_of = tcx.variances_of(id.owner_id); let variances_of = tcx.variances_of(id.owner_id);
res = Err(tcx.dcx().emit_err(errors::VariancesOf { tcx.dcx().emit_err(errors::VariancesOf {
span: tcx.def_span(id.owner_id), span: tcx.def_span(id.owner_id),
variances_of: format!("{variances_of:?}"), variances_of: format!("{variances_of:?}"),
})); });
} }
} }
} }
@ -27,11 +25,10 @@ pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
if tcx.has_attr(id.owner_id, sym::rustc_variance) { if tcx.has_attr(id.owner_id, sym::rustc_variance) {
let variances_of = tcx.variances_of(id.owner_id); let variances_of = tcx.variances_of(id.owner_id);
res = Err(tcx.dcx().emit_err(errors::VariancesOf { tcx.dcx().emit_err(errors::VariancesOf {
span: tcx.def_span(id.owner_id), span: tcx.def_span(id.owner_id),
variances_of: format!("{variances_of:?}"), variances_of: format!("{variances_of:?}"),
})); });
} }
} }
res
} }

View File

@ -734,7 +734,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
}); });
// passes are timed inside typeck // passes are timed inside typeck
rustc_hir_analysis::check_crate(tcx)?; rustc_hir_analysis::check_crate(tcx);
sess.time("MIR_borrow_checking", || { sess.time("MIR_borrow_checking", || {
tcx.hir().par_body_owners(|def_id| { tcx.hir().par_body_owners(|def_id| {