Skip to content

Commit 1c48039

Browse files
committed
rename is_tainted_by_errors
1 parent 3fca95a commit 1c48039

File tree

13 files changed

+42
-33
lines changed

13 files changed

+42
-33
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,9 +2294,13 @@ mod error {
22942294
}
22952295

22962296
pub fn buffer_error(&mut self, t: DiagnosticBuilder<'_, ErrorGuaranteed>) {
2297-
self.tainted_by_errors = Some(
2298-
self.tcx.sess.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
2299-
);
2297+
if let None = self.tainted_by_errors {
2298+
self.tainted_by_errors = Some(
2299+
self.tcx
2300+
.sess
2301+
.delay_span_bug(t.span.clone(), "diagnostic buffered but not emitted"),
2302+
)
2303+
}
23002304
t.buffer(&mut self.buffered);
23012305
}
23022306

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
219219
instantiated_ty: OpaqueHiddenType<'tcx>,
220220
origin: OpaqueTyOrigin,
221221
) -> Ty<'tcx> {
222-
if let Some(e) = self.is_tainted_by_errors() {
222+
if let Some(e) = self.tainted_by_errors() {
223223
return self.tcx.ty_error_with_guaranteed(e);
224224
}
225225

compiler/rustc_hir_typeck/src/fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
104104
// type, `?T` is not considered unsolved, but `?I` is. The
105105
// same is true for float variables.)
106106
let fallback = match ty.kind() {
107-
_ if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
107+
_ if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
108108
ty::Infer(ty::IntVar(_)) => self.tcx.types.i32,
109109
ty::Infer(ty::FloatVar(_)) => self.tcx.types.f64,
110110
_ => match diverging_fallback.get(&ty) {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
528528
pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
529529
match self.typeck_results.borrow().node_types().get(id) {
530530
Some(&t) => t,
531-
None if let Some(e) = self.is_tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
531+
None if let Some(e) = self.tainted_by_errors() => self.tcx.ty_error_with_guaranteed(e),
532532
None => {
533533
bug!(
534534
"no type for node {}: {} in fcx {}",
@@ -543,7 +543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
543543
pub fn node_ty_opt(&self, id: hir::HirId) -> Option<Ty<'tcx>> {
544544
match self.typeck_results.borrow().node_types().get(id) {
545545
Some(&t) => Some(t),
546-
None if let Some(e) = self.is_tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)),
546+
None if let Some(e) = self.tainted_by_errors() => Some(self.tcx.ty_error_with_guaranteed(e)),
547547
None => None,
548548
}
549549
}
@@ -1440,7 +1440,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14401440
if !ty.is_ty_var() {
14411441
ty
14421442
} else {
1443-
if let None = self.is_tainted_by_errors() {
1443+
if let None = self.tainted_by_errors() {
14441444
self.err_ctxt()
14451445
.emit_inference_failure_err((**self).body_id, sp, ty.into(), E0282, true)
14461446
.emit();

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
7373
let ty = self.typeck_results.borrow().expr_ty_adjusted(expr);
7474
let ty = self.resolve_vars_if_possible(ty);
7575
if ty.has_non_region_infer() {
76+
assert!(self.tainted_by_errors().is_some());
7677
self.tcx.ty_error()
7778
} else {
7879
self.tcx.erase_regions(ty)

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn typeck_with_fallback<'tcx>(
344344

345345
fcx.select_all_obligations_or_error();
346346

347-
if let None = fcx.infcx.is_tainted_by_errors() {
347+
if let None = fcx.infcx.tainted_by_errors() {
348348
fcx.check_transmutes();
349349
}
350350

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
133133
}
134134

135135
fn is_tainted_by_errors(&self) -> bool {
136-
self.infcx.is_tainted_by_errors().is_some()
136+
self.infcx.tainted_by_errors().is_some()
137137
}
138138

139139
fn resolve_type_vars_or_error(

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8383
wbcx.typeck_results.treat_byte_string_as_slice =
8484
mem::take(&mut self.typeck_results.borrow_mut().treat_byte_string_as_slice);
8585

86-
if let Some(e) = self.is_tainted_by_errors() {
86+
if let Some(e) = self.tainted_by_errors() {
8787
wbcx.typeck_results.tainted_by_errors = Some(e);
8888
}
8989

@@ -673,7 +673,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
673673
// to mark the `TypeckResults` as tainted in that case, so that downstream
674674
// users of the typeck results don't produce extra errors, or worse, ICEs.
675675
if let Some(e) = resolver.replaced_with_error {
676-
// FIXME(eddyb) keep track of `ErrorGuaranteed` from where the error was emitted.
677676
self.typeck_results.tainted_by_errors = Some(e);
678677
}
679678

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,8 @@ impl<'tcx> InferCtxt<'tcx> {
12081208
/// reporting errors that often occur as a result of earlier
12091209
/// errors, but where it's hard to be 100% sure (e.g., unresolved
12101210
/// inference variables, regionck errors).
1211-
pub fn is_tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
1211+
#[must_use = "this method does not have any side effects"]
1212+
pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
12121213
debug!(
12131214
"is_tainted_by_errors(err_count={}, err_count_on_creation={}, \
12141215
tainted_by_errors={})",
@@ -1217,14 +1218,17 @@ impl<'tcx> InferCtxt<'tcx> {
12171218
self.tainted_by_errors.get().is_some()
12181219
);
12191220

1221+
if let Some(e) = self.tainted_by_errors.get() {
1222+
return Some(e);
1223+
}
1224+
12201225
if self.tcx.sess.err_count() > self.err_count_on_creation {
12211226
// errors reported since this infcx was made
1222-
return Some(self.tcx.sess.delay_span_bug(
1223-
DUMMY_SP,
1224-
"`tcx.sess.error_count()` incorrectly returned non zero value",
1225-
));
1227+
self.set_tainted_by_errors();
1228+
return self.tainted_by_errors.get();
12261229
}
1227-
self.tainted_by_errors.get()
1230+
1231+
None
12281232
}
12291233

12301234
/// Set the "tainted by errors" flag to true. We call this when we
@@ -1274,7 +1278,7 @@ impl<'tcx> InferCtxt<'tcx> {
12741278
let mut inner = self.inner.borrow_mut();
12751279
let inner = &mut *inner;
12761280
assert!(
1277-
self.is_tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
1281+
self.tainted_by_errors().is_some() || inner.region_obligations.is_empty(),
12781282
"region_obligations not empty: {:#?}",
12791283
inner.region_obligations
12801284
);
@@ -1711,7 +1715,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17111715
) {
17121716
let errors = self.resolve_regions(outlives_env);
17131717

1714-
if let None = self.is_tainted_by_errors() {
1718+
if let None = self.tainted_by_errors() {
17151719
// As a heuristic, just skip reporting region errors
17161720
// altogether if other errors have been reported while
17171721
// this infcx was in use. This is totally hokey but

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20602060
// check upstream for type errors and don't add the obligations to
20612061
// begin with in those cases.
20622062
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
2063-
if let None = self.is_tainted_by_errors() {
2063+
if let None = self.tainted_by_errors() {
20642064
self.emit_inference_failure_err(
20652065
body_id,
20662066
span,
@@ -2115,14 +2115,16 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21152115
if impls.len() > 1 && impls.len() < 5 && has_non_region_infer {
21162116
self.annotate_source_of_ambiguity(&mut err, &impls, predicate);
21172117
} else {
2118-
if self.is_tainted_by_errors().is_some() {
2118+
if self.tainted_by_errors().is_some() {
2119+
err.cancel();
21192120
return;
21202121
}
21212122
err.note(&format!("cannot satisfy `{}`", predicate));
21222123
}
21232124
}
21242125
_ => {
2125-
if self.is_tainted_by_errors().is_some() {
2126+
if self.tainted_by_errors().is_some() {
2127+
err.cancel();
21262128
return;
21272129
}
21282130
err.note(&format!("cannot satisfy `{}`", predicate));
@@ -2224,7 +2226,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22242226
] = path.segments
22252227
&& data.trait_ref.def_id == *trait_id
22262228
&& self.tcx.trait_of_item(*item_id) == Some(*trait_id)
2227-
&& let None = self.is_tainted_by_errors()
2229+
&& let None = self.tainted_by_errors()
22282230
{
22292231
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
22302232
ty::AssocKind::Const => ("refer to the", "constant"),
@@ -2293,7 +2295,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22932295
// with error messages.
22942296
if arg.references_error()
22952297
|| self.tcx.sess.has_errors().is_some()
2296-
|| self.is_tainted_by_errors().is_some()
2298+
|| self.tainted_by_errors().is_some()
22972299
{
22982300
return;
22992301
}
@@ -2304,7 +2306,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23042306
ty::PredicateKind::Subtype(data) => {
23052307
if data.references_error()
23062308
|| self.tcx.sess.has_errors().is_some()
2307-
|| self.is_tainted_by_errors().is_some()
2309+
|| self.tainted_by_errors().is_some()
23082310
{
23092311
// no need to overload user in such cases
23102312
return;
@@ -2315,7 +2317,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23152317
self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true)
23162318
}
23172319
ty::PredicateKind::Projection(data) => {
2318-
if predicate.references_error() || self.is_tainted_by_errors().is_some() {
2320+
if predicate.references_error() || self.tainted_by_errors().is_some() {
23192321
return;
23202322
}
23212323
let subst = data
@@ -2349,7 +2351,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23492351
}
23502352

23512353
ty::PredicateKind::ConstEvaluatable(data) => {
2352-
if predicate.references_error() || self.is_tainted_by_errors().is_some() {
2354+
if predicate.references_error() || self.tainted_by_errors().is_some() {
23532355
return;
23542356
}
23552357
let subst = data.walk().find(|g| g.is_non_region_infer());
@@ -2376,7 +2378,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23762378
}
23772379
}
23782380
_ => {
2379-
if self.tcx.sess.has_errors().is_some() || self.is_tainted_by_errors().is_some() {
2381+
if self.tcx.sess.has_errors().is_some() || self.tainted_by_errors().is_some() {
23802382
return;
23812383
}
23822384
let mut err = struct_span_err!(
@@ -2420,7 +2422,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24202422
post.sort();
24212423
post.dedup();
24222424

2423-
if self.is_tainted_by_errors().is_some()
2425+
if self.tainted_by_errors().is_some()
24242426
&& (crate_names.len() == 1
24252427
&& spans.len() == 0
24262428
&& ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str())

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10891089
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
10901090
match self.query_mode {
10911091
TraitQueryMode::Standard => {
1092-
if let Some(e) = self.infcx.is_tainted_by_errors() {
1092+
if let Some(e) = self.infcx.tainted_by_errors() {
10931093
return Err(OverflowError::Error(e));
10941094
}
10951095
self.infcx.err_ctxt().report_overflow_error(error_obligation, true);

src/test/ui/issues/issue-52262.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// compile-flags:-Ztreat-err-as-bug=5
21
#[derive(Debug)]
32
enum MyError {
43
NotFound { key: Vec<u8> },

src/test/ui/issues/issue-52262.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0507]: cannot move out of `*key` which is behind a shared reference
2-
--> $DIR/issue-52262.rs:16:35
2+
--> $DIR/issue-52262.rs:15:35
33
|
44
LL | String::from_utf8(*key).unwrap()
55
| ^^^^ move occurs because `*key` has type `Vec<u8>`, which does not implement the `Copy` trait

0 commit comments

Comments
 (0)