Skip to content

Commit 9ed3483

Browse files
committed
require an ErrorGuaranteed to taint infcx with errors
1 parent 1c48039 commit 9ed3483

File tree

15 files changed

+94
-59
lines changed

15 files changed

+94
-59
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn do_mir_borrowck<'tcx>(
197197
// Gather the upvars of a closure, if any.
198198
let tables = tcx.typeck_opt_const_arg(def);
199199
if let Some(e) = tables.tainted_by_errors {
200-
infcx.set_tainted_by_errors();
200+
infcx.set_tainted_by_errors(e);
201201
errors.set_tainted_by_errors(e);
202202
}
203203
let upvars: Vec<_> = tables

compiler/rustc_borrowck/src/nll.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
303303

304304
if !nll_errors.is_empty() {
305305
// Suppress unhelpful extra errors in `infer_opaque_types`.
306-
infcx.set_tainted_by_errors();
306+
infcx.set_tainted_by_errors(infcx.tcx.sess.delay_span_bug(
307+
body.span,
308+
"`compute_regions` tainted `infcx` with errors but did not emit any errors",
309+
));
307310
}
308311

309312
let remapped_opaque_tys = regioncx.infer_opaque_types(&infcx, opaque_type_values);

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub trait AstConv<'tcx> {
115115
/// (e.g., resolve) that is translated into a ty-error. This is
116116
/// used to help suppress derived errors typeck might otherwise
117117
/// report.
118-
fn set_tainted_by_errors(&self);
118+
fn set_tainted_by_errors(&self, e: ErrorGuaranteed);
119119

120120
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
121121
}
@@ -2620,8 +2620,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26202620
}
26212621
}
26222622
Res::Err => {
2623-
self.set_tainted_by_errors();
2624-
self.tcx().ty_error()
2623+
let e = self
2624+
.tcx()
2625+
.sess
2626+
.delay_span_bug(path.span, "path with `Res:Err` but no error emitted");
2627+
self.set_tainted_by_errors(e);
2628+
self.tcx().ty_error_with_guaranteed(e)
26252629
}
26262630
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
26272631
}

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
518518
ty
519519
}
520520

521-
fn set_tainted_by_errors(&self) {
521+
fn set_tainted_by_errors(&self, _: ErrorGuaranteed) {
522522
// There's no obvious place to track this, so just let it go.
523523
}
524524

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,9 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15441544
// Mark that we've failed to coerce the types here to suppress
15451545
// any superfluous errors we might encounter while trying to
15461546
// emit or provide suggestions on how to fix the initial error.
1547-
fcx.set_tainted_by_errors();
1547+
fcx.set_tainted_by_errors(
1548+
fcx.tcx.sess.delay_span_bug(cause.span, "coercion error but no error emitted"),
1549+
);
15481550
let (expected, found) = if label_expression_as_expected {
15491551
// In the case where this is a "forced unit", like
15501552
// `break`, we want to call the `()` "expected"

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
154154
Err(e) => e,
155155
};
156156

157-
self.set_tainted_by_errors();
157+
self.set_tainted_by_errors(self.tcx.sess.delay_span_bug(
158+
expr.span,
159+
"`TypeError` when attempting coercion but no error emitted",
160+
));
158161
let expr = expr.peel_drop_temps();
159162
let cause = self.misc(expr.span);
160163
let expr_ty = self.resolve_vars_with_obligations(checked_ty);

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,12 +527,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
527527
self.resolve_ty_and_res_fully_qualified_call(qpath, expr.hir_id, expr.span);
528528
let ty = match res {
529529
Res::Err => {
530-
self.set_tainted_by_errors();
531-
tcx.ty_error()
530+
let e =
531+
self.tcx.sess.delay_span_bug(qpath.span(), "`Res::Err` but no error emitted");
532+
self.set_tainted_by_errors(e);
533+
tcx.ty_error_with_guaranteed(e)
532534
}
533535
Res::Def(DefKind::Ctor(_, CtorKind::Fictive), _) => {
534-
report_unexpected_variant_res(tcx, res, qpath, expr.span);
535-
tcx.ty_error()
536+
let e = report_unexpected_variant_res(tcx, res, qpath, expr.span);
537+
tcx.ty_error_with_guaranteed(e)
536538
}
537539
_ => self.instantiate_value_path(segs, opt_ty, res, expr.span, expr.hir_id).0,
538540
};
@@ -1962,7 +1964,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19621964
expr_span: Span,
19631965
) {
19641966
if variant.is_recovered() {
1965-
self.set_tainted_by_errors();
1967+
self.set_tainted_by_errors(
1968+
self.tcx
1969+
.sess
1970+
.delay_span_bug(expr_span, "parser recovered but no error was emitted"),
1971+
);
19661972
return;
19671973
}
19681974
let mut err = self.err_ctxt().type_error_struct_with_diag(

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
140140
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag());
141141
self.typeck_results.borrow_mut().node_types_mut().insert(id, ty);
142142

143-
if ty.references_error() {
144-
self.set_tainted_by_errors();
143+
if let Err(e) = ty.error_reported() {
144+
self.set_tainted_by_errors(e);
145145
}
146146
}
147147

@@ -1148,9 +1148,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11481148
explicit_late_bound = ExplicitLateBound::Yes;
11491149
}
11501150

1151-
if let Err(GenericArgCountMismatch { reported: Some(_), .. }) = arg_count.correct {
1151+
if let Err(GenericArgCountMismatch { reported: Some(e), .. }) = arg_count.correct {
11521152
infer_args_for_err.insert(index);
1153-
self.set_tainted_by_errors(); // See issue #53251.
1153+
self.set_tainted_by_errors(e); // See issue #53251.
11541154
}
11551155
}
11561156

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
512512
tys.into_iter().any(|ty| ty.references_error() || ty.is_ty_var())
513513
}
514514

515-
self.set_tainted_by_errors();
516515
let tcx = self.tcx;
516+
// FIXME: taint after emitting errors and pass through an `ErrorGuaranteed`
517+
self.set_tainted_by_errors(
518+
tcx.sess.delay_span_bug(call_span, "no errors reported for args"),
519+
);
517520

518521
// Get the argument span in the context of the call span so that
519522
// suggestions and labels are (more) correct when an arg is a
@@ -1208,7 +1211,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12081211
let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id);
12091212
let variant = match def {
12101213
Res::Err => {
1211-
self.set_tainted_by_errors();
1214+
self.set_tainted_by_errors(
1215+
self.tcx.sess.delay_span_bug(path_span, "`Res::Err` but no error emitted"),
1216+
);
12121217
return None;
12131218
}
12141219
Res::Def(DefKind::Variant, _) => match ty.kind() {

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod checks;
44
mod suggestions;
55

66
pub use _impl::*;
7+
use rustc_errors::ErrorGuaranteed;
78
pub use suggestions::*;
89

910
use crate::coercion::DynamicCoerceMany;
@@ -289,8 +290,8 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
289290
}
290291
}
291292

292-
fn set_tainted_by_errors(&self) {
293-
self.infcx.set_tainted_by_errors()
293+
fn set_tainted_by_errors(&self, e: ErrorGuaranteed) {
294+
self.infcx.set_tainted_by_errors(e)
294295
}
295296

296297
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, _span: Span) {

0 commit comments

Comments
 (0)