Skip to content

Commit 2423411

Browse files
committed
Stop using track_errors for some forever unstable rustc_attr analyses
1 parent 174e73a commit 2423411

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@ 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, DUMMY_SP};
8+
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
99

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

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

18-
tcx.dcx().emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of });
19+
res = res.and(Err(tcx
20+
.dcx()
21+
.emit_err(TypeOf { span: tcx.def_span(id.owner_id), type_of })));
1922
}
2023
}
2124
}
25+
res
2226
}
2327

2428
/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
173173
// FIXME(matthewjasper) We shouldn't need to use `track_errors` anywhere in this function
174174
// or the compiler in general.
175175
if tcx.features().rustc_attrs {
176-
tcx.sess.track_errors(|| {
177-
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx));
178-
})?;
176+
tcx.sess.time("outlives_testing", || outlives::test::test_inferred_outlives(tcx))?;
179177
}
180178

181179
tcx.sess.track_errors(|| {
@@ -194,17 +192,15 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
194192
})?;
195193

196194
if tcx.features().rustc_attrs {
197-
tcx.sess.track_errors(|| {
198-
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx));
199-
})?;
195+
tcx.sess.time("variance_testing", || variance::test::test_variance(tcx))?;
200196
}
201197

202198
tcx.sess.time("wf_checking", || {
203199
tcx.hir().try_par_for_each_module(|module| tcx.ensure().check_mod_type_wf(module))
204200
})?;
205201

206202
if tcx.features().rustc_attrs {
207-
tcx.sess.track_errors(|| collect::test_opaque_hidden_types(tcx))?;
203+
collect::test_opaque_hidden_types(tcx)?;
208204
}
209205

210206
// Freeze definitions as we don't add new ones at this point. This improves performance by

compiler/rustc_hir_analysis/src/outlives/test.rs

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

4-
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
4+
pub fn test_inferred_outlives(tcx: TyCtxt<'_>) -> Result<(), ErrorGuaranteed> {
5+
let mut res = Ok(());
56
for id in tcx.hir().items() {
67
// For unit testing: check for a special "rustc_outlives"
78
// attribute and report an error with various results if found.
@@ -22,7 +23,8 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
2223
for p in pred {
2324
err.note(p);
2425
}
25-
err.emit();
26+
res = res.and(Err(err.emit()));
2627
}
2728
}
29+
res
2830
}

compiler/rustc_hir_analysis/src/variance/test.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ 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;
56

67
use crate::errors;
78

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

14-
tcx.dcx().emit_err(errors::VariancesOf {
16+
res = res.and(Err(tcx.dcx().emit_err(errors::VariancesOf {
1517
span: tcx.def_span(id.owner_id),
1618
variances_of: format!("{variances_of:?}"),
17-
});
19+
})));
1820
}
1921
}
2022
}
@@ -25,10 +27,11 @@ pub fn test_variance(tcx: TyCtxt<'_>) {
2527
if tcx.has_attr(id.owner_id, sym::rustc_variance) {
2628
let variances_of = tcx.variances_of(id.owner_id);
2729

28-
tcx.dcx().emit_err(errors::VariancesOf {
30+
res = res.and(Err(tcx.dcx().emit_err(errors::VariancesOf {
2931
span: tcx.def_span(id.owner_id),
3032
variances_of: format!("{variances_of:?}"),
31-
});
33+
})));
3234
}
3335
}
36+
res
3437
}

0 commit comments

Comments
 (0)