Skip to content

Commit 4279da5

Browse files
committed
Never bail out early while running all the type check queries
1 parent a6d93ac commit 4279da5

File tree

6 files changed

+20
-28
lines changed

6 files changed

+20
-28
lines changed

compiler/rustc_driver_impl/src/pretty.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
336336
ThirTree => {
337337
let tcx = ex.tcx();
338338
let mut out = String::new();
339-
if rustc_hir_analysis::check_crate(tcx).is_err() {
339+
rustc_hir_analysis::check_crate(tcx);
340+
if tcx.dcx().has_errors().is_some() {
340341
FatalError.raise();
341342
}
342343
debug!("pretty printing THIR tree");
@@ -348,7 +349,8 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
348349
ThirFlat => {
349350
let tcx = ex.tcx();
350351
let mut out = String::new();
351-
if rustc_hir_analysis::check_crate(tcx).is_err() {
352+
rustc_hir_analysis::check_crate(tcx);
353+
if tcx.dcx().has_errors().is_some() {
352354
FatalError.raise();
353355
}
354356
debug!("pretty printing THIR flat");

compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@ use rustc_hir::intravisit::{self, Visitor};
55
use rustc_hir::{self as hir, def, Expr, ImplItem, Item, Node, TraitItem};
66
use rustc_middle::hir::nested_filter;
77
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
8-
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
8+
use rustc_span::{sym, DUMMY_SP};
99

1010
use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType};
1111

12-
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
13-
let mut res = Ok(());
12+
pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) {
1413
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) {
1514
for id in tcx.hir().items() {
1615
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
1716
let type_of = tcx.type_of(id.owner_id).instantiate_identity();
1817

19-
res = Err(tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of }));
18+
tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of });
2019
}
2120
}
2221
}
23-
res
2422
}
2523

2624
/// Checks "defining uses" of opaque `impl Trait` in associated types.

compiler/rustc_hir_analysis/src/lib.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ mod outlives;
9898
pub mod structured_errors;
9999
mod variance;
100100

101-
use rustc_errors::ErrorGuaranteed;
102101
use rustc_hir as hir;
103102
use rustc_middle::middle;
104103
use rustc_middle::query::Providers;
@@ -156,11 +155,11 @@ pub fn provide(providers: &mut Providers) {
156155
hir_wf_check::provide(providers);
157156
}
158157

159-
pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
158+
pub fn check_crate(tcx: TyCtxt<'_>) {
160159
let _prof_timer = tcx.sess.timer("type_check_crate");
161160

162161
if tcx.features().rustc_attrs {
163-
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?;
162+
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
164163
}
165164

166165
tcx.sess.time("coherence_checking", || {
@@ -177,11 +176,11 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
177176
});
178177

179178
if tcx.features().rustc_attrs {
180-
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?;
179+
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
181180
}
182181

183182
if tcx.features().rustc_attrs {
184-
collect::test_opaque_hidden_types(tcx)?;
183+
collect::test_opaque_hidden_types(tcx);
185184
}
186185

187186
// 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> {
211210
});
212211

213212
tcx.ensure().check_unused_traits(());
214-
215-
Ok(())
216213
}
217214

218215
/// A quasi-deprecated helper used in rustdoc and clippy to get

compiler/rustc_hir_analysis/src/outlives/test.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use rustc_middle::ty::{self, TyCtxt};
2-
use rustc_span::{symbol::sym, ErrorGuaranteed};
2+
use rustc_span::symbol::sym;
33

4-
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
5-
let mut res = Ok(());
4+
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
65
for id in tcx.hir().items() {
76
// For unit testing: check for a special "rustc_outlives"
87
// attribute and report an error with various results if found.
@@ -23,8 +22,7 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
2322
for p in pred {
2423
err.note(p);
2524
}
26-
res = Err(err.emit());
25+
err.emit();
2726
}
2827
}
29-
res
3028
}

compiler/rustc_hir_analysis/src/variance/test.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,19 @@ use rustc_hir::def::DefKind;
22
use rustc_hir::def_id::CRATE_DEF_ID;
33
use rustc_middle::ty::TyCtxt;
44
use rustc_span::symbol::sym;
5-
use rustc_span::ErrorGuaranteed;
65

76
use crate::errors;
87

9-
pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
10-
let mut res = Ok(());
8+
pub fn test_variance(tcx: TyCtxt<'_>) {
119
if tcx.has_attr(CRATE_DEF_ID, sym::rustc_variance_of_opaques) {
1210
for id in tcx.hir().items() {
1311
if matches!(tcx.def_kind(id.owner_id), DefKind::OpaqueTy) {
1412
let variances_of = tcx.variances_of(id.owner_id);
1513

16-
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
14+
tcx.dcx().emit_err(errors::VariancesOf {
1715
span: tcx.def_span(id.owner_id),
1816
variances_of: format!("{variances_of:?}"),
19-
}));
17+
});
2018
}
2119
}
2220
}
@@ -27,11 +25,10 @@ pub fn test_variance(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
2725
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
2826
let variances_of = tcx.variances_of(id.owner_id);
2927

30-
res = Err(tcx.dcx().emit_err(errors::VariancesOf {
28+
tcx.dcx().emit_err(errors::VariancesOf {
3129
span: tcx.def_span(id.owner_id),
3230
variances_of: format!("{variances_of:?}"),
33-
}));
31+
});
3432
}
3533
}
36-
res
3734
}

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
734734
});
735735

736736
// passes are timed inside typeck
737-
rustc_hir_analysis::check_crate(tcx)?;
737+
rustc_hir_analysis::check_crate(tcx);
738738

739739
sess.time("MIR_borrow_checking", || {
740740
tcx.hir().par_body_owners(|def_id| {

0 commit comments

Comments
 (0)